diff --git a/components/menu/src/flyout-menu/flyout-menu.js b/components/menu/src/flyout-menu/flyout-menu.js index aa8aec0e90..8cd45bd748 100644 --- a/components/menu/src/flyout-menu/flyout-menu.js +++ b/components/menu/src/flyout-menu/flyout-menu.js @@ -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 (