Repository navigation
feat(Gallery): adds inert to inactive slides - #139
Open
NicholasLancey wants to merge 2 commits into
Open
NicholasLancey wants to merge 2 commits into
NicholasLancey wants to merge 2 commits into
Conversation
andrewrubin
reviewed
Nov 16, 2026
Comment on lines
+60
to
+61
| // This runs during render, before the item loses `inert`, so clear it now to allow focus | ||
| node.inert = false |
Member
There was a problem hiding this comment.
Manipulating the DOM node like this feels like a React anti-pattern. Are there any other ways to approach the race condition issue described here?
| | active | Boolean | Whether the current item being iterated over is the active item. | | ||
| | index | Number | The index of the currently active gallery item. | | ||
|
|
||
| Inactive items are rendered with the [`inert`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inert) attribute (along with `aria-hidden`), so any focusable content inside them can't be tabbed to or focused. To opt out, for example when several items are visible at once, pass `inert={false}`: |
Member
There was a problem hiding this comment.
Don't think we need aria-hidden="true" if it's inert, do we?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes: #137
Inactive gallery items are now
inertby default. Before this, keyboard users could tab into links and buttons inside inactive slides, even when those slides were hidden.Changes
GalleryItem: inactive items now get theinertattribute, next to the existingaria-hidden. Your own props are applied after the defaults, so you can opt out per item withinert={false}. That's useful when several slides are visible at once withvisibleRange.GalleryPaginationItem: clicking a pagination item moves focus to the new slide before React re-renders, while that slide is stillinert, so the focus wouldn't land. The click handler now clearsinerton the target node just before callingfocus().GalleryNav: when the next or previous button becomes disabled, focus moves to the active slide. That happens during render, before React removes the slide'sinert, so the nav clearsinerton the slide just before focusing it, asGalleryPaginationItemdoes.