--- title: SegmentedControl description: "`SegmentedControl` is a component used for allowing users to select one option from multiple choices." links: - style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/segmented-control/segmented-control.style.ts - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/segmented-control - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-segmentedcontrol--basic --- ```tsx ハチワレ うさぎ モモンガ ``` ## Usage ```tsx import { SegmentedControl } from "@yamada-ui/react" ``` ```tsx import { SegmentedControl } from "@/components/ui" ``` ```tsx import { SegmentedControl } from "@workspaces/ui" ``` ```tsx ``` ### Use items ```tsx const items = useMemo( () => [ { label: "ハチワレ", value: "ハチワレ" }, { label: "うさぎ", value: "うさぎ" }, { label: "モモンガ", value: "モモンガ" }, ], [], ) return ``` ### Change size ```tsx const items = useMemo( () => [ { label: "ハチワレ", value: "ハチワレ" }, { label: "うさぎ", value: "うさぎ" }, { label: "モモンガ", value: "モモンガ" }, ], [], ) return ( {(size) => ( )} ) ``` ### Change orientation ```tsx const items = useMemo( () => [ { label: "ハチワレ", value: "ハチワレ" }, { label: "うさぎ", value: "うさぎ" }, { label: "モモンガ", value: "モモンガ" }, ], [], ) return ( {(orientation) => ( )} ) ``` ### Make rounded ```tsx const items = useMemo( () => [ { label: "ハチワレ", value: "ハチワレ" }, { label: "うさぎ", value: "うさぎ" }, { label: "モモンガ", value: "モモンガ" }, ], [], ) return ( ) ``` ### Disable ```tsx const items = useMemo( () => [ { label: "ハチワレ", value: "ハチワレ" }, { label: "うさぎ", value: "うさぎ" }, { label: "モモンガ", value: "モモンガ" }, ], [], ) return ( ハチワレ うさぎ モモンガ ) ``` ### Read-Only ```tsx const items = useMemo( () => [ { label: "ハチワレ", value: "ハチワレ" }, { label: "うさぎ", value: "うさぎ" }, { label: "モモンガ", value: "モモンガ" }, ], [], ) return ( ハチワレ うさぎ モモンガ ) ``` ### Control ```tsx const [value, setValue] = useState("ハチワレ") const items = useMemo( () => [ { label: "ハチワレ", value: "ハチワレ" }, { label: "うさぎ", value: "うさぎ" }, { label: "モモンガ", value: "モモンガ" }, ], [], ) return ``` ## Props ### SegmentedControl.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"` | `"lg" \| "md" \| "sm" \| "xl"` | The size of the component. | | `defaultValue` | - | `Y` | The initial value of the segmented control. | | `disabled` | `false` | `boolean` | If `true`, the segmented control will be disabled. | | `fullRounded` | `false` | `boolean` | If `true`, the segmented control will be full rounded. | | `items` | `[]` | `SegmentedControlItem[]` | If provided, generate segmented control buttons but based on items. | | `name` | - | `string` | The HTML `name` attribute used for forms. | | `onChange` | - | `(value: Y) => void` | The callback fired when any children radio is checked or unchecked. | | `orientation` | `"horizontal"` | `"horizontal" \| "vertical"` | The orientation of the segmented control. | | `readOnly` | `false` | `boolean` | If `true`, the segmented control will be readonly. | | `value` | - | `Y` | The value of the segmented control. | ### SegmentedControl.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. | | `value` | - | `Y` | The value of the segmented control item. | | `disabled` | `false` | `boolean` | If `true`, the field will be disabled. | | `inputProps` | - | `HTMLProps<"input">` | Props for the input element. | | `readOnly` | `false` | `boolean` | If `true`, the field will be readonly. | ## Accessibility Currently, this section is being updated due to the migration of v2.