Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/happy-days-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wethegit/react-gallery": patch
---

Fix the lost focus in Safari when the pressed nav button is disabled
10 changes: 9 additions & 1 deletion src/lib/components/gallery-nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const GalleryNav = ({
children,
...props
}) => {
const { next, previous, loop, activeIndex, galleryItems } = useGallery()
const { next, previous, loop, activeIndex, galleryItems, itemNodes } = useGallery()

const handleClick = () => {
if (direction) next()
Expand All @@ -33,6 +33,14 @@ export const GalleryNav = ({

if (!children && !renderNavItem) return null

/*
* When the clicked/pressed button gets disabled, focus is reset
* to the document, so we are redirecting the focus within the gallery
*/
if (shouldDisable) {
itemNodes.current[activeIndex]?.focus({ focusVisible: false })
}

return (
<button
className={classnames([
Expand Down
Loading