Skip to content

Post author combo box receives focus on page load #42285

Closed

Description

@alexstine

Description

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

  1. Ensure you have 25+ users on your site.
  2. Open an existing post or page.
  3. 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.

Yes

Activity

  1. added
    [Type] Bug
    [Focus] Accessibility (a11y)
    Needs Dev
    on Jul 9, 2022
  2. alexstine commented on Jul 9, 2022

    @alexstine
    ContributorAuthor

    @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.

  3. Mamaduka commented on Jul 13, 2022

    @Mamaduka
    Member

    Hi, @alexstine

    I couldn't reproduce the issue using Chrome / MacOS. Are there any details I'm missing for reproduction?

  4. ciampo commented on Jul 13, 2022

    @ciampo
    Contributor

    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.

  5. alexstine commented on Jul 13, 2022

    @alexstine
    ContributorAuthor

    @Mamaduka I tested on Windows with Firefox. It may not be reproduceable on Mac.

  6. added
    [Priority] High
    on Sep 16, 2022
  7. alexstine commented on Sep 16, 2022

    @alexstine
    ContributorAuthor
  8. alexstine commented on Sep 16, 2022

    @alexstine
    ContributorAuthor

    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?

  9. mirka commented on Sep 21, 2022

    @mirka
    Member

    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' );
    
    const delay = ( ms ) => new Promise( ( resolve ) => setTimeout( resolve, ms ) );
    
    test.describe( 'Author combobox', () => {
    	test.beforeAll( async ( { requestUtils } ) => {
    		await requestUtils.deleteAllUsers();
    	} );
    
    	test.beforeEach( async ( { admin, requestUtils } ) => {
    		await Promise.all(
    			[ ...Array( 30 ).keys() ].map( ( i ) =>
    				requestUtils.createUser( {
    					username: `user${ i }`,
    					email: `user${ i }@test.com`,
    					password: 'password',
    					roles: [ 'author' ],
    				} )
    			)
    		);
    
    		await admin.createNewPost();
    	} );
    
    	test.afterEach( async ( { requestUtils } ) => {
    		await requestUtils.deleteAllUsers();
    	} );
    
    	test( 'should not autofocus after loading an existing post with 25+ possible authors', async ( {
    		browser,
    		editor,
    		page,
    	} ) => {
    		await editor.insertBlock( {
    			name: 'core/paragraph',
    		} );
    		await page.keyboard.type( 'foo' );
    		const postId = await editor.publishPost();
    
    		const freshContext = await browser.newContext();
    		const uncachedPage = await freshContext.newPage();
    		await uncachedPage.goto(
    			`wp-admin/post.php?post=${ postId }&action=edit`,
    			{
    				waitUntil: 'networkidle',
    			}
    		);
    
    		const combobox = uncachedPage.locator(
    			'role=combobox[name="admin, Author"i]'
    		);
    		await delay( 3000 );
    		await expect( combobox ).toBeVisible();
    		await expect( 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 🤔

  10. ironprogrammer commented on Sep 21, 2022

    @ironprogrammer
    Member

    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:

    wp user generate --count=25 --role=editor
  11. joedolson commented on Sep 21, 2022

    @joedolson
    Contributor

    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?

  12. costdev commented on Sep 22, 2022

    @costdev
    Contributor

    Tested on Windows 10 with NVDA and Narrator.

    • 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).

    Author.issue.-.Windows.-.Firefox.-.Narrator.mp4
  13. costdev commented on Sep 22, 2022

    @costdev
    Contributor

    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)

    See the full changelog for Gutenberg 11.4.0.

  14. alexstine commented on Sep 22, 2022

    @alexstine
    ContributorAuthor

    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.

  15. added
    [Status] In Progress
    on Sep 22, 2022
  16. alexstine commented on Sep 22, 2022

    @alexstine
    ContributorAuthor

    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.

  17. joedolson commented on Sep 22, 2022

    @joedolson
    Contributor

    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.

  18. alexstine commented on Sep 22, 2022

    @alexstine
    ContributorAuthor

    @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.

  19. alexstine commented on Sep 28, 2022

    @alexstine
    ContributorAuthor

    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. 👍

  20. ciampo commented on Sep 28, 2022

    @ciampo
    Contributor

    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!

  21. removed
    [Status] In Progress
    on May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Needs Dev[Focus] Accessibility (a11y)[Package] Components[Priority] High[Type] Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions