--- title: Toggle description: "`Toggle` is a component that has two states: on or off." links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/toggle/toggle.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/toggle - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-toggle--basic --- ```tsx } aria-label="Toggle bold" /> ``` ## Usage ```ts import { Toggle, ToggleGroup } from "@yamada-ui/react" ``` ```ts import { Toggle, ToggleGroup } from "@/components/ui" ``` ```ts import { Toggle, ToggleGroup } from "@workspaces/ui" ``` ```tsx ``` ```tsx ``` ### With Text ```tsx Italic ``` ### Change Variant ```tsx {(variant) => ( } aria-label="Toggle bold" variant={variant} /> )} ``` ### Change Size ```tsx {(size) => ( } aria-label="Toggle bold" size={size} /> )} ``` ### Change Color Scheme ```tsx {(colorScheme) => ( } /> )} ``` ### Change Shape To change the shape, set the `rounded` prop. ```tsx {(variant) => ( } aria-label="Toggle bold" variant={variant} fullRounded /> )} ``` ### Disable To disable, set `disabled` to `true`. ```tsx {(variant) => ( } aria-label="Toggle bold" variant={variant} disabled /> )} ``` ### Read-Only To read-only, set `readOnly` to `true`. ```tsx {(variant) => ( } aria-label="Toggle bold" variant={variant} readOnly /> )} ``` ### Invalid To set invalid state, set `invalid` to `true`. ```tsx {(variant) => ( } aria-label="Toggle bold" variant={variant} invalid /> )} ``` ### Change Invalid Border Color To change the border color, set `errorBorderColor` to the color. ```tsx } defaultChecked invalid /> ``` ### Control ```tsx const [checked, setChecked] = useState(false) return ( } aria-label="Toggle bold" checked={checked} onChange={setChecked} /> ) ``` ### Grouping ```tsx } aria-label="Toggle bold" /> } aria-label="Toggle italic" /> } aria-label="Toggle underline" /> ``` For multiple selections, set `value` or `defaultValue` to an array. ```tsx const [value, setValue] = useState([]) return ( } aria-label="Toggle bold" /> } aria-label="Toggle italic" /> } aria-label="Toggle underline" /> ) ``` ## Props ### Toggle | Prop | Default | Type | Description | | ------------------ | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"ghost"` | `"ghost" \| "outline" \| "solid" \| "subtle" \| "surface" ...` | The variant of the component. | | `active` | `false` | `boolean` | If `true`, the button is represented as active. | | `checked` | - | `boolean` | If `true`, the toggle button will be checked. | | `disabled` | `false` | `boolean` | If `true`, the button is disabled. | | `disableRipple` | `false` | `boolean` | If `true`, disable ripple effects when pressing a element. | | `errorBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is invalid. | | `fullRounded` | `false` | `boolean` | If true, the toggle button is full rounded. Else, it'll be slightly round. | | `icon` | - | `string \| number \| bigint \| boolean \| ReactElement> \| Iterable \| ReactPortal \| Promise<...>` | The icon to be used in the button. | | `invalid` | `false` | `boolean` | If `true`, the field will be invalid. | | `loading` | `false` | `boolean` | If `true`, the loading state of the button is represented. | | `onChange` | - | `(checked: boolean) => void` | The callback invoked when checked state changes. | | `readOnly` | `false` | `boolean` | If `true`, the field will be readonly. | | `required` | `false` | `boolean` | If `true`, the field will be required. | | `type` | `"button"` | `"button" \| "reset" \| "submit"` | The type of button. Accepts `button`, `reset`, or `submit`. | | `value` | - | `Y` | The value of the toggle button. | ### ToggleGroup.Root | Prop | Default | Type | Description | | -------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"ghost"` | `"ghost" \| "outline" \| "solid" \| "subtle" \| "surface" ...` | The variant of the component. | | `align` | - | `"-moz-initial" \| "baseline" \| "center" \| "end" \| "flex-end" \| "flex-start" \| "inherit" \| "initial" \| "normal" \| "revert-layer" ...` | The CSS `align-items` property. | | `attached` | `false` | `boolean` | If `true`, the borderRadius of button that are direct children will be altered to look flushed together. | | `basis` | - | `"-moz-fit-content" \| "-moz-initial" \| "-moz-max-content" \| "-moz-min-content" \| "-webkit-auto" \| "0.5" \| "1.5" \| "1" \| "1/12" \| "1/2" ...` | The CSS `flex-basis` property. | | `defaultValue` | - | `Y extends any[] ? Y : undefined \| Y` | The initial value of the toggle button group. | | `direction` | - | `"-moz-initial" \| "column-reverse" \| "column" \| "inherit" \| "initial" \| "revert-layer" \| "revert" \| "row-reverse" \| "row" \| "unset" ...` | The CSS `flex-direction` property. | | `disabled` | `false` | `boolean` | If `true`, all wrapped toggle button will be disabled. | | `fullRounded` | `false` | `boolean` | If true, the toggle button is full rounded. Else, it'll be slightly round. | | `grow` | `false` | `boolean` | If `true`, the children will grow to fill the available space. | | `justify` | - | `"-moz-initial" \| "center" \| "end" \| "flex-end" \| "flex-start" \| "inherit" \| "initial" \| "left" \| "normal" \| "revert-layer" ...` | The CSS `justify-content` property. | | `onChange` | - | `(value: Y extends any[] ? Y : undefined \| Y) => void` | The callback fired when any children toggle button is selected or unselected. | | `orientation` | `"horizontal"` | `"horizontal" \| "vertical"` | The orientation of the group. | | `readOnly` | `false` | `boolean` | If `true`, all wrapped toggle button will be readonly. | | `shrink` | - | `"-moz-initial" \| "inherit" \| "initial" \| "revert-layer" \| "revert" \| "unset" \| number & {} ...` | The CSS `flex-shrink` property. | | `stacking` | - | `"first-on-top" \| "last-on-top"` | The stacking order of the group. | | `value` | - | `Y extends any[] ? Y : undefined \| Y` | The value of the toggle button group. | | `wrap` | - | `"-moz-initial" \| "inherit" \| "initial" \| "nowrap" \| "revert-layer" \| "revert" \| "unset" \| "wrap-reverse" \| "wrap" ...` | The CSS `flex-wrap` property. | ### ToggleGroup.Item | Prop | Default | Type | Description | | ------------------ | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | `as` | - | `As` | The HTML element to render. | | `asChild` | - | `boolean` | Merges its props onto its immediate child. | | `css` | - | `CSSObject \| CSSObject[]` | The CSS object. | | `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. | | `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. | | `variant` | `"ghost"` | `"ghost" \| "outline" \| "solid" \| "subtle" \| "surface" ...` | The variant of the component. | | `active` | `false` | `boolean` | If `true`, the button is represented as active. | | `checked` | - | `boolean` | If `true`, the toggle button will be checked. | | `disabled` | `false` | `boolean` | If `true`, the button is disabled. | | `disableRipple` | `false` | `boolean` | If `true`, disable ripple effects when pressing a element. | | `errorBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is invalid. | | `fullRounded` | `false` | `boolean` | If true, the toggle button is full rounded. Else, it'll be slightly round. | | `icon` | - | `string \| number \| bigint \| boolean \| ReactElement> \| Iterable \| ReactPortal \| Promise<...>` | The icon to be used in the button. | | `invalid` | `false` | `boolean` | If `true`, the field will be invalid. | | `loading` | `false` | `boolean` | If `true`, the loading state of the button is represented. | | `onChange` | - | `(checked: boolean) => void` | The callback invoked when checked state changes. | | `readOnly` | `false` | `boolean` | If `true`, the field will be readonly. | | `required` | `false` | `boolean` | If `true`, the field will be required. | | `type` | `"button"` | `"button" \| "reset" \| "submit"` | The type of button. Accepts `button`, `reset`, or `submit`. | | `value` | - | `Y` | The value of the toggle button. | ## Accessibility Currently, this section is being updated due to the migration of v2.