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 841d270
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions components/menu/src/flyout-menu/flyout-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ const FlyoutMenu = ({

const divRef = useRef(null)

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

useEffect(() => {
if (!divRef) {
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 () => {
Expand Down

0 comments on commit 841d270

Please sign in to comment.