Problem/Motivation

Some accessibility concerns about the use of sticky table headers were brought up in #3070558: Implement bulk operation designs.

@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

Issue fork drupal-3163765

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

bnjmnm created an issue. See original summary.

bnjmnm’s picture

Status: Active » Needs review
StatusFileSize
new8.01 KB
new3.12 MB

This patch adds a disable sticky toggle, a video of it in use is also provided.

bnjmnm’s picture

Title: Add option to un-sticky table headers, to benefit assistive tech users. » Add option to un-sticky table headers to benefit assistive tech users
bnjmnm’s picture

Issue tags: +Accessibility
lauriii’s picture

andrewmacpherson’s picture

Adding a toggle that allows enabling/disabling of sticky headers

Where will the toggle be found?
What will the default state be?

Personally, I think a toggle is a "lipstick on a pig" approach, because we're presenting a UI with accessibility problems, then expecting users to turn on a more accessible version. That introduces a discoverability problem. It will be better if content is never obscured by sticky headers in the first place.

Somewhere else there's an issue about changing the page margins when a sticky header is used. (Or maybe it's an issue about the toolbar? It's the same problem either way.)

andrewmacpherson’s picture

Oops, I failed to notice there was a movie attachment in #2. Now I see where the toggle is.

Having the toggle adjacent to the content which it controls is generally a good idea. The somewhat annoying thing is that by the time you realize you need the toggle, it's no longer in the viewport. So there's effort involved to get what you need; you need to back-track to find the control. There might also be a some discoverability and/or working memory aspects too; did you notice the control was available before scrolling?

+  Drupal.theme.disableStickyHeaderButton = () =>
+    `<div class="tableheader-toggle-sticky"><button data-drupal-toggle-sticky-header class="link">${Drupal.theme(
+      'disableStickyHeaderContent',
+    )}</button></div>`;
+
+  /**
+   * Theme function for the contents of a sticky header toggle button.
+   *
+   * @return {string}
+   *   The text and/or html that will appear in the sticky header toggle button.
+   */
+  Drupal.theme.disableStickyHeaderContent = () =>
+    disableStickyHeader
+      ? Drupal.t('Enable Sticky Header')
+      : Drupal.t('Disable sticky header');

This would be clearer if it was a checkbox, or role="switch", rather than a button which changes it's name. The problem with the latter is that it conflates purpose-of-control with current state. For anything other than a very commonly-recognized toggle such as play/pause, a button which changes it's name can be confusing. A checkbox is a cleaner separation of name, role, and value. (Another problem is that some assistive tech doesn't pick up on the accessible name change; I think have some reference material bookmarked about this. I'm unsure about the current state of play.)

FWIW, our "show/hide row weights" buttons also have this problem, and it isn't a good pattern to repeat. I think we have an issue about that already.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new143 bytes

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.

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mgifford’s picture

Issue tags: +wcag247

yash.rode made their first commit to this issue’s fork.

yash.rode’s picture

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

bnjmnm’s picture

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: #3362276: Use position: sticky for views sticky table header 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.

yash.rode’s picture

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.

yash.rode’s picture

StatusFileSize
new3.1 KB

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.

yash.rode’s picture

StatusFileSize
new2.88 KB

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 #3439580: Make drupal.tableheader only use CSS for sticky table headers just got in, which makes all this of no use.

yash.rode’s picture

StatusFileSize
new2.31 KB

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.

bnjmnm’s picture

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()

yash.rode’s picture

I am working on adding the test.

yash.rode’s picture

Status: Needs work » Needs review
bnjmnm’s picture

Status: Needs review » Needs work
StatusFileSize
new98.75 KB
new216.69 KB

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.

bnjmnm’s picture

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.

yash.rode’s picture

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

yash.rode’s picture

Status: Needs work » Needs review
smustgrave’s picture

StatusFileSize
new261.25 KB

permission

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

pyrello’s picture

+1 for theme setting.

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

smustgrave’s picture

Status: Needs review » Needs work

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

yash.rode’s picture

Status: Needs work » Needs review

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.

smustgrave’s picture

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

bnjmnm’s picture

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.

smustgrave’s picture

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.

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

utkarsh_33’s picture

Addressed feedbacks mentioned in #38.

simohell’s picture

Status: Needs review » Needs work
StatusFileSize
new81.18 KB

The current MR seems to add the checkbox twice on admin/content - once before and once after the toggle for in a narrow view toggling on and off the low priority column. The order of the two toggles is something to be decided. The toggle seems to be missing admin/content/blocks, admin/content/files or admin/content/media - the last of which also has an alternative grid-view that doesn't need one.

A screenshot from admin/content start of table, showing sticky headers checkbox as double.

On permissions page the checkbox is also doubled, but there are no other controls in between.

I think we should have do both the toggles with similar implementation. Now one is a checkbox and the other is a button. Styling can then be decided per theme if one would like to use a pin-icon for sighted users etc.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.