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';
Links
Props
| Name | Default | Description |
|---|---|---|
choices | [] |
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 | () => {} |
Callback function to be called with a choice when user hovers over a new choice (will be empty on mouse leave). |
Examples
Default
const Default = ( {
onHover,
onSelect,
choices,
} ) => {
const [ choice, setChoice ] = useState( choices[ 0 ]?.value ?? '' );
return (
<MenuGroup label="Editor">
<MenuItemsChoice
choices={ choices }
value={ choice }
onSelect={ ( ...selectArgs ) => {
onSelect( ...selectArgs );
setChoice( ...selectArgs );
} }
onHover={ onHover }
/>
</MenuGroup>
);
};




