Skip to content

Commit

Permalink
Merge pull request #1378 from DiamondLightSource/initial-overflows
Browse files Browse the repository at this point in the history
Add prop to manually add components to overflow menu
  • Loading branch information
axelboc authored Mar 14, 2023
2 parents 86df8d5 + 68d5eb4 commit c798ed2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/lib/src/toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import InteractionHelp from './controls/InteractionHelp';
interface Props {
children: ReactNode;
interactions?: InteractionInfo[];
overflowChildren?: ReactNode;
}

function Toolbar(props: Props) {
const { children, interactions } = props;
const { children, interactions, overflowChildren = [] } = props;

/* Convert `children` to flat array by traversing nested arrays and fragments.
* (Note that `flattenChildren` guarantees stable string keys regardless of JSX logic.) */
Expand Down Expand Up @@ -45,6 +46,8 @@ function Toolbar(props: Props) {
);

const isSeparatorLast = inView[inView.length - 1]?.type === Separator;
const initialOverflows =
flattenChildren(overflowChildren).filter(isReactElement);

return (
<div className={styles.toolbar}>
Expand All @@ -63,7 +66,10 @@ function Toolbar(props: Props) {
</div>

<OverflowMenu>
{outOfView.filter((child) => child.type !== Separator)}
{[
...initialOverflows,
...outOfView.filter((child) => child.type !== Separator),
]}
</OverflowMenu>

{interactions && <Separator />}
Expand Down

0 comments on commit c798ed2

Please sign in to comment.