Add option to un-sticky table headers to benefit assistive tech users

Created on 6 August 2020, almost 4 years ago
Updated 24 June 2024, 1 day ago

Problem/Motivation

Some accessibility concerns about the use of sticky table headers were brought up in ๐Ÿ“Œ Implement bulk operation designs Fixed .

@andrewmacpherson pointed out that the use of a sticky header obscures content. There are two categories of issues this causes:

  1. In a table such as admin/content users can can navigate to an items hidden beneath a sticky header, so there's no longer a visual indication of the item in focus.
  2. Speech control users may encounter a problem with "show numbers" functionality, which displays a number label for each control on the page. These labels would also be applied to items concealed by the sticky and cause confusion.

Steps to reproduce

In admin/content, get the page in a position where the header is sticky, then tab-navigate through the table. Note that items hidden underneath the sticky header can still be focused, but the item+focus state is not visible.

Proposed resolution

This issue was discussed with @rain. There was agreement that there are UX benefits to sticky headers (and potentially other sticky elements such as the one proposed in #3070558). While are several straightforward ways to address concern #1 (keyboard users) while retaining the benefits of Sticky navigation, this doesn't seem possible for addressing #2 (Speech control "show numbers"). @rain suggested adding a toggle that allows enabling/disabling of sticky headers. This would allow the subset of users adversely impacted by sticky headers to bypass that functionality.

Remaining tasks

Determine if this is an acceptable change to core
Review the patch

User interface changes

A new toggle button above tables with sticky headers.

Release notes snippet

๐Ÿ“Œ Task
Status

Needs review

Version

11.0 ๐Ÿ”ฅ

Component
Javascriptย  โ†’

Last updated about 5 hours ago

  • Maintained by
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom @justafish
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance @nod_
Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States bnjmnm Ann Arbor, MI

Live updates comments and jobs are added and updated live.
  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot โ†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

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

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada mgifford Ottawa, Ontario
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia yash.rode pune

    yash.rode โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia yash.rode pune

    Hi, I was trying to make the patch from #3163765-2: Add option to un-sticky table headers to benefit assistive tech users โ†’ compatible with 11.x, but while trying to apply tableheader.js's changes, I noticed that TableHeader is not getting initialised. Can someone tell me how to approach this? For now I have created a new instance of TableHeader which doesn't seem right

  • Merge request !8150Resolve #3163765 "Add option to" โ†’ (Open) created by yash.rode
  • Pipeline finished with Failed
    about 1 month ago
    Total: 195s
    #179248
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States bnjmnm Ann Arbor, MI

    Hi, I was trying to make the patch from #3163765-2: Add option to un-sticky table headers to benefit assistive tech users compatible with 11.x, but while trying to apply tableheader.js's changes, I noticed that TableHeader is not getting initialised. Can someone tell me how to approach this? For now I have created a new instance of TableHeader which doesn't seem right

    To understand why this might not be working Do a search for sticky-enabled (the class Tableheader looks for to initialize) in the codebase and it's a pretty manageable 15 matches. One of them is this line in Claro that intentionally removes this class from tables.

    public static function tablePositionSticky(array $element) {
        if (isset($element['#attributes']['class']) && is_array($element['#attributes']['class']) && in_array('sticky-enabled', $element['#attributes']['class'], TRUE)) {
          unset($element['#attributes']['class'][array_search('sticky-enabled', $element['#attributes']['class'])]);
          $element['#attributes']['class'][] = 'position-sticky';
        }
        return $element;
      }
    
    

    A git blame will show this was added in the following issue: ๐Ÿ“Œ Use position: sticky for views sticky table header Fixed which updates Claro to use CSS for positioning sticky.

    Another means of narrowing this down would have been to use your browser dev tools to inspect the sticky element and see what is making it sticky.

    Either way, it looks like the approach will need to be adjusted to account for changes to core in the 4+ years since the last patch was added.

    So for non-Claro themes, Tableheader will need to be updated to make sticky toggle-able. Claro is using a different approach to making the header sticky, and it will require a different toggle implementation based on that.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia yash.rode pune

    I tried keeping/removing the `position-sticky` class from the table, which makes it sticky/non-sticky respectively. I will try to implement that solution.

  • Pipeline finished with Failed
    about 1 month ago
    Total: 177s
    #180270
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia yash.rode pune

    Hi, the current version of the MR works for all other themes, except Claro as discussed in #3163765-19: Add option to un-sticky table headers to benefit assistive tech users โ†’ . I have the version of tableheader.js which is working for Claro also, but there are few things that needs to sanitised in that, will get to that tomorrow. Posting that as a patch for now.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia yash.rode pune

    This is the working patch for Claro which encorporates suggestions from #3163765-7: Add option to un-sticky table headers to benefit assistive tech users โ†’ ,
    but unfortunately ๐Ÿ“Œ Make drupal.tableheader only use CSS for sticky table headers Needs review just got in, which makes all this of no use.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia yash.rode pune

    Re-created the tableheader.js for making the sticky optional. Added the sticky header checkbox before the sticky header.
    need to be cleaned and use local storage to handle the page refresh.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States bnjmnm Ann Arbor, MI

    Patch testing will be deactivated in 32 days โ†’ so it's best to do all of this in Gitlab.

    1. +++ b/core/core.libraries.yml
      @@ -680,6 +680,14 @@ drupal.tabledrag.ajax:
      +      - core/jquery
      +      - core/drupal
      +      - core/drupalSettings
      +      - core/once
      +      - core/drupal.displace
      

      Currently none of these dependencies are used, but core/drupal probably should be used so Drupal behaviors are used instead of DomContentLoaded

    2. +++ b/core/misc/tableheader.js
      @@ -0,0 +1,32 @@
      +              Sticky Header
      

      Not translated

    3. +++ b/core/misc/tableheader.js
      @@ -0,0 +1,32 @@
      +document.addEventListener('DOMContentLoaded', function () {
      

      Was this a GPT suggestion? GPT loves DOMContent loaded ๐Ÿ™‚. Drupal behaviors would be used for something like this

    4. +++ b/core/misc/tableheader.js
      @@ -0,0 +1,32 @@
      +  const stickyHeaderElement = document.getElementsByClassName('views-table')[0];
      

      Since you're just getting the first match document.querySelector() is cleaner

    5. +++ b/core/misc/tableheader.js
      @@ -0,0 +1,32 @@
      +    const checkbox = document.querySelector('[data-drupal-toggle-sticky-header]');
      

      The theme function might be overridden and not have this selector. While it is ultimately up to the developer to make sure these things are in place, you have the return value 2 lines above and could reference whatever is returned by stickyHeaderCheckbox

    6. +++ b/core/misc/tableheader.js
      @@ -0,0 +1,32 @@
      +    checkbox.addEventListener('change', function () {
      

      Drupal uses arrow syntax

    7. +++ b/core/misc/tableheader.js
      @@ -0,0 +1,32 @@
      +      if (checkbox.checked) {
      +        if (!stickyHeaderElement.classList.contains('sticky-header')) {
      +          stickyHeaderElement.classList.add('sticky-header');
      +        }
      +      } else {
      +         if (stickyHeaderElement.classList.contains('sticky-header')) {
      +           stickyHeaderElement.classList.remove('sticky-header');
      +         }
      +      }
      

      All this logic can be just one line by using toggle()

  • Merge request !8235Resolve #3163765 "Add toggle" โ†’ (Open) created by yash.rode
  • Pipeline finished with Canceled
    26 days ago
    Total: 125s
    #187047
  • Pipeline finished with Failed
    26 days ago
    Total: 204s
    #187052
  • Pipeline finished with Failed
    26 days ago
    Total: 221s
    #187088
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia yash.rode pune

    I am working on adding the test.

  • Pipeline finished with Failed
    23 days ago
    Total: 179s
    #189678
  • Pipeline finished with Failed
    22 days ago
    Total: 180s
    #189756
  • Pipeline finished with Failed
    22 days ago
    Total: 189s
    #189787
  • Pipeline finished with Failed
    22 days ago
    Total: 546s
    #189793
  • Pipeline finished with Failed
    22 days ago
    Total: 190s
    #189841
  • Pipeline finished with Failed
    22 days ago
    Total: 582s
    #189846
  • Pipeline finished with Success
    22 days ago
    Total: 587s
    #189922
  • Status changed to Needs review 22 days ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia yash.rode pune
  • Status changed to Needs work 19 days ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States bnjmnm Ann Arbor, MI

    This is consuming quite a bit of space for a control that most users will be indifferent to.

    The location "show row weights" button, while not perfect (as mentioned in #7) is probably a better option as it is less greedy while still being visible.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States bnjmnm Ann Arbor, MI

    I have selected demo_umami profile because we get the ready made list of contents to check the sticky feature? Should I remove this and add content manually?

    Yep, you'll need to add some dummy content, the need for nodes to fill the table isn't justification to use a whole profile. Creating what you need can be done in a handful of lines with a loop that calls $this->drupalCreateNode() enough times to fill the view.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia yash.rode pune

    It is not working for stark theme, I will have to debug that more to figure that out.

  • Pipeline finished with Success
    19 days ago
    Total: 600s
    #193493
  • Pipeline finished with Failed
    19 days ago
    Total: 735s
    #193501
  • Pipeline finished with Failed
    18 days ago
    Total: 5705s
    #193529
  • Pipeline finished with Failed
    16 days ago
    Total: 624s
    #195232
  • Pipeline finished with Failed
    16 days ago
    Total: 544s
    #195279
  • Pipeline finished with Failed
    16 days ago
    Total: 538s
    #195323
  • Pipeline finished with Failed
    16 days ago
    #195348
  • Pipeline finished with Success
    16 days ago
    Total: 541s
    #195355
  • Pipeline finished with Failed
    16 days ago
    #195365
  • Pipeline finished with Failed
    15 days ago
    Total: 611s
    #195461
  • Pipeline finished with Failed
    15 days ago
    Total: 538s
    #195474
  • Pipeline finished with Failed
    15 days ago
    Total: 512s
    #195500
  • Pipeline finished with Canceled
    15 days ago
    Total: 816s
    #195542
  • Pipeline finished with Failed
    15 days ago
    Total: 539s
    #195553
  • Pipeline finished with Failed
    15 days ago
    Total: 513s
    #195581
  • Pipeline finished with Canceled
    15 days ago
    Total: 725s
    #195586
  • Pipeline finished with Failed
    15 days ago
    #195603
  • Pipeline finished with Failed
    15 days ago
    Total: 1702s
    #195599
  • Pipeline finished with Success
    15 days ago
    Total: 623s
    #195627
  • Pipeline finished with Success
    15 days ago
    Total: 566s
    #196106
  • Status changed to Needs review 15 days ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia yash.rode pune
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    So tested out on the permissions page and not sure how I feel about it haha. I like the control it gives but also wonder if it should be a theme setting. "Allow users to toggle sticky headers" so if you don't really want it you could turn off.

    Functionally though working as advertised.

    Leaving in NR for additional feedback

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States pyrello

    +1 for theme setting.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    smustgrave โ†’ changed the visibility of the branch 3163765-add-option-to to hidden.

  • Status changed to Needs work 6 days ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Cleaning up MR and patches some. Could we add the theme setting?

  • Status changed to Needs review 6 days ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia yash.rode pune

    It is mainly for the accessibility users, so it makes more sense for it to be just above the table instead of going to theme settings page and changing it there.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Then I may be a -1 for it as it feel kinda awkward with the current placement

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States bnjmnm Ann Arbor, MI

    I'm not sure a theme setting would work well here for a few reasons:

    • This doesn't work as well as a site-level setting. It's something that should be available on a per-user level
    • An AT-using user that wants to disable sticky should not need to have permissions to change theme settings
    • There's a reduced likelihood of a user knowing such an option even exists as it is no longer in the same location as the UI element it impacts

    I mentioned the hide/show weights toggle in #28 as a table-specific A11y setting that has existed in Drupal core for some time without much objection. Were the positioning of the sticky toggle more similar to hide/show weights I suspect the awkwardness would be mitigated.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Were the positioning of the sticky toggle more similar to hide/show weights I suspect the awkwardness would be mitigated.

    I'd agree with that statement too.

Production build 0.69.0 2024