Skip to content

SplitButton

import { SplitButton } from '@yarcl/react';

The main button executes the selected action. The arrow opens a menu of choices. Choosing an option updates the button’s label and icon without executing anything.

Nothing executed yet
<SplitButton
aria-label="Save actions"
defaultValue="draft"
options={[
{ value: 'draft', label: 'Save draft' },
{ value: 'publish', label: 'Publish' },
{ value: 'schedule', label: 'Schedule', disabled: true },
]}
onAction={(value) => handleSave(value)}
/>

Use value and onValueChange to control the selection. Without defaultValue, the first enabled option is selected initially. Values must be unique. Empty lists and lists with no enabled options disable both buttons. If the selected option is removed or disabled, the main button is disabled until an enabled action is chosen.

size, color, radius and variant come from your config. Both button segments follow components.SplitButton, including allowedSizes and sizeOverrides; menu items follow components.Menu. Native attributes, className, style and ref go to the outer group. Both buttons use type="button"; use onAction to perform an action or submit a form explicitly.

  • Give the group an aria-label describing its actions. dropdownLabel names the arrow button and the menu choices.
  • Both segments are keyboard focusable. Enter or Space executes the main action or opens the menu; Arrow Down and Arrow Up also open the menu from its trigger.
  • Arrow keys navigate choices, typing finds a label, and Enter or Space selects without executing. Escape closes the menu. Closing returns focus to the arrow button.
  • The selected choice exposes role="menuitemradio" and aria-checked. Disabled options cannot be selected. Icons are decorative.
  • disabled and loading disable both buttons and close the menu. Loading shows a spinner and marks the main action busy.
PropTypeDefaultDescription
options requiredreadonly SplitButtonOption<V>[]Actions to choose from. Values must be unique.
colorColorconfigconfig.defaults.colorSemantic color, from the colors config.
defaultValueNoInfer<V>The first enabled option's value.Initial selected action when uncontrolled.
disabledbooleanDisables both buttons and closes the menu.
dropdownLabelstringconfig.labels.chooseActionAccessible name for the dropdown button and its choices.
loadingbooleanShows a spinner on the main button, disables both buttons and closes the menu.
onAction(value: V) => voidCalled when the main button executes the selected action.
onValueChange(value: V) => voidCalled when an action is selected. Selection does not execute the action.
placeholderstringconfig.labels.chooseActionMain button label when the selected value has no matching option.
radius'size' | Radiusconfigconfig.defaults.radiusBorder radius, from the radii config, or 'size' for the radius named like the control's size.
size'lg' | 'xs' | 'sm' | 'md' | 'xl'config.defaults.sizeControl size, from the sizes config.
valueNoInfer<V>Controlled selected action.
variantVariantconfigconfig.defaults.variantStyle recipe, from the component's variant map or the shared variants config.
PropTypeDefaultDescription
label requiredstringVisible action label, also used for type-to-select.
value requiredVValue reported when this action is selected or executed.
disabledbooleanPrevents selecting or executing this action.
iconReactNodeDecorative icon shown before the label.