MenuGroup

MenuGroup wraps a series of related MenuItem components into a common section.

View on Storybook

View source on GitHub

Import

import { MenuGroup } from '@wordpress/components';

Props

NameTypeDefaultRequiredDescription
classNamestring

A CSS class to give to the container element.

hideSeparatorboolean

Hide the top border on the container.

labelstring

Text to be displayed as the menu group header.

childrenReactNode

The children elements.

Examples

Default

const Default = () => {
    return (
        <MenuGroup>
            <MenuItem>Menu Item 1</MenuItem>
            <MenuItem>Menu Item 2</MenuItem>
        </MenuGroup>
    );
};

With Separator

When other menu items exist above or below a MenuGroup, the group should have a divider line between it and the adjacent item.

const WithSeparator = () => {
    const [ mode, setMode ] = useState( 'visual' );
    const choices = [
		{
			value: 'visual',
			label: 'Visual editor',
		},
		{
			value: 'text',
			label: 'Code editor',
		},
	];

    return (
        <>
            <MenuGroup label="View">
                <MenuItem>Top Toolbar</MenuItem>
                <MenuItem>Spotlight Mode</MenuItem>
                <MenuItem>Distraction Free</MenuItem>
            </MenuGroup>
            <MenuGroup hideSeparator={false} label="Editor">
                <MenuItemsChoice
                    choices={ choices }
                    value={ mode }
                    onSelect={ ( newMode: string ) => setMode( newMode ) }
                    onHover={ () => {} } />
            </MenuGroup>
        </>
    );
};