File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -22,13 +22,8 @@ export default function useDropdownMenu(itemCount: number) {
2222 itemRefs . current [ itemIndex ] . current ?. focus ( ) ;
2323 } ;
2424
25- // Run whenever the menu opens/closes
25+ // Focus the first item when the menu opens
2626 useEffect ( ( ) => {
27- // Stop if the ref currently points to a null value
28- if ( ! itemRefs . current [ 0 ] . current || ! buttonRef . current ) {
29- return ;
30- }
31-
3227 // Stop if this is the first fire of the Hook, and update the ref
3328 if ( firstRun . current ) {
3429 firstRun . current = false ;
@@ -39,7 +34,10 @@ export default function useDropdownMenu(itemCount: number) {
3934 if ( isOpen ) {
4035 moveFocus ( 0 ) ;
4136 }
37+ } , [ isOpen ] ) ;
4238
39+ // Handle listening for clicks and auto-hiding the menu
40+ useEffect ( ( ) => {
4341 // This function is designed to handle every click
4442 const handleEveryClick = ( event : MouseEvent ) => {
4543 // Ignore if the menu isn't open
You can’t perform that action at this time.
0 commit comments