# Slider

> Numeric slider bound via Controller, validated against a Zod range.

A shadcn/ui block from the [@flx](https://ui.flexnative.com) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/flx/rhf-fields-04).

- Page, with a live preview: https://shadcn.exchange/r/flx/rhf-fields-04
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/flx/rhf-fields-04-light-09cef979a118532a.png
- Registry item: https://ui.flexnative.com/r/rhf-fields-04.json
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://ui.flexnative.com/r/rhf-fields-04.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `@hookform/resolvers`, `react-hook-form`, `sonner`, `zod`
- Registry items: `field`, `slider`, `button`

## Files

### `registry/forms/react-hook-form/fields/rhf-fields-04.tsx`

```tsx
'use client'

import { Controller, useForm } from 'react-hook-form'
import { zodResolver } from '@hookform/resolvers/zod'
import { toast } from 'sonner'
import * as z from 'zod'

import { Button } from '@/components/ui/button'
import {
  Field,
  FieldContent,
  FieldDescription,
  FieldError,
  FieldGroup,
  FieldLabel,
} from '@/components/ui/field'
import { Slider } from '@/components/ui/slider'

const formSchema = z.object({
  budget: z
    .number()
    .min(10, 'Budget must be at least $10.')
    .max(100, 'Budget cannot exceed $100.'),
})

type FormValues = z.infer<typeof formSchema>

export function RhfFields04() {
  const form = useForm<FormValues>({
    resolver: zodResolver(formSchema),
    defaultValues: { budget: 0 },
  })

  function onSubmit(data: FormValues) {
    toast.success('Budget set', { description: `$${data.budget} / month` })
  }

  return (
    <form
      onSubmit={form.handleSubmit(onSubmit)}
      className="flex w-full max-w-sm flex-col gap-6"
    >
      <FieldGroup>
        <Controller
          control={form.control}
          name="budget"
          render={({ field, fieldState }) => (
            <Field data-invalid={fieldState.invalid}>
              <FieldContent>
                <FieldLabel htmlFor="rhf-fields-04-budget">
                  Monthly budget
                </FieldLabel>
                <FieldDescription>${field.value} / month</FieldDescription>
              </FieldContent>
              <Slider
                id="rhf-fields-04-budget"
                min={0}
                max={100}
                step={5}
                value={[field.value]}
                onValueChange={(v) => field.onChange((v as number[])[0])}
                aria-invalid={fieldState.invalid}
              />
              {fieldState.invalid && <FieldError errors={[fieldState.error]} />}
            </Field>
          )}
        />
      </FieldGroup>
      <Button type="submit" size="sm">
        Save
      </Button>
    </form>
  )
}
```
