diff --git a/docs/data/joy/components/button-group/SplitButton.js b/docs/data/joy/components/button-group/SplitButton.js index 40b68f3ac669f8..9ffdd206a964a7 100644 --- a/docs/data/joy/components/button-group/SplitButton.js +++ b/docs/data/joy/components/button-group/SplitButton.js @@ -23,6 +23,19 @@ export default function SplitButton() { setOpen(false); }; + const handleOutsideClick = (event) => { + if (anchorRef.current && !anchorRef.current.contains(event.target)) { + setOpen(false); + } + }; + + React.useEffect(() => { + document.addEventListener('mousedown', handleOutsideClick); + return () => { + document.removeEventListener('mousedown', handleOutsideClick); + }; + }, []); + return ( { + if (anchorRef.current && !anchorRef.current.contains(event.target as Node)) { + setOpen(false); + } + }; + + React.useEffect(() => { + document.addEventListener('mousedown', handleOutsideClick); + return () => { + document.removeEventListener('mousedown', handleOutsideClick); + }; + }, []); + return (