MenuItem


目录

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

Usage

import { useState } from 'react';
import { MenuItem } from '@wordpress/components';

const MyMenuItem = () => {
    const [ isActive, setIsActive ] = useState( true );

    return (
        <MenuItem
            icon={ isActive ? 'yes' : 'no' }
            isSelected={ isActive }
            onClick={ () => setIsActive( ( state ) => ! state ) }
        >
            Toggle
        </MenuItem>
    );
};

Props

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

children

Element to render as child of button.

disabled

Refer to documentation for Button’s disabled prop.

info

Text to use as description for button text.

icon

Refer to documentation for Button’s icon prop.

iconPosition

Determines where to display the provided icon.

isSelected

Whether or not the menu item is currently selected. isSelected is only taken into account when the role prop is either "menuitemcheckbox" or "menuitemradio".

shortcut

If shortcut is a string, it is expecting the display text. If shortcut is an object, it will accept the properties of display (string) and ariaLabel (string).

role

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

suffix

Allows for markup other than icons or shortcuts to be added to the menu item.


版本号 #2
由 壳壳虫 创建于 2026-10-31 18:13:50 UTC
由 壳壳虫 更新于 2026-10-31 18:13:52 UTC