Skip to main content

ToggleControl

The ToggleControl component lets users select one option from a short list of choices. It can optionally show icons, allow clearing the selection, or stack vertically when space is restricted.

Import

// with @dhl-official/react-library:
import { DhlToggleControl } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlToggleControl } from "@dhl-official/ui-libraries/react-library"

Code

<DhlToggleControl
options={[
{ label: "Option A", value: "a" },
{ label: "Option B", value: "b" },
{ label: "Option C", value: "c" },
]}
defaultValue="a"
></DhlToggleControl>

Interactive Demo

Readme

Properties

PropertyAttributeDescriptionTypeDefault
allowEmptyallow-emptyAn optional flag that allows users to clear the current selection by reselecting the active option.booleanfalse
dataAriaLabeldata-aria-labelAn optional prop defining the text read by the screen reader to represent the component; use this if you need different text to be read from label.stringundefined
dataClassNamedata-class-nameAn optional class name prop for the component.stringundefined
dataIdidAn optional prop. Gives a valid HTML ID attribute value for the component.stringdhl-toggle-control-${getRandomString()}
dataTestiddata-testidAn optional prop. The test id attached to the component as a data-testid attribute.stringundefined
dataTrackingdata-trackingAn optional data tracking prop for the component.stringundefined
defaultValuedefault-valueAn optional prop defining the initial value when the component is uncontrolled.stringundefined
isDisabledis-disabledAn optional flag to define if the component is disabled.booleanfalse
isFullWidthis-full-widthAn optional prop that sets the component to 100% width of it's parent container.booleanfalse
options--A REQUIRED array describing the toggle options rendered by the component.DhlToggleControlOption[][]
orientationorientationAn optional orientation for the toggle options.Orientation.horizontal \| Orientation.verticalDHL_TOGGLE_CONTROL.ORIENTATION.HORIZONTAL
sizesizeAn optional size prop for the toggle options.Sizes.MD \| Sizes.SM \| Sizes.XSDHL_TOGGLE_CONTROL.SIZE.MD
valuevalueAn optional prop defining the selected value. If unset, the component can operate in an uncontrolled manner using defaultValue.stringundefined

Events

EventDescriptionType
dhlBlurEvent emitted when one of the toggle options loses focus.CustomEvent<{ value: string; }>
dhlChangeEvent emitted when the selected option changes.CustomEvent<{ value: string; }>
dhlFocusEvent emitted when one of the toggle options receives focus.CustomEvent<{ value: string; }>

Dependencies

Depends on

Graph


Built by DHL User Interface Library Team!