Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useConstrainedTabbing steals focus from elements with tabindex="-1" #34681

Closed
Aljullu opened this issue Sep 9, 2021 · 0 comments · Fixed by #34836
Closed

useConstrainedTabbing steals focus from elements with tabindex="-1" #34681

Aljullu opened this issue Sep 9, 2021 · 0 comments · Fixed by #34836
Assignees
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@Aljullu
Copy link
Contributor

Aljullu commented Sep 9, 2021

Description

If an element with tabindex="-1" is focused and is rendered inside a component using useConstrainedTabbing(), pressing Tab will not focus the next focusable element, but instead it will go back to the first focusable item.

Step-by-step reproduction instructions

One way to reproduce this issue is to modify the <Modal> story:

<Modal { ...props } onRequestClose={ closeModal }>
<Button variant="secondary" onClick={ closeModal }>
Close Modal
</Button>
</Modal>

Like this:

<Modal { ...props } onRequestClose={ closeModal }>
+	<Button>Button 1</Button>
+	<div className="placeholder-div" tabIndex={ -1 } />
+	<Button>Button 2</Button>
+	<Button
+		onClick={ () => {
+			const placeholder = document.querySelector(
+				'.placeholder-div'
+			);
+			placeholder.focus();
+		} }
+	>
+		Button 3
+	</Button>
	<Button variant="secondary" onClick={ closeModal }>
		Close Modal
	</Button>
</Modal>
  1. Run npm run storybook.
  2. Go to the Modal story, open the modal and, navigating with the keyboard, focus and click Button 3.
  3. Focus has moved to placeholder-div.

Expected behavior:
4. Pressing Tab will focus Button 2.

Actual behavior:
4. Pressing Tab focuses close button.

Screenshots, screen recording, code snippet

Actual:

actual.mp4

Expected:

expected.mp4

Environment info

No response

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

@Aljullu Aljullu added [Type] Bug An existing feature does not function as intended [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components labels Sep 9, 2021
@Aljullu Aljullu self-assigned this Sep 9, 2021
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Components /packages/components [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
1 participant