Skip to content

feat(Gallery): adds inert to inactive slides - #139

Open
NicholasLancey wants to merge 2 commits into
mainfrom
feature/adds-inert-to-inactive-slides
Open

NicholasLancey wants to merge 2 commits into
mainfrom
feature/adds-inert-to-inactive-slides

Conversation

@NicholasLancey

Copy link
Copy Markdown
Contributor

Summary

Fixes: #137

Inactive gallery items are now inert by 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 the inert attribute, next to the existing aria-hidden. Your own props are applied after the defaults, so you can opt out per item with inert={false}. That's useful when several slides are visible at once with visibleRange.
  • GalleryPaginationItem: clicking a pagination item moves focus to the new slide before React re-renders, while that slide is still inert, so the focus wouldn't land. The click handler now clears inert on the target node just before calling focus().
  • GalleryNav: when the next or previous button becomes disabled, focus moves to the active slide. That happens during render, before React removes the slide's inert, so the nav clears inert on the slide just before focusing it, as GalleryPaginationItem does.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread README.md Outdated
| 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}`:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need aria-hidden="true" if it's inert, do we?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update to add inert on inactive slides by default

2 participants