Components
Multi Select Menu
A Multi Select Menu lets users choose multiple options from a list.
A Multi Select Menu allows users to choose multiple options from a list. It is designed for scenarios where more than one selection is valid, managing checked state internally or through external props. The component supports a simple data-driven setup or full customization using menu primitives, providing teams with complete flexibility.
import { MultiSelectMenu } from '@sproutsocial/seeds-react-menu'
() => {return (<Box display="flex" justifyContent="center" alignItems="center" height="100%"><MultiSelectMenumenuToggleElement={<MenuToggleButton>Select books</MenuToggleButton>}><MenuContent><MenuGroup id="books">{TEST_BOOKS.map((itemsToRender) => (<MenuIteminputType="checkbox"key={itemsToRender.id}id={itemsToRender.id}>{itemsToRender.title}</MenuItem>))}</MenuGroup></MenuContent></MultiSelectMenu></Box>)}
Properties
Name | Type | Default | Description | Required? |
---|---|---|---|---|
menuToggleElement | React.ReactElement<any> | The element that is or contains an element that will toggle the menu when clicked.
May contain labels, buttons, inputs or other content as needed. | ||
popoutProps | Partial<
Omit<TypePopoutProps, "isOpen" | "setIsOpen" | "content" | "children">
> | Props to pass through to the underlying Popout.
Any Popout prop is valid except those explicitly omitted. | ||
width | TypePopoutProps["width"] | The width of the Popout content.
Defaults to 200px or the width of the toggle element, whichever is greater. | ||
MenuRootComponent | React.ComponentType<TypeMenuRootProps> | ({
children,
menuToggleElement,
popoutProps: { placement = "bottom", focusLockProps, ...popoutProps } = {},
width,
...contextProps
}: TypeMenuRootProps) => {
const {
isOpen,
openMenu,
closeMenu,
inputValue,
hiddenItemsCount = 0,
items,
getMenuProps,
} = contextProps;
const toggleElementRef = React.useRef<HTMLElement>(null);
const [finalWidth, setFinalWidth] = React.useState<typeof width>();
const min_width = 200;
useLayoutEffect(() => {
if (width) {
setFinalWidth(width);
} else if (toggleElementRef.current?.offsetWidth) {
const toggleWidth = toggleElementRef.current.offsetWidth;
setFinalWidth(Math.max(toggleWidth, min_width));
} else {
setFinalWidth(min_width);
}
}, [width, toggleElementRef.current?.offsetWidth]);
const menuContext = useMenu(contextProps);
// Hack to suppress error: "downshift: You forgot to call the getMenuProps getter function on your component / element."
getMenuProps?.({}, { suppressRefError: true });
return (
<MenuPopout
placement={placement}
isOpen={!!isOpen}
openMenu={openMenu}
closeMenu={closeMenu}
content={
<MenuContentProvider menuContext={menuContext}>
{children}
</MenuContentProvider>
}
width={finalWidth}
{...popoutProps}
>
{(toggleProps) => (
<MenuToggleProvider
menuContext={{
...menuContext,
...toggleProps,
ref: mergeRefs<HTMLElement>(
toggleProps.ref,
toggleElementRef
) as RefObject<HTMLElement>,
}}
>
{menuToggleElement}
</MenuToggleProvider>
)}
</MenuPopout>
);
} | Overrides the default MenuRoot component. Only necessary for specialized use cases. | |
getA11yMultiStatusMessage | UseMultipleSelectionProps<TypeInternalItemProps>["getA11yStatusMessage"] | Optional override to the built-in getA11yStatusMessage function for multiple selection | ||
onMultiSelectStateChange | UseMultipleSelectionProps<TypeInternalItemProps>["onStateChange"] | Optional override to the built-in onStateChange function for multiple selection | ||
multiSelectStateReducer | UseMultipleSelectionProps<TypeInternalItemProps>["stateReducer"] | Optional override to the built-in stateReducer function for multiple selection | ||
children | | React.ReactChild | React.ReactFragment | React.ReactPortal | Allows menu items to be passed in as children. Cannot be used with the menuItems prop. | ||
menuItems | I[] | Allows menu items to be passed in as objects. Cannot be used with the children prop.
The type of each menu item, I, must be or extend TypeMenuItemProps. | ||
MenuItemComponent | React.ComponentType<I> | Allows a custom MenuItem component to be used when rendering using the menuItems prop.
MenuItemComponent's prop type must match the type of the menuItems, I. |
Recipes
Using the menuItems prop
The Multi Select Menu can accept an array of menu item data as a prop ([{ id, onClick, children }]
) to render a simple, selectable list.
import { MultiSelectMenu } from '@sproutsocial/seeds-react-menu'
() => {const items = TEST_BOOKS.map((book) => ({id: book.id,children: book.title,inputType: "checkbox"}));return (<Box display="flex" justifyContent="center" alignItems="center" height="100%"><MultiSelectMenumenuToggleElement={<MenuToggleButton>Select books</MenuToggleButton>}menuItems={items}/></Box>);}
Composable Multi Select Menu
For more customization and control, the Multi Select Menu can also be composed using menu primitives. This approach allows you to define custom layouts, add icons, or integrate with other components while keeping the menu behavior consistent.
import { MultiSelectMenu } from '@sproutsocial/seeds-react-menu'
() => {return (<Box display="flex" justifyContent="center" alignItems="center" height="100%"><MultiSelectMenumenuToggleElement={<MenuToggleButton>Select books</MenuToggleButton>}><MenuContent><MenuGroup title="Classics" id="classics">{TEST_BOOKS.slice(0, 5).map((itemsToRender) => (<MenuIteminputType="checkbox"key={itemsToRender.id}id={itemsToRender.id}>{itemsToRender.title}</MenuItem>))}</MenuGroup><MenuGroup title="Essentials" id="essentials" isSingleSelect>{EXTRA_BOOKS.slice(0, 5).map((itemsToRender) => (<MenuIteminputType="radio"key={itemsToRender.id}id={itemsToRender.id}>{itemsToRender.title}</MenuItem>))}</MenuGroup></MenuContent></MultiSelectMenu></Box>)}