Problem/Motivation
There is a visually-hidden text input for editing the machine name, in between the "Edit" button and the "Description" text area.
Pressing the Edit button reveals the "Machine-readable name" text input field, by removing a visually-hidden CSS class from a wrapper <div>. The problem is that when the machine-readable name field is visually hidden, it still exists in the tab order for the page.
Steps to reproduce
You can experience the problem anywhere that we use a "machine-readable name" field. For example:
Visit "Add content type" at admin/structure/types/add.
- Type a name (e.g. "Book Review") for the content type in the "Name" field. While you do this, the text "Machine name: book_review [edit]" appears nearby.
- While you still have keyboard focus inside the "Name" field, press tab. It is not focus moves to the [Edit] button, which gains an underline style.
- Press tab again. It is not visually clear where focus has moved to. THIS IS THE BUG. Focus is on a text field for the machine name, which is visually-hidden but still in the keyboard tabbing order.
- Press tab again. Focus will move to the "Description" text area.
Tip: the FireFocus add-on for Firefox is a handy tool for tracking focus around the DOM, even when elements are visually hidden.
Proposed resolution
We can fix this by keeping the macine-name text field out of the tabbing order unless the "[Edit]" button is pressed.
Instead of using our .visually-hidden CSS style to conceal the field, we should be removing it from the tabbing order and accessibility tree completely, using CSS display: none.
Drupal 8 already has some CSS utility styles for this. Propose we try "hidden" class instead of "visually-hidden" class in machine-name.js, lines 53 and 112.
As a result of the change proposed here, the hidden machine-name field is no longer picked up by screen readers unless the Machine name: ... [edit] is clicked. In order to improve accessibility, we should add aria-label="Edit machine name" to this button. This will result in a screen reader describing this button as "Edit machine name, button" instead of the current "Edit, button".
Remaining tasks
Patch.Manual testing, with keyboard-onlyManual testing with a screen-reader.
User interface changes
No change to the UI design as such. This is an accessibility improvement, to make the existing interface more robust.
API changes
None proposed.
Data model changes
None.
Original report by cortezj
"Visual focus disappears between user interface elements. As an example within the “Add comment type” screen, after entering data in the “Label” required field and pressing Tab, user is navigated to a dynamically appearing “Edit” links. Pressing the Tab key to navigate away from the “Edit” link causes the focus to disappear. However, pressing the Tab key once more brings the focus to the next field, “Description” text box.
The defect exists in IE 11 and Google Chrome Version 55.0.2883.87 m.
Expected result: An indication of focus is expected to be visually present at all times so that a user can discern their location within the application.
Reference: Section 508, Part 1194.21, Paragraph (c).
Notes:
• This defect also exists elsewhere within the application.
• This is a medium severity defect as the user needs to only press Tab once to bring focus back into the following field and can discern their location."
Also reported by findleys in #2933550: 508 Compliance - Add Menu Page - Visual Focus Disappears.
| Comment | File | Size | Author |
|---|---|---|---|
| #76 | drupal-machine_name_accessibility-2852724-9.5.x.patch | 6.04 KB | au_dave |
| #70 | 2852724-afterpatch.mp4 | 704.84 KB | gaurav-mathur |
| #70 | 2852724-beforepatch.mp4 | 907.69 KB | gaurav-mathur |
Issue fork drupal-2852724
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
Comment #2
kershme commentedComment #3
mgiffordI don't know if this is possible at this time. I believe the behavior you are describing is happening because a link is listed as hidden or invisible. The browser at this time will still navigate to an invisible element and I am unaware of any pattern or best practice that overrides this.
I agree it's annoying.
Comment #4
andrewmacpherson commentedThanks cortezj + kershme, I managed to replicate this.
There is a visually-hidden text input for editing the machine name, in between the "Edit" button and the "Description" text area.
Pressing the Edit button reveals the "Machine-readable name" text input field, by removing a
visually-hiddenCSS class from a wrapper<div>. The problem is that when the machine-readable name field is visually hidden, it still exists in the tab order for the page.We can fix this. Instead of using our
.visually-hiddenCSS style to conceal the field, we should be removing it from the tabbing order and accessibility tree completely, using CSSdisplay: none.Drupal 8 already has some CSS utility styles for this. We just need to use
.hiddeninstead of.visually-hidden.Comment #5
andrewmacpherson commentedI propose we try "hidden" class instead of "visually-hidden" class in
machine-name.js, lines 53 and 112.Comment #6
andrewmacpherson commentedComment #7
andrewmacpherson commentedThis mainly a problem for sighted keyboard-only users who can focus the machine-name input, but not see it on the
screen.
It also means that the machine-name field is presented to screen reader users, to whom it is announced.
Comment #8
andrewmacpherson commentedUpdating issue summary, for whoever works on fixing this. It's a good introductory issue for learning about keyboard accessibility.
Comment #9
andrewmacpherson commentedminor issue summary edit.
Comment #10
andrewmacpherson commentedComment #11
andrewmacpherson commentedComment #12
andrewmacpherson commentedComment #13
andrewmacpherson commentedComment #14
andrewmacpherson commentedComment #15
brenv commentedPatch in core/misc/machine-name.js changing "visually-hidden" to "hidden"
Comment #17
jofitzAddress test failure.
Comment #18
droplet commentedThis is designed for screen reader I think. So that they able to read the machine name change? After patching, it required Drupal.announce to speak it out.
Comment #20
jofitzHaving problems with my local test environment so I'm just gonna throw this one out there.
Comment #21
droplet commentedCompletely hidden elements should be tested with
\Zumba\Mink\Driver\PhantomJSDriver::isVisibleComment #22
droplet commentedComment #23
himanshu-dixit commented@droplet Not too sure if this should be done. Have you read this comment
Comment #24
droplet commentedWith current patch, the comment is wrong. Needs a fix on it.
But again. @see my comment on #18. I think that needs a review and further tweaks and new tests.
Comment #25
droplet commentedPer #21, #18
Comment #27
andrewmacpherson commentedChanging the parent issue, making it part of a wider a11y review.
Comment #28
andrewmacpherson commentedComment #35
au_dave commentedReroll of patch for use with Drupal 9.3.x
Comment #36
vladimirausThanks for commit.
Applies and works on 9.3.
Comment #37
tintoTest fails, because the ES6 version of the file is not modified. Working on a fix now.
Comment #38
tintoI took the necessary changes made in #35 and applied them to the ES6 file too. Also provided a patch version for 9.4.x.
(Sorry, could not generate an interdiff because of a whitespace error.)
Comment #40
rkollerI've had found two separate issue about the machine name problem. for one content types and then for adding block types. i've searched upfront in the course of finding issues in regards of the focus visible meta issue for Claro https://www.drupal.org/project/drupal/issues/3163810 . I've closed both issues marked as duplicate thanks to the notification @tinto who dug up and found the issue. i set this issue as a related issue to the focus visible issue in claro since it is a general drupal issue and not an claro exclusive one.
in regards of #38. i've tested the patch manually against 9.4.x, i was able to apply it and everything worked as expected. i've also did the same with the updated patch for 9.3.x, with the exact same results. so from a manual testing perspective i would say the patch is good to go. from a code perspective i wouldn't consider myself fully qualified (am into content strategy and am not a coder). but except the tests which failed and need some work the rest looks none invasive and correct from my perspective. but a second opinion more knowledgable and code savvy would be welcome to be completely sure :)
Comment #41
tintoMade some additional changes to patch #38 for 9.4.x in an attempt to get the test passed.
Tested this successfully on my local 9.4.x install.
Comment #42
rkollerthank you! i've applied the patch to a 9.4.x install. the patch still applies and the functionality behaves still as expected. so nothing changed function wise from the patch in #38. i've waited with my reply until the tests were finished and they are all on green now :) so your fixes there worked as well. and since the tests mostly changed
visually-hiddentohiddenaccording to the diff in the patch and others have checked those tests withvisually-hiddenbefore i would say the issue could be set to RTBC. the only change i make is i set the version from 9.3.x to 9.4.x for the issue since the patch is for 9.4.x now :)Comment #43
tintoThank you for the quick test and follow-up!
@rkoller, you are correct. Patch #41 basically changes ./core/misc/machine-name.js so that the class that is provided on the form element div of the machine name field is now 'hidden' instead of 'visually-hidden'.
I think this approach is correct for this scenario, especially after reading the Drupal documentation about how to hide content properly. It states the following:
See: https://www.drupal.org/docs/accessibility/hide-content-properly
Comment #44
alexpottI think we need to address #18 directly. I've read all the comments on the issue and not found a response.
Comment #45
tintoI have tested #41 with Chrome Screen Reader and it works for the machine-name field, but only after it has been revealed (by clicking the
Machine name: ... editbutton).I think this makes more sense than having an invisible element that gets picked up by screen readers and causes invisible focus when tabbing through the page. However, I'm no accessibility expert, so I hope someone with more knowledge on the matter can chime in.
P.S. The machine name edit button could use some improvements, as my screen reader currently describes it as "button, edit", not indicating what it is that a user will be editing. Perhaps this warrants a separate issue, depending on the outcome of this one.
Comment #46
andrewmacpherson commentedalexpott asked me to review this, assigning myself. I'd like to test this manually, and remind myself where the moving parts are.
Meanwhile...
Drupal.announce. I think that's likely to be overkill, becauseDrupal.announceis just disrespecting their preferences.Comment #47
tintoThank you for your feedback @andrewmacpherson
Here's a new patch that contains the necessary changes in order to address #21-24, so that
MachineNameTest.phpnow usesisVisible()to check visibility.Concerning #46.3: I propose to add an
aria-label="edit machine-name"attribute to the button element. For my own sanity, I will create a separate patch for this additional change after #47 passes testing.Comment #49
lendudeThis should be assertFalse(), the second machine name field should still be hidden after pressing the button for the first field.
Edit: Oh and the comment should remain 'The ID field must not be visible'
Comment #50
tintoThank you @Lendude. Applying your suggested changes.
Comment #51
lendudeLooks good from a code point of view, setting back to 'needs review' for a review from @andrewmacpherson
Comment #52
tintoI think the last remaining task is to address my PS in #45 (and #46.3). Working on that now.
Comment #53
tintoAdding an aria-label to the
Machine name: ... [Edit]button, so that screen readers now say "Edit machine name, button" instead of "Edit, button".Comment #54
tintoAttempting to fix automated testing error
Edit: fixed!
Comment #55
lendude@tinto code looks great, could you update the Issue summary too with the arguments for the added change to the aria-label?
Comment #56
tintoUpdating the issue summary by with an explanation of the
aria-labeladdition.Comment #59
rkollerthe patch from #54 probably needs a reroll. i was unable to apply it to a fresh install of Drupal 10.1.x-dev with composer-patches. The apply failed.
Comment #61
vladimirausOpened merge request.
Ready for review.
Comment #62
vladimirausComment #63
rkollerthanks for the fast reroll the patch successfully applies in 10.1.x-dev now! i did a brief basic manual test and it looks like there is a regression to the previous patch by @tinto now. i've tested on
/admin/structure/types/add. if i tab through the form the outline disappears in between the name and the description field when the not visible machine name field gets into focus.Comment #64
smustgrave commentedBelieve the issue is because the description field has a tabindex of -1
Comment #65
smustgrave commentedFrom what I can tell this is coming from the tabbingmanager.js line 237
For testing I commented that line out. And when I go to the add content type page I don't lose focus and it goes into description field.
Comment #66
smustgrave commentedDisregard #65. That was because of #2991686: Enabling "Edit" to show all contextual links breaks tabbing in edit forms in the backend
Comment #67
smustgrave commentedFixed the issue with the reroll.
Comment #69
gaurav-mathur commentedComment #70
gaurav-mathur commentedHi i Applied patch#54 on Drupal 9.4.x it works and issue got fixed. adding videos for the reference.
Comment #71
rkollerre #66 oh that is interesting. first I can confirm that your changes fixed the issue that the focus outline was hidden again for one tab press as soon as the edit link got into focus while hidden (tested on 10.1.x-dev). awesome thanks! the only odd detail is, that the patch worked for 9.4, after the reroll the focus not be visible for one tab problem turned up again, but the root cause you have identified for fixing that regression with #2991686: Enabling "Edit" to show all contextual links breaks tabbing in edit forms in the backend is already existing for much longer, so i wonder why it hasnt applied to the patch in 9.4.x (but that shouldn't stop this issue - i was just thinking out loud out of curiosity).
The only thing left to do is just a formal accessibility review and sign off by @andrewmcpherson who assigned himself before but got unassigned in the course by people working on the changes for the reroll. but i am unable to re-assign the issue to him.
Comment #72
vladimirausComment #74
rkollerThanks! I've applied the merge request (3071) with the lastest changes to a Drupal 10.1.x-dev install. I've tested on MacOS with Safari 16.1 and the latest versions in Firefox and Edge. I can confirm that the regression was fixed and the focus outline is displayed as intended again.
I've noticed after i've posted my initial reply that another merge request (3119) was opened. That one fails to apply with composer patches unfortunately on my end. :(
Comment #75
mgiffordI think we can classify this under WCAG 4.1.2.
Comment #76
au_dave commentedRe roll patch for 9.5.x
Comment #77
smustgrave commentedReviewing MR 3071
For accessibility
Before patch
1. Went to /admin/structure/types/add
2. While tabbing focus is lost between label and description
After patch
1. Went to /admin/structure/types/add
2. While tabbing focus goes between label and description with no in between
3. Backtab back to label and type "Test"
4. Machine name appears with Edit link and I can tab to it in this order: Label > edit link > description
5. Press enter on edit link. Can tab and backtab in this order label > machine name > description.
Issue appears to have been solved.
Comment #78
mgiffordThanks for testing this and describing the process you went through @smustgrave.
Based on this, I am going to remove the Needs Accessibility Maintainer tag so this issue can proceed.
Comment #79
smustgrave commentedThanks! @mgifford
Comment #81
lauriiiCommitted 60cce59 and pushed to 10.1.x. Thanks!