MenuItemsChoice functions similarly to a set of MenuItems, but allows the user to select one option from a set of multiple choices.
import { MenuItemsChoice } from '@wordpress/components';
LinksPermalink to this section
PropsPermalink to this section
| Name | Default | Description |
|---|---|---|
choices Required | [] |
Array of choices. |
value Required |
Value of currently selected choice (should match a | |
onSelect Required |
Callback function to be called with the selected choice when user selects a new choice. | |
onHover Required | () => {} |
Callback function to be called with a choice when user hovers over a new choice (will be empty on mouse leave). |
ExamplesPermalink to this section
DefaultPermalink to this section
const Default = ( {
onHover,
onSelect,
choices,
} ) => {
const [ choice, setChoice ] = useState( choices[ 0 ]?.value ?? '' );
return (
<NavigableMenu>
<MenuGroup label="Editor">
<MenuItemsChoice
choices={ choices }
value={ choice }
onSelect={ ( ...selectArgs ) => {
onSelect( ...selectArgs );
setChoice( ...selectArgs );
} }
onHover={ onHover }
/>
</MenuGroup>
</NavigableMenu>
);
};