Menu toggle

A menu toggle is a selectable control that opens and closes a menu.

Examples

Collapsed toggle

A toggle is collapsed until it is selected by a user.

Expanded toggle

When a user selects a toggle, it becomes expanded and is styled with a blue underline. To flag expanded toggles, and apply expanded styling, use the isExpanded property .

Small toggle

You can pass size="sm" to a MenuToggle to style it as a small toggle, such as within a breadcrumb.

Disabled toggle

To disable the selection and expansion of a toggle, use the isDisabled property.

With a badge

To display a count of selected items in a toggle, use the badge property. You can also pass in variant="plainText" for a badge only toggle.

With icons

To add a recognizable icon to a menu toggle, use the icon property. The following example adds a CogIcon to the toggle.

For most basic icons, it is recommended to wrap it inside our icon component.

With avatar and text

You can also pass images into the icon property. The following example passes in an <Avatar> component with an imgAvatar.

This can be used alongside a text label that provides more context for the image.

Variant styles

Variant styling can be applied to menu toggles. In the following example, the toggle uses primary styling by passing variant="primary" into the <MenuToggle> component. Additional variant options include “default”, “plain”, “plainText”, “secondary”, and “typeahead”.

Plain toggle with icon

To apply plain styling to a menu toggle with an icon, pass in variant="plain". This will remove the default bottom border and caret. You may pass in an icon to serve as the menu toggle. The following example passes in an EllipsisVIcon.

If the toggle does not have any visible text content, use the aria-label property to provide an accessible name.

Plain toggle with text label

To apply plain styling to a menu toggle with a text label, pass in variant="plainText". Unlike the “plain” variant, “plainText” adds a caret pointing down in the toggle.

Split toggle with checkbox

To add a checkbox (or other action/control) to a menu toggle, use a split button.

A <MenuToggle> can be rendered as a split button by adding a splitButtonOptions object. Elements to be displayed before the toggle button must be included in the items property of splitButtonOptions.

The following example shows a split button with a <MenuToggleCheckbox>.

Variant styling can be applied to split button toggles to adjust their appearance for different scenarios. Both "primary" and "secondary" variants can be used with split button toggles.

Split toggle with labeled checkbox

To add a text label to a split button toggle, pass children to the <MenuToggle> component.

Split toggle with checkbox and toggle text label

You can allow users to select a toggle checkbox by clicking either the checkbox or the text label.

To do so, pass children to the <MenuToggleCheckbox> component. When the menu toggle text is clicked, the checkbox's onChange callback will be triggered.

Split toggle with action

To add an action to a split button, pass variant='action' into splitButtonOptions and add a <MenuToggleAction> to the items property of splitButtonOptions.

Actions may be used with primary and secondary toggle variants.

Full height toggle

A full height toggle fills the height of its parent. To flag a full height toggle, use the isFullHeight property.

In the following example, the toggle fills the size of the "80px" <div> element that it is within.

Full width toggle

A full width toggle fills the width of its parent. To flag a full width toggle, use the isFullWidth property.

In the following example, the toggle fills the width of its parent as the window size changes.

Typeahead toggle

To create a typeahead toggle, pass in variant="typeahead" to the <MenuToggle>. Then, pass a <TextInputGroup> component as a child of the <MenuToggle>.

To create a multiple typeahead toggle, pass a <TextInputGroup> component implemented like the text input group's filter example as a child of <MenuToggle>.

Status toggle

To create a toggle with a status, pass in the status property to the MenuToggle. The default icon associated with each status may be overridden by using the statusIcon property.

When the status value is "warning" or "danger", you must include helper text that conveys what is causing the warning/error.



Warning text that explains the issue.: warning status;


Danger text that explains the issue.: error status;

Props

*required
NameTypeDefaultDescription
badgeBadgeProps | React.ReactNodeOptional badge rendered inside the toggle, after the children content
childrenReact.ReactNodeContent rendered inside the toggle
classNamestringAdditional classes added to the toggle
iconReact.ReactNodeOptional icon or image rendered inside the toggle, before the children content. It is recommended to wrap most basic icons in our icon component.
isDisabledbooleanFlag indicating the toggle is disabled
isExpandedbooleanFlag indicating the toggle has expanded styling
isFullHeightbooleanFlag indicating the toggle is full height
isFullWidthbooleanFlag indicating the toggle takes up the full width of its parent
ouiaIdnumber | stringValue to overwrite the randomly generated data-ouia-component-id. It will always target the toggle button.
ouiaSafebooleanSet the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false.
size'default' | 'sm'Adds styling which affects the size of the menu toggle
splitButtonOptionsSplitButtonOptionsObject used to configure a split button menu toggle
status'success' | 'warning' | 'danger'Status styles of the menu toggle
statusIconReact.ReactNodeOverrides the status icon
variant'default' | 'plain' | 'primary' | 'plainText' | 'secondary' | 'typeahead'Variant styles of the menu toggle
*required
NameTypeDefaultDescription
childrenReact.ReactNodeElement to be rendered inside the <button>
classNamestring''Additional classes added to the MenuToggleAction
idstringId of the action button
isDisabledbooleanfalseFlag to show if the action button is disabled
onClick(event: React.MouseEvent<HTMLButtonElement>) => void() => {}A callback for when the action button is clicked
*required
NameTypeDefaultDescription
idrequiredstringId of the checkbox
childrenReact.ReactNodeElement to be rendered inside the <span>
classNamestringAdditional classes added to the MenuToggleCheckbox
defaultCheckedboolean | nullFlag to set the default checked value of the checkbox when it is uncontrolled by React state. To make the checkbox controlled instead use the isChecked prop, but do not use both.
isCheckedboolean | nullFlag to show if the checkbox is checked when it is controlled by React state. To make the checkbox uncontrolled instead use the defaultChecked prop, but do not use both.
isDisabledbooleanfalseFlag to show if the checkbox is disabled
isValidbooleantrueFlag to show if the checkbox selection is valid or invalid
onChange(checked: boolean, event: React.FormEvent<HTMLInputElement>) => void() => undefined as anyA callback for when the checkbox selection changes
ouiaIdnumber | stringValue to overwrite the randomly generated data-ouia-component-id.
ouiaSafebooleanSet the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false.

SplitButtonOptions

*required
NameTypeDefaultDescription
itemsrequiredReact.ReactNode[]Elements to display before the toggle button. When included, renders the menu toggle as a split button.
variant'action' | 'checkbox'Variant of split button toggle

CSS variables

Expand or collapse columnSelectorVariableValue