Skip to content

Commit

Permalink
refactor: conditional focus of flyout menu
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rita committed Jun 30, 2024
1 parent f31fd08 commit 3a6e749
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions components/menu/src/flyout-menu/flyout-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,26 @@ const FlyoutMenu = ({

const divRef = useRef(null)

const handleFocus = (event) => {
if (event.target === divRef.current) {
divRef.current.children[0].focus()
}
}

useEffect(() => {
if (!divRef) {
if (!divRef.current) {
return
}
const div = divRef.current

const handleFocus = (event) => {
if (event.target === div) {
if (div.children && div.children.length > 0) {
div.children[0].focus()
}
}
}

div.addEventListener('focus', handleFocus)

return () => {
div.removeEventListener('focus', handleFocus)
}
})
}, [])

return (
<div
Expand Down

0 comments on commit 3a6e749

Please sign in to comment.