File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed
Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -309,6 +309,23 @@ const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
309309 setFlyoutRef ( null ) ;
310310 }
311311 } ;
312+
313+ React . useEffect ( ( ) => {
314+ if ( isFocused && ref . current ) {
315+ const itemEl = ref . current ;
316+ const parentListEl = itemEl . parentElement ;
317+
318+ if ( parentListEl ) {
319+ const isAboveTop = itemEl . offsetTop - parentListEl . offsetTop < parentListEl . scrollTop ;
320+ const isBelowBottom = itemEl . offsetTop - parentListEl . offsetTop + itemEl . clientHeight ;
321+
322+ if ( isAboveTop || isBelowBottom ) {
323+ itemEl . scrollIntoView ( { behavior : 'smooth' , block : 'nearest' } ) ;
324+ }
325+ }
326+ }
327+ } , [ isFocused ] ) ;
328+
312329 const isSelectMenu = menuRole === 'listbox' ;
313330
314331 const renderItem = (
@@ -428,13 +445,7 @@ const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
428445 { ...( hasCheckbox && { 'aria-label' : ariaLabel } ) }
429446 { ...props }
430447 >
431- { tooltipProps ? (
432- < Tooltip { ...tooltipProps } >
433- { renderItem }
434- </ Tooltip >
435- ) : (
436- renderItem
437- ) }
448+ { tooltipProps ? < Tooltip { ...tooltipProps } > { renderItem } </ Tooltip > : renderItem }
438449 </ li >
439450 ) ;
440451} ;
You can’t perform that action at this time.
0 commit comments