From 841d2702c694df4f28fec76261c711aae58c4497 Mon Sep 17 00:00:00 2001 From: Diana Nanyanzi Date: Sun, 30 Jun 2024 21:50:50 +0300 Subject: [PATCH] refactor: conditional focus of flyout menu --- components/menu/src/flyout-menu/flyout-menu.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/components/menu/src/flyout-menu/flyout-menu.js b/components/menu/src/flyout-menu/flyout-menu.js index aa8aec0e90..7b2343c087 100644 --- a/components/menu/src/flyout-menu/flyout-menu.js +++ b/components/menu/src/flyout-menu/flyout-menu.js @@ -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 () => {