Skip to main content

ButtonGroup

import { ButtonGroup } from '@enmovil/ui-design-system';

A row of buttons where one option is selected at a time, built from an options list. onChange fires when the user picks an option, and the group can be spaced out or rounded.

Properties​

PropertyTypeRequiredDefaultAllowed valuesDescription
optionsOption[]Yes——Array of { label, value, icon?, onChange? }. An option's own onChange fires when that option is clicked, after the group's onChange.
selectedstringYes——The selected value
labelstringNo——Text shown above the buttons, such as a field label. Nothing is shown without it.
spacedbooleanNofalse—Shows the options as separate buttons with a gap between them instead of joined together. Defaults to false.
gapstring | numberNo8—Space between the buttons: a number in pixels or any CSS length. Defaults to 8. Requires spaced.
roundedbooleanNofalse—Gives each button fully rounded (pill) corners. Requires spaced; joined buttons are not affected.

options​

An array of objects (Option). Each object has these fields:

FieldTypeRequiredDescription
labelstringYesText of the button. Not shown when the option has an icon.
valuestringYesPassed to onChange when the option is clicked and compared with selected; also the button's key, so values must be unique.
iconReact.ReactNodeNoShown in the button instead of the label.
onChange(value: string) => voidNoFires when this option is clicked, after the group's onChange.

Events​

NameSignatureWhen it fires
onChange(value: string) => voidTriggered when the selection changes
onOptionMouseEnter((value: string, event: MouseEvent<HTMLButtonElement, MouseEvent>) => void)Fires when the pointer enters an option, with that option's value.
onOptionMouseLeave((value: string, event: MouseEvent<HTMLButtonElement, MouseEvent>) => void)Fires when the pointer leaves an option, with that option's value.
onFocusFocusEventHandler<HTMLDivElement>Fires when any option receives focus.
onBlurFocusEventHandler<HTMLDivElement>Fires when an option loses focus, including when focus moves to another option.

Children​

ButtonGroup does not accept children.

Variants​

Loading examples…

Playground​

Change the controls to see how the properties affect the component. Values the controls don't cover come from the Basic Toggle example.

Loading playground…

Storybook​

Open ButtonGroup in Storybook to try every story with the full set of controls.