# Segmented control (UI SDK): Controlled

> Pass `value` and update it in `onValueChange`. A controller from `createSegmentedControlController()` checks an item from anywhere.

Canonical: https://hextaui.com/docs/ui-sdk-segmented-control/examples/controlled

Component docs: https://hextaui.com/docs/ui-sdk-segmented-control

## Add this example

```bash
npx shadcn@latest add https://hextaui.com/r/ui-sdk-segmented-control-controlled.json
```

This adds `components/examples/ui-sdk-segmented-control/controlled.tsx` with the Segmented control component and the HextaUI theme tokens.

## Source

```tsx title="components/examples/ui-sdk-segmented-control/controlled.tsx"
"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import {
  SegmentedControl,
  SegmentedControlItem,
  createSegmentedControlController,
} from "@/components/ui/ui-sdk-segmented-control"

type Range = "day" | "week" | "month"

function UiSdkSegmentedControlControlled() {
  const [controller] = React.useState(() =>
    createSegmentedControlController<Range>()
  )
  const [range, setRange] = React.useState<Range | null>("week")

  return (
    <div className="flex flex-col items-center gap-3">
      <SegmentedControl<Range>
        aria-label="Range"
        value={range}
        onValueChange={(value) => setRange(value)}
        controller={controller}
      >
        <SegmentedControlItem value="day">Day</SegmentedControlItem>
        <SegmentedControlItem value="week">Week</SegmentedControlItem>
        <SegmentedControlItem value="month">Month</SegmentedControlItem>
      </SegmentedControl>
      <div className="flex items-center gap-2">
        <Button
          size="sm"
          variant="outline"
          onClick={() => controller.setValue("month")}
        >
          Show month
        </Button>
        <p className="m-0 text-xs text-muted-foreground">
          {`Showing ${range ?? "nothing"}`}
        </p>
      </div>
    </div>
  )
}

export { UiSdkSegmentedControlControlled }
```

## Props in this example

### SegmentedControlItem

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | – |  |

## More Segmented control examples

- [Sizes](https://hextaui.com/docs/ui-sdk-segmented-control/examples/sizes)
- [Icons](https://hextaui.com/docs/ui-sdk-segmented-control/examples/icons)
- [Full width](https://hextaui.com/docs/ui-sdk-segmented-control/examples/full-width)
- [Vertical](https://hextaui.com/docs/ui-sdk-segmented-control/examples/vertical)
- [Disabled](https://hextaui.com/docs/ui-sdk-segmented-control/examples/disabled)
- [Form](https://hextaui.com/docs/ui-sdk-segmented-control/examples/form)
- [Read-only](https://hextaui.com/docs/ui-sdk-segmented-control/examples/read-only)
- [Right to left](https://hextaui.com/docs/ui-sdk-segmented-control/examples/rtl)
