Skip to content

Commit

Permalink
Ensure items in menu leave menu if there is space
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerJDev committed Dec 23, 2024
1 parent 6d70d1b commit 415b888
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/react/src/ActionBar/ActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const overflowEffect = (
childArray: Array<React.ReactElement>,
childWidthArray: ChildWidthArray,
updateListAndMenu: (props: ResponsiveProps) => void,
hasActiveMenu: boolean,
) => {
if (childWidthArray.length === 0) {
updateListAndMenu({items: childArray, menuItems: []})
Expand Down Expand Up @@ -160,6 +161,9 @@ const overflowEffect = (
}

updateListAndMenu({items, menuItems})
} else if (numberOfItemsPossible >= childArray.length && hasActiveMenu) {
/* If the items fit in the list and there are items in the overflow menu, we need to move them back to the list */
updateListAndMenu({items: childArray, menuItems: []})
}
}

Expand Down Expand Up @@ -203,7 +207,9 @@ export const ActionBar: React.FC<React.PropsWithChildren<ActionBarProps>> = prop
useResizeObserver((resizeObserverEntries: ResizeObserverEntry[]) => {
const navWidth = resizeObserverEntries[0].contentRect.width
const moreMenuWidth = moreMenuRef.current?.getBoundingClientRect().width ?? 0
navWidth !== 0 && overflowEffect(navWidth, moreMenuWidth, validChildren, childWidthArray, updateListAndMenu)
const hasActiveMenu = menuItems.length > 0
navWidth !== 0 &&
overflowEffect(navWidth, moreMenuWidth, validChildren, childWidthArray, updateListAndMenu, hasActiveMenu)
}, navRef as RefObject<HTMLElement>)

const [isWidgetOpen, setIsWidgetOpen] = useState(false)
Expand Down

0 comments on commit 415b888

Please sign in to comment.