Skip to content

Latest commit

 

History

History
71 lines (46 loc) · 1.58 KB

File metadata and controls

71 lines (46 loc) · 1.58 KB

MenuItem

MenuItem is a component which renders a button intended to be used in combination with the DropdownMenu component.

Usage

import { MenuItem } from '@wordpress/components';
import { withState } from '@wordpress/compose';

const MyMenuItem = withState( {
	isActive: true,
} )( ( { isActive, setState } ) => (
	<MenuItem
		icon={ isActive ? 'yes' : 'no' }
		isSelected={ isActive }
		onClick={ () => setState( state => ( { isActive: ! state.isActive } ) ) }
	>
		Toggle
	</MenuItem>
) );

Props

MenuItem supports the following props. Any additional props are passed through to the underlying Button.

children

  • Type: WPElement
  • Required: No

Element to render as child of button.

info

  • Type: string
  • Required: No

Text to use as description for button text.

Refer to documentation for label.

icon

  • Type: string
  • Required: No

Refer to documentation for Button's icon prop.

isSelected

  • Type: boolean
  • Required: No

Whether or not the menu item is currently selected.

shortcut

  • Type: string
  • Required: No

Refer to documentation for Shortcut's shortcut prop.

role

  • Type: string
  • Require: No
  • Default: 'menuitem'

Aria Spec. If you need to have selectable menu items use menuitemradio for single select, and menuitemcheckbox for multiselect.