You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Post author combo box receives focus on page load #42285
Needs DevReady for, and needs developer efforts[Focus] Accessibility (a11y)Changes that impact accessibility and need corresponding review (e.g. markup changes).[Package] Components/packages/components[Priority] HighUsed to indicate top priority items that need quick attention[Type] BugAn existing feature does not function as intended
When editing an existing post and you have at least 25 users to select from the post author combo box, focus is automatically placed on the combo box after page load is complete. I expect this to not happen.
Step-by-step reproduction instructions
Ensure you have 25+ users on your site.
Open an existing post or page.
Notice how focus is moved to the post author combo box just after the page finishes loading.
Screenshots, screen recording, code snippet
No response
Environment info
Gutenberg trunk
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
@ciampo I assigned this to you because you worked on the last issue with the duplicate IDs. I am not sure if this is related to the ComboboxControl component, I could not find anything there, this may be coming from somewhere else. I just do not have the time to track it down. If you do not have time either, any ideas who might be able to investigate? This is a super annoying issue.
Hey folks, I'll keep an eye open for updates on this issue but at the moment I'm struggling to keep up with my notifications queue. I'll try to get to this one eventually, if no-one else can do before me.
I looked in to this a bit more. Part of me wonders if something about setting the initially selected author is causing some type of focus to occur. This select has a ton of event listeners and it happens quick enough to make me think it could be some type of initial selection firing the onChange. Maybe that provides a place to start?
I looked into this a bit, and unfortunately could not reproduce. I suspect there is a missing repro condition. Here is an E2E test I tried in both headed/headless mode, and in Desktop Chrome/Firefox:
E2E test code
/** * WordPress dependencies */const{ test, expect }=require('@wordpress/e2e-test-utils-playwright');constdelay=(ms)=>newPromise((resolve)=>setTimeout(resolve,ms));test.describe('Author combobox',()=>{test.beforeAll(async({ requestUtils })=>{awaitrequestUtils.deleteAllUsers();});test.beforeEach(async({ admin, requestUtils })=>{awaitPromise.all([ ...Array(30).keys()].map((i)=>requestUtils.createUser({username: `user${i}`,email: `user${i}@test.com`,password: 'password',roles: ['author'],})));awaitadmin.createNewPost();});test.afterEach(async({ requestUtils })=>{awaitrequestUtils.deleteAllUsers();});test('should not autofocus after loading an existing post with 25+ possible authors',async({
browser,
editor,
page,})=>{awaiteditor.insertBlock({name: 'core/paragraph',});awaitpage.keyboard.type('foo');constpostId=awaiteditor.publishPost();constfreshContext=awaitbrowser.newContext();constuncachedPage=awaitfreshContext.newPage();awaituncachedPage.goto(`wp-admin/post.php?post=${postId}&action=edit`,{waitUntil: 'networkidle',});constcombobox=uncachedPage.locator('role=combobox[name="admin, Author"i]');awaitdelay(3000);awaitexpect(combobox).toBeVisible();awaitexpect(combobox).not.toBeFocused();});});
I also inspected the relevant code paths (editor/src/components/post-author and components/src/combobox-control) and could not think of a way this unwanted focus could happen. I would think it has something to do with async loading of the users data though 🤔
Also confirming that I was unable to reproduce this on macOS / Safari or Chrome 😞. I've pinged #core-test to see if we can rope in any Windows users to help.
As @alexstine noted, once there are 25+ authors available, the Author components-input-control (a typical <select>) shifts to components-combobox-control (a JS-driven <input>).
For anyone wishing to attempt to reproduce this issue, I might suggest the following WP-CLI command to quickly generate 25 editor users:
I was able to partially reproduce this with NVDA/Firefox. On loading a post editor with the described conditions met, the last read text from NVDA announced the author combobox. However, it didn't seem like it actually had focus; when I navigated with tab, I landed on the Skip link at the top of the page, as normal. Could that load condition be getting fed to an aria-live region or alert?
On Chrome and Edge, I was unable to reproduce the issue.
On Firefox: I reproduced the issue as described by @joedolson.
Also reproduced when adding a new post, so it's not just on existing posts.
I've attached a brief video which shows me navigating to edit an existing post, and the author box being highlighted by Narrator. I then press tab, which focuses on the View posts link to the top left (i.e. the WordPress Logo).
Did some further digging and the issue exists from WordPress 5.9 onwards. I installed WordPress 5.8.5 and stepped through Gutenberg versions. It was introduced in Gutenberg 11.4.0.
In that release, there's one item marked for accessibility, which is:
Add aria-describedby to custom select control component to describe currently-selected font size. (#33941)
The attribute itself does not seem to be the problem, but I believe the onChange is updating the currently selected index which causes a focus force because that is what the attribute is intended to do. Sadly, this is another example of how ARIA comes back to haunt us.
I am working on figuring out if there is much that can be done. I may try to inject the attribute after the initial value is set but this is getting to be quite complex.
Well, my PR can in my opinion, only be described as a fun work of art. I have no idea why it works or how it works, but the important take away is this. I am simply manipulating at which point aria-activedescendant has a value. For example, the attribute should only exist when the user moves their focus to the combo box but not before this due to the setting of the default value. When the value changes, it updates the selection index which then tells aria-activedescendant to update. Whenever this attribute updates, it moves focus because that is what it is meant to do. At least immolating focus. From my understanding, most combo boxes of this type use a button to trigger them and this may be why other large projects do not see such an issue. It could also be that other combo boxes are not setting the default value async from an API.
Anyway, my thoughts at nearly 1AM. Hopefully someone follows this.
Interesting. Reading the docs, this makes sense with what I was seeing. aria-activedescendant doesn't actually set focus, it just informs AT what element has focus. Which would align with getting information about focus, but having keyboard navigation be located at the top of the screen.
It seems to me like aria-activedescendant should only be set at all if the composite widget has focus. The value should probably be held in a value attribute and should dynamically set the active descendant only on focus.
Since aria-activedescendent is specifically about setting and managing focus, I don't think it is appropriate on an unfocused element. Since the combobox uses an input element as the root element, it's appropriate to use value to track the current value.
@joedolson This was super tricky to fix due to the conditional rendering. I just pushed some updates to my PR. Can you check those out? I actually eliminated a couple ARIA attributes and I think it works just as well. Just be sure to watch for visual regressions I introduced. Hopefully this did not change the way screen readers communicate the visual order.
Pushed another large batch of changes. Since I apparently cannot read, I fixed my mistakes. Instead of using the value to show the changing items in real time, I removed the aria-label so value could communicate the selected label directly to screen readers.
@joedolson My PR is now in line with what I think you were intending to communicate. Testing should be much easier now. 👍
After reviewing @alexstine 's PR, I also created a PR with an alternative approach #44526 — it would be good if @joedolson and @costdev (who were both able to reproduce the issue) could take a look as well. Thank you!
Needs DevReady for, and needs developer efforts[Focus] Accessibility (a11y)Changes that impact accessibility and need corresponding review (e.g. markup changes).[Package] Components/packages/components[Priority] HighUsed to indicate top priority items that need quick attention[Type] BugAn existing feature does not function as intended
Activity
alexstine commentedon Jul 9, 2022
@ciampo I assigned this to you because you worked on the last issue with the duplicate IDs. I am not sure if this is related to the ComboboxControl component, I could not find anything there, this may be coming from somewhere else. I just do not have the time to track it down. If you do not have time either, any ideas who might be able to investigate? This is a super annoying issue.
Thanks.
Mamaduka commentedon Jul 13, 2022
Hi, @alexstine
I couldn't reproduce the issue using Chrome / MacOS. Are there any details I'm missing for reproduction?
ciampo commentedon Jul 13, 2022
Hey folks, I'll keep an eye open for updates on this issue but at the moment I'm struggling to keep up with my notifications queue. I'll try to get to this one eventually, if no-one else can do before me.
alexstine commentedon Jul 13, 2022
@Mamaduka I tested on Windows with Firefox. It may not be reproduceable on Mac.
alexstine commentedon Sep 16, 2022
Follow-up: https://wordpress.slack.com/archives/C02QB2JS7/p1663289397915119
alexstine commentedon Sep 16, 2022
I looked in to this a bit more. Part of me wonders if something about setting the initially selected author is causing some type of focus to occur. This select has a ton of event listeners and it happens quick enough to make me think it could be some type of initial selection firing the onChange. Maybe that provides a place to start?
mirka commentedon Sep 21, 2022
I looked into this a bit, and unfortunately could not reproduce. I suspect there is a missing repro condition. Here is an E2E test I tried in both headed/headless mode, and in Desktop Chrome/Firefox:
E2E test code
I also inspected the relevant code paths (
editor/src/components/post-authorandcomponents/src/combobox-control) and could not think of a way this unwanted focus could happen. I would think it has something to do with async loading of the users data though 🤔ironprogrammer commentedon Sep 21, 2022
Also confirming that I was unable to reproduce this on macOS / Safari or Chrome 😞. I've pinged #core-test to see if we can rope in any Windows users to help.
As @alexstine noted, once there are 25+ authors available, the Author
components-input-control(a typical<select>) shifts tocomponents-combobox-control(a JS-driven<input>).For anyone wishing to attempt to reproduce this issue, I might suggest the following WP-CLI command to quickly generate 25 editor users:
joedolson commentedon Sep 21, 2022
I was able to partially reproduce this with NVDA/Firefox. On loading a post editor with the described conditions met, the last read text from NVDA announced the author combobox. However, it didn't seem like it actually had focus; when I navigated with tab, I landed on the Skip link at the top of the page, as normal. Could that load condition be getting fed to an aria-live region or alert?
costdev commentedon Sep 22, 2022
Tested on Windows 10 with NVDA and Narrator.
I've attached a brief video which shows me navigating to edit an existing post, and the author box being highlighted by Narrator. I then press tab, which focuses on the View posts link to the top left (i.e. the WordPress Logo).
Author.issue.-.Windows.-.Firefox.-.Narrator.mp4
costdev commentedon Sep 22, 2022
Did some further digging and the issue exists from WordPress 5.9 onwards. I installed WordPress 5.8.5 and stepped through Gutenberg versions. It was introduced in Gutenberg 11.4.0.
In that release, there's one item marked for accessibility, which is:
See the full changelog for Gutenberg 11.4.0.
alexstine commentedon Sep 22, 2022
Thanks all for looking in to this. I think I finally found what is causing it.
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-activedescendant
The attribute itself does not seem to be the problem, but I believe the onChange is updating the currently selected index which causes a focus force because that is what the attribute is intended to do. Sadly, this is another example of how ARIA comes back to haunt us.
I am working on figuring out if there is much that can be done. I may try to inject the attribute after the initial value is set but this is getting to be quite complex.
alexstine commentedon Sep 22, 2022
Well, my PR can in my opinion, only be described as a fun work of art. I have no idea why it works or how it works, but the important take away is this. I am simply manipulating at which point
aria-activedescendanthas a value. For example, the attribute should only exist when the user moves their focus to the combo box but not before this due to the setting of the default value. When the value changes, it updates the selection index which then tellsaria-activedescendantto update. Whenever this attribute updates, it moves focus because that is what it is meant to do. At least immolating focus. From my understanding, most combo boxes of this type use a button to trigger them and this may be why other large projects do not see such an issue. It could also be that other combo boxes are not setting the default value async from an API.Anyway, my thoughts at nearly 1AM. Hopefully someone follows this.
joedolson commentedon Sep 22, 2022
Interesting. Reading the docs, this makes sense with what I was seeing.
aria-activedescendantdoesn't actually set focus, it just informs AT what element has focus. Which would align with getting information about focus, but having keyboard navigation be located at the top of the screen.It seems to me like
aria-activedescendantshould only be set at all if the composite widget has focus. The value should probably be held in avalueattribute and should dynamically set the active descendant only on focus.Since
aria-activedescendentis specifically about setting and managing focus, I don't think it is appropriate on an unfocused element. Since the combobox uses aninputelement as the root element, it's appropriate to usevalueto track the current value.alexstine commentedon Sep 22, 2022
@joedolson This was super tricky to fix due to the conditional rendering. I just pushed some updates to my PR. Can you check those out? I actually eliminated a couple ARIA attributes and I think it works just as well. Just be sure to watch for visual regressions I introduced. Hopefully this did not change the way screen readers communicate the visual order.
alexstine commentedon Sep 28, 2022
Pushed another large batch of changes. Since I apparently cannot read, I fixed my mistakes. Instead of using the
valueto show the changing items in real time, I removed thearia-labelsovaluecould communicate the selected label directly to screen readers.@joedolson My PR is now in line with what I think you were intending to communicate. Testing should be much easier now. 👍
ciampo commentedon Sep 28, 2022
After reviewing @alexstine 's PR, I also created a PR with an alternative approach #44526 — it would be good if @joedolson and @costdev (who were both able to reproduce the issue) could take a look as well. Thank you!