# Feedback

Opt-in haptics and click sounds for controls, in the spirit of Apple platforms.

Page: https://sui.draco.dev/docs/components/feedback

`FeedbackProvider` turns on short haptics, and optionally soft synthesized clicks, for the controls inside it. Feedback is off by default, so components behave exactly like their primitives until you enable it.

### Example: feedback-demo

```tsx
import { FeedbackProvider } from "@workspace/ui/components/feedback";
import { Label } from "@workspace/ui/components/label";
import { Slider } from "@workspace/ui/components/slider";
import { Switch } from "@workspace/ui/components/switch";
import {
  ToggleGroup,
  ToggleGroupItem,
} from "@workspace/ui/components/toggle-group";
import { useId as usePreviewId } from "react";

export function FeedbackDemo() {
  const previewId = usePreviewId();

  return (
    <FeedbackProvider haptics sound>
      <div className="flex w-full max-w-xs flex-col gap-6">
        <div className="flex items-center space-x-2">
          <Switch id={`${previewId}-wifi`} defaultChecked />
          <Label htmlFor={`${previewId}-wifi`}>Wi-Fi</Label>
        </div>
        <ToggleGroup variant="outline" spacing={0} defaultValue={["day"]}>
          <ToggleGroupItem value="day">Day</ToggleGroupItem>
          <ToggleGroupItem value="week">Week</ToggleGroupItem>
          <ToggleGroupItem value="month">Month</ToggleGroupItem>
        </ToggleGroup>
        <Slider defaultValue={[5]} max={10} aria-label="Volume" />
      </div>
    </FeedbackProvider>
  );
}

export default FeedbackDemo;
```

## Installation

```bash
npx shadcn@latest add @sui/feedback
```

With pnpm, Yarn or Bun, use `pnpm dlx`, `yarn dlx` or `bunx --bun` in place of `npx`, and `pnpm add`, `yarn add` or `bun add` in place of `npm install`.

Install with the shadcn CLI or use the shared `@workspace/ui` package. Follow the [installation guide](/docs/installation) to configure the registry, load styles, and choose import aliases.

## Usage

```tsx showLineNumbers
import { FeedbackProvider } from "@workspace/ui/components/feedback"
```

```tsx showLineNumbers
<FeedbackProvider haptics>
  {/* Your app content */}
</FeedbackProvider>
```

Add `sound` for clicks as well. Most Apple controls stay quiet, so haptics alone is the closer match.

## Per component

Every supported component takes a `feedback` prop that overrides the provider for that instance.

| Value | Effect |
| --- | --- |
| unset | Follows the nearest `FeedbackProvider`; silent without one. |
| `true` | Haptics and sound. |
| `"haptic"` | Haptics only. |
| `"sound"` | Sound only. |
| `false` | Silent, even inside an enabled provider. |

```tsx showLineNumbers
<Switch feedback="haptic" />
<Button feedback>Save</Button>
```

`Button` stays silent unless `feedback` is set, even inside an enabled provider, because most buttons should not tap back.

## Moments

| Component | When | Haptic |
| --- | --- | --- |
| `Switch` | Toggled | light; rising or falling click |
| `Checkbox`, `RadioGroup`, `Toggle` | Selection changes | selection |
| `Tabs`, `ToggleGroup`, `TabBar` | Selection changes | selection |
| `TabBar` | Long press, then each item passed while sliding | medium, then selection |
| `Slider` | Reaching either end; each step when there are 20 or fewer | light; selection |
| `BottomSheet`, `Drawer` | Settling on a detent or snap point | light |
| `WheelPicker` | Each row crossed | selection, tick |
| `Toaster` | A success, warning or error toast appears | notification |
| `CopyButton`, `CopyText` | Copy succeeds or fails | success or error |
| `InputOTP` | `status` turns success or error | success or error |
| `Button` | Clicked | light; medium for `destructive` |

## Platform support

- **Android and other browsers with the Vibration API** play a timed pattern for each kind.
- **iOS 18 and later** have no Vibration API. A hidden `<input type="checkbox" switch>` plays the system Taptic click, so notification kinds differ by the number of clicks.
- **Desktop** has no haptics; only sound plays.

Browsers only allow haptics during a user gesture. Feedback that follows asynchronous work, such as a copy result or a toast, may not vibrate on iOS. Sound never plays before the first user interaction.

## useFeedback

`useFeedback` returns a stable `trigger(kind, sound)` for your own components. It follows the provider and accepts the same `feedback` option.

```tsx showLineNumbers
import { type FeedbackOption, useFeedback } from "@workspace/ui/components/feedback"

function Stepper({ feedback }: { feedback?: FeedbackOption }) {
  const trigger = useFeedback(feedback)
  return <button onClick={() => trigger("selection", "tick")}>+</button>
}
```

`kind` is one of `"selection"`, `"light"`, `"medium"`, `"heavy"`, `"success"`, `"warning"` or `"error"`. `sound` is `"tick"`, `"tap"`, `"toggle-on"` or `"toggle-off"`, or `false` for haptics only. Pass `{ optIn: true }` as the second argument to ignore the provider, as `Button` does.

## API Reference

### FeedbackProvider

| Prop | Type | Default |
| --- | --- | --- |
| `haptics` | `boolean` | `false` |
| `sound` | `boolean` | `false` |
