Problem/Motivation

The `drupal.tableheader` library provided a way to make table header sticky using JS when IE11 didn't have support for `position:sticky`.
Now that Drupal doesn't support IE11, we can remove the JS workaround and use `position:sticky` instead.

Related issues:

Steps to reproduce

Proposed resolution

  1. ✅ Remove tableheader.js
  2. ✅ Add `sticky-header` class to tables if `#sticky` is `true` for the table.
  3. ✅ Add CSS to set `position:sticky` for `.sticky-header thead`
  4. ✅ Update `drupal.tableheader` to include this css
  5. ✅ Add/update tests

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

Sticky table headers are now implemented with pure CSS instead of JavaScript.

Claro's custom implementation of sticky table headers which was already using pure CSS, has been removed and now relies on the default implementation.

Themes that heavily customise the sticky tableheaders markup, CSS, or JavaScript may need to update, or may be able to remove overrides if they were implementing a CSS-only solution similar to Claro's.

Issue fork drupal-3439580

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dipakmdhrm created an issue. See original summary.

dipakmdhrm’s picture

Issue summary: View changes
dipakmdhrm’s picture

Status: Active » Needs review
dipakmdhrm’s picture

Issue summary: View changes

dipakmdhrm’s picture

It's fascinating that `position:sticky` replaces ~450 lines of code.
Things IE made developers do.

needs-review-queue-bot’s picture

Status: Needs review » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

dipakmdhrm’s picture

Status: Needs work » Needs review

Thanks mr. needs-review-queue-bot. MR created.

bramdriesen’s picture

Status: Needs review » Needs work

Don't think this is good to go. You can't remove and deprecate at the same time.

dipakmdhrm’s picture

Don't think this is good to go. You can't remove and deprecate at the same time.

I've created an MR which should be better implemented than the patch.
The MR deprecates the `drupal.tableheader` library but removes the associated JS files, PHP code & text, and adds the css for sticky position.

Eum, you already removed it? Also D11 is not yet released, so I believe it's possible to remove this in 11.0.0 and add the deprecations to D10.

That's not a bad idea.

dipakmdhrm’s picture

Version: 11.x-dev » 10.3.x-dev

dipakmdhrm’s picture

Status: Needs work » Needs review

Ready for review for 10.3.x

dipakmdhrm’s picture

StatusFileSize
new20.65 KB

DO NOT USE THIS PATCH

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new4.96 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

catch’s picture

Version: 10.3.x-dev » 11.x-dev

The MR should target 11.x, it will be backported to 10.3.x from there. Couple of extra comments on the MR. This looks great in general, so much code to get rid of.

Binoli Lalani made their first commit to this issue’s fork.

catch’s picture

Title: Remove drupal.tableheader library » Make drupal.tableheader use only CSS for sticky tableheaders
Component: theme system » javascript
Issue tags: +Needs issue summary update, +Needs change record

Small metadata change - putting this into JavaScript because it's mostly about getting rid of JavaScript, might be questionably but close to that than theme system. Also re-titling for the new proposed solution.

Will need an issue summary update to match the new solution as well as a change record.

dipakmdhrm’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update
dipakmdhrm’s picture

Issue summary: View changes
bramdriesen’s picture

Title: Make drupal.tableheader use only CSS for sticky tableheaders » Make drupal.tableheader only use CSS for sticky table headers

Making the title easier to read

catch’s picture

One comment on the MR - because stable9 is there for backwards compatibility, we should probably add the new class and retain the old class instead or replacing. Otherwise this looks great to me!

balagan’s picture

StatusFileSize
new20.66 KB

Just rerolled patch #15 for D10.2.5.
Now that I have realized, that there are problems with this patch, I see the comment "Do not use this patch" at #15. So please ignore this too

dipakmdhrm’s picture

StatusFileSize
new23.27 KB

Patch re-rolled for Drupal 10.2.5

sourojeetpaul made their first commit to this issue’s fork.

dipakmdhrm changed the visibility of the branch 3439580-remove-drupal.tableheader-library to hidden.

dipakmdhrm changed the visibility of the branch 3439580-remove-drupal.tableheader-library to active.

dipakmdhrm’s picture

Status: Needs work » Needs review
Related issues: +#3441844: Set budgets rather than exact numbers of asset size assertions

Tests for this should now hopefully pass for 11.x branch after the changes from this issue were merged in the MR branch.

shriaas’s picture

Tested with Drupal 11.x
The header is sticky on scroll(see the attached video).

+1 for RTBC

balagan’s picture

StatusFileSize
new24.27 KB
nicxvan’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

This looks good to go, I updated the summary to be clearer.

Tests are passing and the video confirms it is working as expected as well.

The feedback on the MR has been addressed as well so I think it is ready.

nicxvan’s picture

Forgot to mention I also reviewed the change record which looks good too!

nod_’s picture

why the class name change? looks like it wouldn't cause a problem to use the sticky-enabled class to apply the css instead of creating a new one.

catch’s picture

The original js adds the sticky-header class, and this is what the existing CSS targets, so it's not actually creating a new class.

this.$stickyTable = $(
          '<table class="sticky-header" style="visibility: hidden; position: fixed; top: 0;"></table>',

core/modules/system/css/components/sticky-header.module.css

table.sticky-header {
  z-index: 500;
  top: 0;
  margin-top: 0;
  background-color: #fff;
}
needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new93 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

dipakmdhrm’s picture

Status: Needs work » Reviewed & tested by the community

The patch in #31 is retroactively made for a specific version of D10.
The MR's still work for the issue.

nod_’s picture

hiding patch to prevent the bot from messing with the issue

@#35 thanks for the details, all good then!

dipakmdhrm’s picture

@nod_ @catch: We're now at beta for D11. Does that mean we now need to adjust the change record & deprecation to target 11.1 & 12 instead of 10.3 & 11?

catch’s picture

Status: Reviewed & tested by the community » Needs work

It will either need to be 11.1 for removal in 12 or 10.4 for removal in 12 depending on whether we backport this to 10.4 or not. I am not entirely sure if we would or not - it might be useful for themes that want to override the component to backport this to keep things in sync, but it's otherwise going to be quite a transparent change for most sites I would think which could be an argument for or against a backport. Will get an opinion or two from other committers.

dipakmdhrm’s picture

Any chance to do a d11-beta2 to avoid all this? :P

nod_’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record

let's get this in, risk is low

  • nod_ committed 4609482e on 10.3.x
    Issue #3439580 by dipakmdhrm, balagan, Shriaas, catch, BramDriesen,...

  • nod_ committed bd85e4ec on 10.4.x
    Issue #3439580 by dipakmdhrm, balagan, Shriaas, catch, BramDriesen,...

  • nod_ committed eac0f2a2 on 11.0.x
    Issue #3439580 by dipakmdhrm, balagan, Shriaas, catch, BramDriesen,...

  • nod_ committed b01b0831 on 11.x
    Issue #3439580 by dipakmdhrm, balagan, Shriaas, catch, BramDriesen,...

nod_’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed to 11.x

dipakmdhrm’s picture

Wooo wooo yay!!!

nod_’s picture

fixing issue credits

grimreaper’s picture

Hi,

Glad to see JS features made available with CSS only!

Sorry to arrive after the party, but in https://git.drupalcode.org/project/drupal/-/blob/10.3.x/core/modules/vie...

    $form['sticky'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Enable Drupal style "sticky" table headers (JavaScript)'),
      '#default_value' => !empty($this->options['sticky']),
      '#description' => $this->t('(Sticky header effects will not be active for preview below, only on live output.)'),
    ];

Should the (JavaScript) be removed too?

catch’s picture

@GrimReaper - good find, could you open follow-up issue for fixing that text?

grimreaper’s picture

Thanks @catch.

I am on it :)

grimreaper’s picture

Follow up issue created: #3451738: Remove JavaScript from Views configuration form now that it is only CSS

MR created and pipeline green, ready for review.

catch’s picture

Issue summary: View changes

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

boulaffasae’s picture

Hi,

After this change, a lot of people seems to run into this issue

InvalidArgumentException: The callable definition provided "[Drupal\claro\ClaroPreRender,tablePositionSticky]" is not a valid callable. in Drupal\Core\Utility\CallableResolver->getCallableFromDefinition() (line 69 of core/lib/Drupal/Core/Utility/CallableResolver.php).

Is there any solution for it ?

Thank you