url
stringlengths 17
87
| content
stringlengths 152
81.8k
|
---|---|
https://www.chakra-ui.com/docs/components/drawer | 1. Components
2. Drawer
# Drawer
Used to render a content that slides in from the side of the screen.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/drawer)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-drawer--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/drawer.ts)[Ark](https://ark-ui.com/react/docs/components/dialog)
PreviewCode
Open Drawer
```
import { Button } from "@/components/ui/button"
import {
DrawerActionTrigger,
DrawerBackdrop,
DrawerBody,
DrawerCloseTrigger,
DrawerContent,
DrawerFooter,
DrawerHeader,
DrawerRoot,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"
const Demo = () => {
return (
<DrawerRoot>
<DrawerBackdrop />
<DrawerTrigger asChild>
<Button variant="outline" size="sm">
Open Drawer
</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Drawer Title</DrawerTitle>
</DrawerHeader>
<DrawerBody>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</DrawerBody>
<DrawerFooter>
<DrawerActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DrawerActionTrigger>
<Button>Save</Button>
</DrawerFooter>
<DrawerCloseTrigger />
</DrawerContent>
</DrawerRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `drawer` snippet
```
npx @chakra-ui/cli snippet add drawer
```
The snippet includes a closed component composition for the `Drawer` component.
## [Usage]()
```
import {
DrawerBackdrop,
DrawerBody,
DrawerCloseTrigger,
DrawerContent,
DrawerFooter,
DrawerHeader,
DrawerRoot,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"
```
```
<DrawerRoot>
<DrawerBackdrop />
<DrawerTrigger />
<DrawerContent>
<DrawerCloseTrigger />
<DrawerHeader>
<DrawerTitle />
</DrawerHeader>
<DrawerBody />
<DrawerFooter />
</DrawerContent>
</DrawerRoot>
```
## [Examples]()
### [Controlled]()
Use the `open` and `onOpenChange` props to control the drawer component.
PreviewCode
Open Drawer
```
"use client"
import { Button } from "@/components/ui/button"
import {
DrawerActionTrigger,
DrawerBackdrop,
DrawerBody,
DrawerCloseTrigger,
DrawerContent,
DrawerFooter,
DrawerHeader,
DrawerRoot,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"
import { useState } from "react"
const Demo = () => {
const [open, setOpen] = useState(false)
return (
<DrawerRoot open={open} onOpenChange={(e) => setOpen(e.open)}>
<DrawerBackdrop />
<DrawerTrigger asChild>
<Button variant="outline" size="sm">
Open Drawer
</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Drawer Title</DrawerTitle>
</DrawerHeader>
<DrawerBody>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</DrawerBody>
<DrawerFooter>
<DrawerActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DrawerActionTrigger>
<Button>Save</Button>
</DrawerFooter>
<DrawerCloseTrigger />
</DrawerContent>
</DrawerRoot>
)
}
```
### [Sizes]()
Use the `size` prop to change the size of the drawer component.
PreviewCode
Open (xs)Open (sm)Open (md)Open (lg)Open (xl)Open (full)
```
import { For, HStack, Kbd } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
DrawerActionTrigger,
DrawerBackdrop,
DrawerBody,
DrawerCloseTrigger,
DrawerContent,
DrawerFooter,
DrawerHeader,
DrawerRoot,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"
const Demo = () => {
return (
<HStack wrap="wrap">
<For each={["xs", "sm", "md", "lg", "xl", "full"]}>
{(size) => (
<DrawerRoot key={size} size={size}>
<DrawerBackdrop />
<DrawerTrigger asChild>
<Button variant="outline" size="sm">
Open ({size})
</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Drawer Title</DrawerTitle>
</DrawerHeader>
<DrawerBody>
Press the <Kbd>esc</Kbd> key to close the drawer.
</DrawerBody>
<DrawerFooter>
<DrawerActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DrawerActionTrigger>
<Button>Save</Button>
</DrawerFooter>
<DrawerCloseTrigger />
</DrawerContent>
</DrawerRoot>
)}
</For>
</HStack>
)
}
```
### [Offset]()
Pass the `offset` prop to the `DrawerContent` to change the offset of the drawer component.
PreviewCode
Open Drawer
```
import { Button } from "@/components/ui/button"
import {
DrawerActionTrigger,
DrawerBackdrop,
DrawerBody,
DrawerCloseTrigger,
DrawerContent,
DrawerFooter,
DrawerHeader,
DrawerRoot,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"
const Demo = () => {
return (
<DrawerRoot>
<DrawerBackdrop />
<DrawerTrigger asChild>
<Button variant="outline" size="sm">
Open Drawer
</Button>
</DrawerTrigger>
<DrawerContent offset="4" rounded="md">
<DrawerHeader>
<DrawerTitle>Drawer Title</DrawerTitle>
</DrawerHeader>
<DrawerBody>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</DrawerBody>
<DrawerFooter>
<DrawerActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DrawerActionTrigger>
<Button>Save</Button>
</DrawerFooter>
<DrawerCloseTrigger />
</DrawerContent>
</DrawerRoot>
)
}
```
### [Placement]()
Use the `placement` prop to change the placement of the drawer component.
PreviewCode
Open (bottom)Open (top)Open (start)Open (end)
```
import { For, HStack } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
DrawerActionTrigger,
DrawerBackdrop,
DrawerBody,
DrawerCloseTrigger,
DrawerContent,
DrawerFooter,
DrawerHeader,
DrawerRoot,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"
const Demo = () => {
return (
<HStack wrap="wrap">
<For each={["bottom", "top", "start", "end"]}>
{(placement) => (
<DrawerRoot key={placement} placement={placement}>
<DrawerBackdrop />
<DrawerTrigger asChild>
<Button variant="outline" size="sm">
Open ({placement})
</Button>
</DrawerTrigger>
<DrawerContent
roundedTop={placement === "bottom" ? "l3" : undefined}
roundedBottom={placement === "top" ? "l3" : undefined}
>
<DrawerHeader>
<DrawerTitle>Drawer Title</DrawerTitle>
</DrawerHeader>
<DrawerBody>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</DrawerBody>
<DrawerFooter>
<DrawerActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DrawerActionTrigger>
<Button>Save</Button>
</DrawerFooter>
<DrawerCloseTrigger />
</DrawerContent>
</DrawerRoot>
)}
</For>
</HStack>
)
}
```
### [Initial Focus]()
Use the `initialFocusEl` prop to set the initial focus of the drawer component.
PreviewCode
Open Drawer
```
"use client"
import { Input, Stack } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
DrawerActionTrigger,
DrawerBackdrop,
DrawerBody,
DrawerCloseTrigger,
DrawerContent,
DrawerFooter,
DrawerHeader,
DrawerRoot,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"
import { useRef } from "react"
const Demo = () => {
const ref = useRef<HTMLInputElement>(null)
return (
<DrawerRoot initialFocusEl={() => ref.current}>
<DrawerBackdrop />
<DrawerTrigger asChild>
<Button variant="outline" size="sm">
Open Drawer
</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Drawer Title</DrawerTitle>
</DrawerHeader>
<DrawerBody>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
<Stack mt="5">
<Input defaultValue="Naruto" placeholder="First name" />
<Input ref={ref} placeholder="Email" />
</Stack>
</DrawerBody>
<DrawerFooter>
<DrawerActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DrawerActionTrigger>
<Button>Save</Button>
</DrawerFooter>
<DrawerCloseTrigger />
</DrawerContent>
</DrawerRoot>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'xs'`
`'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full'`
The size of the component
`placement``'end'`
`'start' | 'end' | 'top' | 'bottom'`
The placement of the component
`contained`
`'true' | 'false'`
The contained of the component
`as`
`React.ElementType`
The underlying element to render.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Dialog](https://www.chakra-ui.com/docs/components/dialog)
[Next
\
Editable](https://www.chakra-ui.com/docs/components/editable) |
https://www.chakra-ui.com/docs/components/fieldset | 1. Components
2. Fieldset
# Fieldset
A set of form controls optionally grouped under a common name.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/fieldset)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-fieldset--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/fieldset.ts)[Ark](https://ark-ui.com/react/docs/components/fieldset)
PreviewCode
Contact detailsPlease provide your contact details below.
Name
Email address
Country
United Kingdom (UK)Canada (CA)United States (US)
Submit
```
import { Button, Fieldset, Input, Stack } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
const Demo = () => {
return (
<Fieldset.Root size="lg" maxW="md">
<Stack>
<Fieldset.Legend>Contact details</Fieldset.Legend>
<Fieldset.HelperText>
Please provide your contact details below.
</Fieldset.HelperText>
</Stack>
<Fieldset.Content>
<Field label="Name">
<Input name="name" />
</Field>
<Field label="Email address">
<Input name="email" type="email" />
</Field>
<Field label="Country">
<NativeSelectRoot>
<NativeSelectField
name="country"
items={[
"United Kingdom (UK)",
"Canada (CA)",
"United States (US)",
]}
/>
</NativeSelectRoot>
</Field>
</Fieldset.Content>
<Button type="submit" alignSelf="flex-start">
Submit
</Button>
</Fieldset.Root>
)
}
```
## [Usage]()
```
import { Fieldset } from "@chakra-ui/react"
```
```
<Fieldset.Root>
<Fieldset.Legend />
<Fieldset.Content />
</Fieldset.Root>
```
## [Examples]()
### [Disabled]()
Use the `disabled` prop to disable the fieldset to disable all input elements within the fieldset.
PreviewCode
Shipping details
Street address
Country
United Kingdom (UK)Canada (CA)United States (US)
Delivery notes
```
import { Fieldset, Input, Textarea } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
const Demo = () => {
return (
<Fieldset.Root size="lg" disabled>
<Fieldset.Legend>Shipping details</Fieldset.Legend>
<Field label="Street address">
<Input name="address" />
</Field>
<Field label="Country">
<NativeSelectRoot>
<NativeSelectRoot>
<NativeSelectField
name="country"
items={[
"United Kingdom (UK)",
"Canada (CA)",
"United States (US)",
]}
/>
</NativeSelectRoot>
</NativeSelectRoot>
</Field>
<Field label="Delivery notes">
<Textarea name="notes" />
</Field>
</Fieldset.Root>
)
}
```
### [Invalid]()
Use the `invalid` prop to mark the fieldset as invalid. This will show the error text.
Note: You need to pass the `invalid` prop to the `Field` component within the fieldset to make each input element invalid.
PreviewCode
Shipping details
Street address
Country
United Kingdom (UK)Canada (CA)United States (US)
Notes
Some fields are invalid. Please check them.
```
import { Fieldset, Input, Textarea } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
const Demo = () => {
return (
<Fieldset.Root size="lg" invalid>
<Fieldset.Legend>Shipping details</Fieldset.Legend>
<Fieldset.Content>
<Field label="Street address">
<Input name="address" />
</Field>
<Field label="Country" invalid>
<NativeSelectRoot>
<NativeSelectField
name="country"
items={[
"United Kingdom (UK)",
"Canada (CA)",
"United States (US)",
]}
/>
</NativeSelectRoot>
</Field>
<Field label="Notes" invalid>
<Textarea name="notes" />
</Field>
</Fieldset.Content>
<Fieldset.ErrorText>
Some fields are invalid. Please check them.
</Fieldset.ErrorText>
</Fieldset.Root>
)
}
```
## [Props]()
PropDefaultType`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`invalid`
`boolean`
Indicates whether the fieldset is invalid.
[Previous
\
Field](https://www.chakra-ui.com/docs/components/field)
[Next
\
File Upload](https://www.chakra-ui.com/docs/components/file-upload) |
https://www.chakra-ui.com/docs/components/color-picker | 1. Components
2. Color Picker
# Color Picker
Used to select colors from a color area or a set of defined swatches
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/color-picker)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-color-picker--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/color-picker.ts)[Ark](https://ark-ui.com/react/docs/components/color-picker)
PreviewCode
Color
```
"use client"
import { HStack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot defaultValue={parseColor("#eb5e41")} maxW="200px">
<ColorPickerLabel>Color</ColorPickerLabel>
<ColorPickerControl>
<ColorPickerInput />
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
</HStack>
</ColorPickerContent>
</ColorPickerRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `color-picker` snippet
```
npx @chakra-ui/cli snippet add color-picker
```
The snippet includes a closed component composition for the `ColorPicker` component.
## [Usage]()
```
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
```
```
<ColorPickerRoot>
<ColorPickerLabel />
<ColorPickerControl>
<ColorPickerInput />
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<ColorPickerEyeDropper />
<ColorPickerSliders />
</ColorPickerContent>
</ColorPickerRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the color picker.
PreviewCode
Color (2xs)
Color (xs)
Color (sm)
Color (md)
Color (lg)
Color (xl)
Color (2xl)
```
"use client"
import { For, HStack, Stack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerSwatchGroup,
ColorPickerSwatchTrigger,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<Stack gap="8" maxW="sm">
<For each={["2xs", "xs", "sm", "md", "lg", "xl", "2xl"]}>
{(size) => (
<ColorPickerRoot
key={size}
defaultValue={parseColor("#eb5e41")}
size={size}
>
<ColorPickerLabel>Color ({size})</ColorPickerLabel>
<ColorPickerControl>
<ColorPickerInput />
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
</HStack>
<ColorPickerSwatchGroup>
{["red", "blue", "green"].map((item) => (
<ColorPickerSwatchTrigger
swatchSize="4.5"
key={item}
value={item}
/>
))}
</ColorPickerSwatchGroup>
</ColorPickerContent>
</ColorPickerRoot>
)}
</For>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to change the visual style of the color picker. Values can be either `outline` or `subtle`.
PreviewCode
Color (outline)
Color (subtle)
```
"use client"
import { For, HStack, Stack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<Stack gap="8">
<For each={["outline", "subtle"]}>
{(variant) => (
<ColorPickerRoot
defaultValue={parseColor("#eb5e41")}
maxW="200px"
variant={variant}
>
<ColorPickerLabel>Color ({variant})</ColorPickerLabel>
<ColorPickerControl>
<ColorPickerInput />
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
</HStack>
</ColorPickerContent>
</ColorPickerRoot>
)}
</For>
</Stack>
)
}
```
### [Input Only]()
Combine the `ColorPickerValueSwatch` and the `ColorPickerEyeDropper` on the `InputGroup` to render a color picker that contains only an input.
PreviewCode
Color
```
"use client"
import { parseColor } from "@chakra-ui/react"
import {
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerValueSwatch,
} from "@/components/ui/color-picker"
import { InputGroup } from "@/components/ui/input-group"
const Demo = () => {
return (
<ColorPickerRoot defaultValue={parseColor("#eb5e41")} maxW="200px">
<ColorPickerLabel>Color</ColorPickerLabel>
<ColorPickerControl>
<InputGroup
startOffset="0px"
startElement={<ColorPickerValueSwatch boxSize="4.5" />}
endElementProps={{ px: "1" }}
endElement={<ColorPickerEyeDropper variant="ghost" />}
>
<ColorPickerInput />
</InputGroup>
</ColorPickerControl>
</ColorPickerRoot>
)
}
```
### [Swatch Only]()
Use the `ColorPickerSwatchGroup` and `ColorPickerSwatchTrigger` to render only the color swatches.
PreviewCode
Color: rgba(0, 0, 0, 1)
```
import {
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSwatchGroup,
ColorPickerSwatchTrigger,
ColorPickerValueText,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot alignItems="flex-start">
<ColorPickerLabel>
Color: <ColorPickerValueText />
</ColorPickerLabel>
<ColorPickerSwatchGroup>
{swatches.map((item) => (
<ColorPickerSwatchTrigger key={item} value={item} />
))}
</ColorPickerSwatchGroup>
</ColorPickerRoot>
)
}
const swatches = ["red", "green", "blue", "purple", "orange", "pink"]
```
### [Trigger Only]()
Compose the color picker to initially show only a trigger using the `ColorPickerValueSwatch` and `ColorPickerValueText`.
PreviewCode
Color
rgba(235, 94, 65, 1)
```
"use client"
import { HStack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerTrigger,
ColorPickerValueSwatch,
ColorPickerValueText,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot defaultValue={parseColor("#eb5e41")} maxW="200px">
<ColorPickerLabel>Color</ColorPickerLabel>
<ColorPickerControl>
<ColorPickerTrigger px="2">
<ColorPickerValueSwatch boxSize="6" />
<ColorPickerValueText minW="160px" />
</ColorPickerTrigger>
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
<ColorPickerValueSwatch />
</HStack>
</ColorPickerContent>
</ColorPickerRoot>
)
}
```
### [Trigger Inside Input]()
Compose the color picker to trigger in input using the `InputGroup` and `ColorPickerInput`.
PreviewCode
Color
rgba(235, 94, 65, 1)
```
"use client"
import { HStack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerTrigger,
ColorPickerValueSwatch,
ColorPickerValueText,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot defaultValue={parseColor("#eb5e41")} maxW="200px">
<ColorPickerLabel>Color</ColorPickerLabel>
<ColorPickerControl>
<ColorPickerTrigger px="2">
<ColorPickerValueSwatch boxSize="6" />
<ColorPickerValueText minW="160px" />
</ColorPickerTrigger>
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
<ColorPickerValueSwatch />
</HStack>
</ColorPickerContent>
</ColorPickerRoot>
)
}
```
### [Controlled]()
Use the `value` and `onValueChange` props to control the state of the color picker.
PreviewCode
Color
```
"use client"
import { HStack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
import { useState } from "react"
const Demo = () => {
const [color, setColor] = useState(parseColor("#eb5e41"))
return (
<ColorPickerRoot
value={color}
format="hsla"
onValueChange={(e) => setColor(e.value)}
maxW="200px"
>
<ColorPickerLabel>Color</ColorPickerLabel>
<ColorPickerControl>
<ColorPickerInput />
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
</HStack>
</ColorPickerContent>
</ColorPickerRoot>
)
}
```
### [Change End]()
Use the `onValueChangeEnd` to listen to when the user finishes selecting a color, rather than while they are scrubbing or dragging through the color area.
PreviewCode
`onChangeEnd: #EB5E41`
Color
```
"use client"
import { Code, HStack, Stack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
import { useState } from "react"
const Demo = () => {
const [value, setValue] = useState(parseColor("#eb5e41"))
return (
<Stack gap="8" align="flex-start">
<Code>
onChangeEnd: <b>{value.toString("hex")}</b>
</Code>
<ColorPickerRoot
defaultValue={value}
onValueChangeEnd={(e) => setValue(e.value)}
>
<ColorPickerLabel>Color</ColorPickerLabel>
<ColorPickerControl>
<ColorPickerInput />
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
</HStack>
</ColorPickerContent>
</ColorPickerRoot>
</Stack>
)
}
```
### [Channel Slider]()
Combine the `ColorPickerChannelSliders` and the `format` prop to add the different color channels to the color picker.
PreviewCode
rgbahslahsba
red
green
blue
alpha
```
"use client"
import { ColorPickerFormatSelect, parseColor } from "@chakra-ui/react"
import {
ColorPickerChannelSliders,
ColorPickerContent,
ColorPickerControl,
ColorPickerRoot,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot defaultValue={parseColor("#eb5e41")} maxW="200px">
<ColorPickerControl>
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerFormatSelect />
<ColorPickerChannelSliders format="hsla" />
<ColorPickerChannelSliders format="hsba" />
<ColorPickerChannelSliders format="rgba" />
</ColorPickerContent>
</ColorPickerRoot>
)
}
```
### [Hook Form]()
Here's an example of how to integrate the color picker with `react-hook-form`.
PreviewCode
Submit
```
"use client"
import { Button, HStack, Stack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
import { Controller, useForm } from "react-hook-form"
interface FormValues {
color: string
}
const Demo = () => {
const { control, handleSubmit } = useForm<FormValues>({
defaultValues: { color: "#000000" },
})
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Stack gap="4" align="flex-start" maxW="sm">
<Controller
name="color"
control={control}
render={({ field }) => (
<ColorPickerRoot
name={field.name}
defaultValue={parseColor(field.value)}
onValueChange={(e) => field.onChange(e.valueAsString)}
>
<ColorPickerControl>
<ColorPickerInput />
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
</HStack>
</ColorPickerContent>
</ColorPickerRoot>
)}
/>
<Button type="submit">Submit</Button>
</Stack>
</form>
)
}
```
### [Inline]()
Use the `ColorPickerInlineContent` and pass `open` to the `ColorPickerRoot` to display an inline version of the color picker.
PreviewCode
```
"use client"
import { HStack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerEyeDropper,
ColorPickerInlineContent,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerValueSwatch,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot open defaultValue={parseColor("#000")}>
<ColorPickerInlineContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
<ColorPickerValueSwatch />
</HStack>
</ColorPickerInlineContent>
</ColorPickerRoot>
)
}
```
### [Disabled]()
Pass the `disabled` prop to disable the color picker.
PreviewCode
Color
```
"use client"
import { HStack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot disabled defaultValue={parseColor("#eb5e41")} maxW="200px">
<ColorPickerLabel>Color</ColorPickerLabel>
<ColorPickerControl>
<ColorPickerInput />
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
</HStack>
</ColorPickerContent>
</ColorPickerRoot>
)
}
```
### [Channel Input]()
Use the `ChannelFormatSelect` and `ColorPickerChannelInputs` to create a color picker that allows users to select their preferred channel.
PreviewCode
Color
R
G
B
A
```
"use client"
import { HStack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerChannelInputs,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot defaultValue={parseColor("#eb5e41")} maxW="200px">
<ColorPickerLabel>Color</ColorPickerLabel>
<ColorPickerControl>
<ColorPickerInput />
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
</HStack>
<ColorPickerChannelInputs format="rgba" />
<ColorPickerChannelInputs format="hsla" />
<ColorPickerChannelInputs format="hsba" />
</ColorPickerContent>
</ColorPickerRoot>
)
}
```
### [Fit Content]()
Here's an example of how to create a rounded trigger that fits the content.
PreviewCode
Color
```
"use client"
import { HStack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerTrigger,
ColorPickerValueSwatch,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot defaultValue={parseColor("#eb5e41")} maxW="200px">
<ColorPickerLabel>Color</ColorPickerLabel>
<ColorPickerControl>
<ColorPickerInput />
<ColorPickerTrigger fitContent rounded="full">
<ColorPickerValueSwatch rounded="inherit" />
</ColorPickerTrigger>
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
</HStack>
</ColorPickerContent>
</ColorPickerRoot>
)
}
```
### [ReadOnly]()
Use the `readOnly` prop to make the color picker component read-only.
### [Save Swatch]()
Here's an example of how to save a selected color as a swatch.
PreviewCode
```
"use client"
import {
Button,
HStack,
IconButton,
Show,
VStack,
parseColor,
} from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerSwatchGroup,
ColorPickerSwatchTrigger,
ColorPickerTrigger,
ColorPickerValueSwatch,
} from "@/components/ui/color-picker"
import { useState } from "react"
import { LuPlus, LuType } from "react-icons/lu"
const Demo = () => {
const [color, setColor] = useState(parseColor("#000"))
const [view, setView] = useState<"picker" | "swatch">("swatch")
const [swatches, setSwatches] = useState<string[]>([
"#FF0000",
"#00FF00",
"#0000FF",
"#FFFF00",
])
return (
<ColorPickerRoot
defaultValue={color}
onValueChange={(e) => setColor(e.value)}
maxW="200px"
>
<ColorPickerControl>
<ColorPickerTrigger>
<VStack gap="1">
<LuType />
<ColorPickerValueSwatch h="2" />
</VStack>
</ColorPickerTrigger>
</ColorPickerControl>
<ColorPickerContent>
<Show when={view === "picker"}>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
</HStack>
<Button
onClick={() => {
setSwatches((prev) => [...prev, color.toString("css")])
setView("swatch")
}}
>
Save Swatch
</Button>
</Show>
<Show when={view === "swatch"}>
<ColorPickerSwatchGroup>
{swatches.map((swatch) => (
<ColorPickerSwatchTrigger key={swatch} value={swatch} />
))}
<IconButton
variant="outline"
size="xs"
onClick={() => setView("picker")}
>
<LuPlus />
</IconButton>
</ColorPickerSwatchGroup>
</Show>
</ColorPickerContent>
</ColorPickerRoot>
)
}
```
### [Swatches]()
Here's an example of how to combine the color picker with pre-defined swatches.
PreviewCode
Color
```
"use client"
import { HStack, parseColor } from "@chakra-ui/react"
import {
ColorPickerArea,
ColorPickerContent,
ColorPickerControl,
ColorPickerEyeDropper,
ColorPickerInput,
ColorPickerLabel,
ColorPickerRoot,
ColorPickerSliders,
ColorPickerSwatchGroup,
ColorPickerSwatchTrigger,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot defaultValue={parseColor("#eb5e41")} maxW="200px">
<ColorPickerLabel>Color</ColorPickerLabel>
<ColorPickerControl>
<ColorPickerInput />
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerArea />
<HStack>
<ColorPickerEyeDropper />
<ColorPickerSliders />
</HStack>
<ColorPickerSwatchGroup>
{swatches.map((item) => (
<ColorPickerSwatchTrigger
swatchSize="4.5"
key={item}
value={item}
/>
))}
</ColorPickerSwatchGroup>
</ColorPickerContent>
</ColorPickerRoot>
)
}
// prettier-ignore
const swatches = ["#000000", "#4A5568", "#F56565", "#ED64A6", "#9F7AEA", "#6B46C1", "#4299E1", "#0BC5EA", "#00B5D8", "#38B2AC", "#48BB78", "#68D391", "#ECC94B", "#DD6B20"]
```
### [Swatch and Input]()
Here's how to compose a swatch with an input.
PreviewCode
```
"use client"
import { ColorPickerChannelInput, parseColor } from "@chakra-ui/react"
import {
ColorPickerContent,
ColorPickerControl,
ColorPickerRoot,
ColorPickerSwatchGroup,
ColorPickerSwatchTrigger,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot
size="xs"
defaultValue={parseColor("#eb5e41")}
maxW="200px"
>
<ColorPickerControl>
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerSwatchGroup>
{swatches.map((item) => (
<ColorPickerSwatchTrigger key={item} value={item} />
))}
</ColorPickerSwatchGroup>
<ColorPickerChannelInput channel="hex" />
</ColorPickerContent>
</ColorPickerRoot>
)
}
const swatches = ["red", "blue", "green"]
```
### [Swatch and Trigger]()
Here's how to compose a swatch with a trigger.
PreviewCode
```
"use client"
import { ColorPickerChannelInput, parseColor } from "@chakra-ui/react"
import {
ColorPickerContent,
ColorPickerControl,
ColorPickerRoot,
ColorPickerSwatchGroup,
ColorPickerSwatchTrigger,
ColorPickerTrigger,
} from "@/components/ui/color-picker"
const Demo = () => {
return (
<ColorPickerRoot
size="xs"
defaultValue={parseColor("#eb5e41")}
maxW="200px"
>
<ColorPickerControl>
<ColorPickerTrigger />
</ColorPickerControl>
<ColorPickerContent>
<ColorPickerSwatchGroup>
{swatches.map((item) => (
<ColorPickerSwatchTrigger key={item} value={item} />
))}
</ColorPickerSwatchGroup>
<ColorPickerChannelInput channel="hex" />
</ColorPickerContent>
</ColorPickerRoot>
)
}
const swatches = ["red", "blue", "green"]
```
## [Props]()
### [Root]()
PropDefaultType`closeOnSelect``false`
`boolean`
Whether to close the color picker when a swatch is selected
`format``'\'rgba\''`
`ColorFormat`
The color format to use
`lazyMount``false`
`boolean`
Whether to enable lazy mounting
`unmountOnExit``false`
`boolean`
Whether to unmount on exit.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultOpen`
`boolean`
The initial open state of the color picker when it is first rendered. Use when you do not need to control its open state.
`defaultValue`
`string`
The initial value of the color picker when it is first rendered. Use when you do not need to control the state of the color picker.
`disabled`
`boolean`
Whether the color picker is disabled
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ root: string; control: string; trigger: string; label: string; input: string; hiddenInput: string; content: string; area: string; areaGradient: string; positioner: string; formatSelect: string; areaThumb: string; channelInput(id: string): string; channelSliderTrack(id: ColorChannel): string; channelSliderT...`
The ids of the elements in the color picker. Useful for composition.
`immediate`
`boolean`
Whether to synchronize the present change immediately or defer it to the next frame
`initialFocusEl`
`() => HTMLElement | null`
The initial focus element when the color picker is opened.
`name`
`string`
The name for the form input
`onExitComplete`
`() => void`
Function called when the animation ends in the closed state
`onFocusOutside`
`(event: FocusOutsideEvent) => void`
Function called when the focus is moved outside the component
`onFormatChange`
`(details: FormatChangeDetails) => void`
Function called when the color format changes
`onInteractOutside`
`(event: InteractOutsideEvent) => void`
Function called when an interaction happens outside the component
`onOpenChange`
`(details: OpenChangeDetails) => void`
Handler that is called when the user opens or closes the color picker.
`onPointerDownOutside`
`(event: PointerDownOutsideEvent) => void`
Function called when the pointer is pressed down outside the component
`onValueChange`
`(details: ValueChangeDetails) => void`
Handler that is called when the value changes, as the user drags.
`onValueChangeEnd`
`(details: ValueChangeDetails) => void`
Handler that is called when the user stops dragging.
`open`
`boolean`
Whether the color picker is open
`positioning`
`PositioningOptions`
The positioning options for the color picker
`present`
`boolean`
Whether the node is present (controlled by the user)
`readOnly`
`boolean`
Whether the color picker is read-only
`required`
`boolean`
Whether the color picker is required
`value`
`string`
The current value of the color picker.
[Previous
\
Collapsible](https://www.chakra-ui.com/docs/components/collapsible)
[Next
\
Color Swatch](https://www.chakra-ui.com/docs/components/color-swatch) |
https://www.chakra-ui.com/docs/components/dialog | 1. Components
2. Dialog
# Dialog
Used to display a dialog prompt
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/dialog)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-dialog--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/dialog.ts)[Ark](https://ark-ui.com/react/docs/components/dialog)
PreviewCode
Open Dialog
```
import { Button } from "@/components/ui/button"
import {
DialogActionTrigger,
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
const Demo = () => {
return (
<DialogRoot>
<DialogTrigger asChild>
<Button variant="outline" size="sm">
Open Dialog
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Dialog Title</DialogTitle>
</DialogHeader>
<DialogBody>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</DialogBody>
<DialogFooter>
<DialogActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DialogActionTrigger>
<Button>Save</Button>
</DialogFooter>
<DialogCloseTrigger />
</DialogContent>
</DialogRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `dialog` snippet
```
npx @chakra-ui/cli snippet add dialog
```
The snippet includes a closed component composition for the `Dialog` component.
## [Usage]()
```
import {
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
```
```
<DialogRoot>
<DialogBackdrop />
<DialogTrigger />
<DialogContent>
<DialogCloseTrigger />
<DialogHeader>
<DialogTitle />
</DialogHeader>
<DialogBody />
<DialogFooter />
</DialogContent>
</DialogRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the dialog component.
PreviewCode
Open (xs)Open (sm)Open (md)Open (lg)
```
import { For, HStack } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
DialogActionTrigger,
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
const Demo = () => {
return (
<HStack>
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<DialogRoot key={size} size={size}>
<DialogTrigger asChild>
<Button variant="outline" size={size}>
Open ({size})
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Dialog Title</DialogTitle>
</DialogHeader>
<DialogBody>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</DialogBody>
<DialogFooter>
<DialogActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DialogActionTrigger>
<Button>Save</Button>
</DialogFooter>
<DialogCloseTrigger />
</DialogContent>
</DialogRoot>
)}
</For>
</HStack>
)
}
```
### [Cover]()
Use the `size="cover"` prop to make the dialog component cover the entire screen while revealing a small portion of the page behind.
PreviewCode
Open Dialog
```
import { Button } from "@/components/ui/button"
import {
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
const Demo = () => {
return (
<DialogRoot size="cover" placement="center" motionPreset="slide-in-bottom">
<DialogTrigger asChild>
<Button variant="outline" size="sm">
Open Dialog
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Dialog Title</DialogTitle>
<DialogCloseTrigger />
</DialogHeader>
<DialogBody>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</DialogBody>
</DialogContent>
</DialogRoot>
)
}
```
### [Fullscreen]()
Use the `size="full"` prop to make the dialog component take up the entire screen.
PreviewCode
Open Dialog
```
import { Button } from "@/components/ui/button"
import {
DialogActionTrigger,
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
const Demo = () => {
return (
<DialogRoot size="full" motionPreset="slide-in-bottom">
<DialogTrigger asChild>
<Button variant="outline" size="sm">
Open Dialog
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Dialog Title</DialogTitle>
</DialogHeader>
<DialogBody>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</DialogBody>
<DialogFooter>
<DialogActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DialogActionTrigger>
<Button>Save</Button>
</DialogFooter>
<DialogCloseTrigger />
</DialogContent>
</DialogRoot>
)
}
```
### [Placement]()
Use the `placement` prop to change the placement of the dialog component.
PreviewCode
Open Dialog (top) Open Dialog (center) Open Dialog (bottom)
```
import { For, HStack } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
DialogActionTrigger,
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
const Demo = () => {
return (
<HStack wrap="wrap" gap="4">
<For each={["top", "center", "bottom"]}>
{(placement) => (
<DialogRoot
key={placement}
placement={placement}
motionPreset="slide-in-bottom"
>
<DialogTrigger asChild>
<Button variant="outline">Open Dialog ({placement}) </Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Dialog Title</DialogTitle>
</DialogHeader>
<DialogBody>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</DialogBody>
<DialogFooter>
<DialogActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DialogActionTrigger>
<Button>Save</Button>
</DialogFooter>
<DialogCloseTrigger />
</DialogContent>
</DialogRoot>
)}
</For>
</HStack>
)
}
```
### [Controlled]()
Use the `open` and `onOpenChange` prop to control the visibility of the dialog component.
PreviewCode
Open
```
"use client"
import { Button } from "@/components/ui/button"
import {
DialogActionTrigger,
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { useState } from "react"
import Lorem from "react-lorem-ipsum"
const Demo = () => {
const [open, setOpen] = useState(false)
return (
<DialogRoot lazyMount open={open} onOpenChange={(e) => setOpen(e.open)}>
<DialogTrigger asChild>
<Button variant="outline">Open</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Dialog Title</DialogTitle>
</DialogHeader>
<DialogBody>
<Lorem p={2} />
</DialogBody>
<DialogFooter>
<DialogActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DialogActionTrigger>
<Button>Save</Button>
</DialogFooter>
<DialogCloseTrigger />
</DialogContent>
</DialogRoot>
)
}
```
### [Initial Focus]()
Use the `initialFocusEl` prop to set the initial focus of the dialog component.
PreviewCode
Open
```
"use client"
import { Input, Stack } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
DialogActionTrigger,
DialogBody,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { Field } from "@/components/ui/field"
import { useRef } from "react"
const Demo = () => {
const ref = useRef<HTMLInputElement>(null)
return (
<DialogRoot initialFocusEl={() => ref.current}>
<DialogTrigger asChild>
<Button variant="outline">Open</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Dialog Header</DialogTitle>
</DialogHeader>
<DialogBody pb="4">
<Stack gap="4">
<Field label="First Name">
<Input placeholder="First Name" />
</Field>
<Field label="Last Name">
<Input ref={ref} placeholder="Focus First" />
</Field>
</Stack>
</DialogBody>
<DialogFooter>
<DialogActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DialogActionTrigger>
<Button>Save</Button>
</DialogFooter>
</DialogContent>
</DialogRoot>
)
}
```
### [Inside Scroll]()
Use the `scrollBehavior=inside` prop to change the scroll behavior of the dialog when its content overflows.
PreviewCode
Inside Scroll
```
import { Button } from "@/components/ui/button"
import {
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import Lorem from "react-lorem-ipsum"
const Demo = () => {
return (
<DialogRoot scrollBehavior="inside" size="sm">
<DialogTrigger asChild>
<Button variant="outline">Inside Scroll</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>With Inside Scroll</DialogTitle>
</DialogHeader>
<DialogCloseTrigger />
<DialogBody>
<Lorem p={8} />
</DialogBody>
</DialogContent>
</DialogRoot>
)
}
```
### [Outside Scroll]()
Use the `scrollBehavior=outside` prop to change the scroll behavior of the dialog when its content overflows.
PreviewCode
Outside Scroll
```
import { Button } from "@/components/ui/button"
import {
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import Lorem from "react-lorem-ipsum"
const Demo = () => {
return (
<DialogRoot size="sm" scrollBehavior="outside">
<DialogTrigger asChild>
<Button variant="outline">Outside Scroll</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>With Outside Scroll</DialogTitle>
</DialogHeader>
<DialogCloseTrigger />
<DialogBody>
<Lorem p={8} />
</DialogBody>
</DialogContent>
</DialogRoot>
)
}
```
### [Motion Preset]()
Use the `motionPreset` prop to change the animation of the dialog component.
PreviewCode
Slide in Bottom
```
import { Button } from "@/components/ui/button"
import {
DialogActionTrigger,
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
const Demo = () => {
return (
<DialogRoot motionPreset="slide-in-bottom">
<DialogTrigger asChild>
<Button variant="outline">Slide in Bottom</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Dialog Title</DialogTitle>
</DialogHeader>
<DialogBody>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</DialogBody>
<DialogFooter>
<DialogActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DialogActionTrigger>
<Button>Save</Button>
</DialogFooter>
<DialogCloseTrigger />
</DialogContent>
</DialogRoot>
)
}
```
### [Alert Dialog]()
Set the `role: "alertdialog"` prop to change the dialog component to an alert dialog.
PreviewCode
Open Dialog
```
import { Button } from "@/components/ui/button"
import {
DialogActionTrigger,
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
const Demo = () => {
return (
<DialogRoot role="alertdialog">
<DialogTrigger asChild>
<Button variant="outline" size="sm">
Open Dialog
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you sure?</DialogTitle>
</DialogHeader>
<DialogBody>
<p>
This action cannot be undone. This will permanently delete your
account and remove your data from our systems.
</p>
</DialogBody>
<DialogFooter>
<DialogActionTrigger asChild>
<Button variant="outline">Cancel</Button>
</DialogActionTrigger>
<Button colorPalette="red">Delete</Button>
</DialogFooter>
<DialogCloseTrigger />
</DialogContent>
</DialogRoot>
)
}
```
### [Close Button Outside]()
Here's an example of how to customize the `DialogCloseTrigger` component to position the close button outside the dialog component.
PreviewCode
Open Dialog
```
import { AspectRatio } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogDescription,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
const Demo = () => {
return (
<DialogRoot placement="center">
<DialogTrigger asChild>
<Button variant="outline" size="sm">
Open Dialog
</Button>
</DialogTrigger>
<DialogContent>
<DialogBody pt="4">
<DialogTitle>Dialog Title</DialogTitle>
<DialogDescription mb="4">
This is a dialog with some content and a video.
</DialogDescription>
<AspectRatio ratio={4 / 3} rounded="lg" overflow="hidden">
<iframe
title="naruto"
src="https://www.youtube.com/embed/QhBnZ6NPOY0"
allowFullScreen
/>
</AspectRatio>
</DialogBody>
<DialogCloseTrigger top="0" insetEnd="-12" bg="bg" />
</DialogContent>
</DialogRoot>
)
}
```
### [With DataList]()
Here's an example of how to compose the dialog component with the `DataList` component.
PreviewCode
Open Dialog
```
import { Badge, HStack, Textarea, VStack } from "@chakra-ui/react"
import { Avatar } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import { DataListItem, DataListRoot } from "@/components/ui/data-list"
import {
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
const Demo = () => {
return (
<VStack alignItems="start">
<DialogRoot>
<DialogTrigger asChild>
<Button variant="outline">Open Dialog</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Prepare Chakra V3</DialogTitle>
</DialogHeader>
<DialogBody pb="8">
<DataListRoot orientation="horizontal">
<DataListItem
label="Status"
value={<Badge colorPalette="green">Completed</Badge>}
/>
<DataListItem
label="Assigned to"
value={
<HStack>
<Avatar
size="xs"
name="Segun Adebayo"
src="https://bit.ly/sage-adebayo"
/>
Segun Adebayo
</HStack>
}
/>
<DataListItem label="Due date" value="12th August 2024" />
</DataListRoot>
<Textarea placeholder="Add a note" mt="8" />
</DialogBody>
<DialogCloseTrigger />
</DialogContent>
</DialogRoot>
</VStack>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`closeOnEscape``true`
`boolean`
Whether to close the dialog when the escape key is pressed
`closeOnInteractOutside``true`
`boolean`
Whether to close the dialog when the outside is clicked
`lazyMount``false`
`boolean`
Whether to enable lazy mounting
`modal``true`
`boolean`
Whether to prevent pointer interaction outside the element and hide all content below it
`preventScroll``true`
`boolean`
Whether to prevent scrolling behind the dialog when it's opened
`role``'\'dialog\''`
`'dialog' | 'alertdialog'`
The dialog's role
`trapFocus``true`
`boolean`
Whether to trap focus inside the dialog when it's opened
`unmountOnExit``false`
`boolean`
Whether to unmount on exit.
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`scrollBehavior``'outside'`
`'inside' | 'outside'`
The scrollBehavior of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full'`
The size of the component
`motionPreset``'scale'`
`'scale' | 'slide-in-bottom' | 'slide-in-top' | 'slide-in-left' | 'slide-in-right' | 'none'`
The motionPreset of the component
`aria-label`
`string`
Human readable label for the dialog, in event the dialog title is not rendered
`defaultOpen`
`boolean`
The initial open state of the dialog when it is first rendered. Use when you do not need to control its open state.
`finalFocusEl`
`() => HTMLElement | null`
Element to receive focus when the dialog is closed
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ trigger: string positioner: string backdrop: string content: string closeTrigger: string title: string description: string }>`
The ids of the elements in the dialog. Useful for composition.
`immediate`
`boolean`
Whether to synchronize the present change immediately or defer it to the next frame
`initialFocusEl`
`() => HTMLElement | null`
Element to receive focus when the dialog is opened
`onEscapeKeyDown`
`(event: KeyboardEvent) => void`
Function called when the escape key is pressed
`onExitComplete`
`() => void`
Function called when the animation ends in the closed state
`onFocusOutside`
`(event: FocusOutsideEvent) => void`
Function called when the focus is moved outside the component
`onInteractOutside`
`(event: InteractOutsideEvent) => void`
Function called when an interaction happens outside the component
`onOpenChange`
`(details: OpenChangeDetails) => void`
Callback to be invoked when the dialog is opened or closed
`onPointerDownOutside`
`(event: PointerDownOutsideEvent) => void`
Function called when the pointer is pressed down outside the component
`open`
`boolean`
Whether the dialog is open
`persistentElements`
`(() => Element | null)[]`
Returns the persistent elements that: - should not have pointer-events disabled - should not trigger the dismiss event
`present`
`boolean`
Whether the node is present (controlled by the user)
`restoreFocus`
`boolean`
Whether to restore focus to the element that had focus before the dialog was opened
`centered`
`'true' | 'false'`
The centered of the component
`as`
`React.ElementType`
The underlying element to render.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Data List](https://www.chakra-ui.com/docs/components/data-list)
[Next
\
Drawer](https://www.chakra-ui.com/docs/components/drawer) |
https://www.chakra-ui.com/docs/components/hover-card | 1. Components
2. Hover Card
# Hover Card
Used to display content when hovering over an element
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/hover-card)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-hover-card--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/hover-card.ts)[Ark](https://ark-ui.com/react/docs/components/hover-card)
PreviewCode
[@chakra\_ui]()
CU![](https://pbs.twimg.com/profile_images/1244925541448286208/rzylUjaf_400x400.jpg)
Chakra UI
The most powerful toolkit for building modern web applications.
2.5M Downloads
```
import { HStack, Icon, Link, Stack, Text } from "@chakra-ui/react"
import { Avatar } from "@/components/ui/avatar"
import {
HoverCardArrow,
HoverCardContent,
HoverCardRoot,
HoverCardTrigger,
} from "@/components/ui/hover-card"
import { LuLineChart } from "react-icons/lu"
const Demo = () => {
return (
<HoverCardRoot size="sm">
<HoverCardTrigger asChild>
<Link href="#">@chakra_ui</Link>
</HoverCardTrigger>
<HoverCardContent>
<HoverCardArrow />
<Stack gap="4" direction="row">
<Avatar
name="Chakra UI"
src="https://pbs.twimg.com/profile_images/1244925541448286208/rzylUjaf_400x400.jpg"
/>
<Stack gap="3">
<Stack gap="1">
<Text textStyle="sm" fontWeight="semibold">
Chakra UI
</Text>
<Text textStyle="sm" color="fg.muted">
The most powerful toolkit for building modern web applications.
</Text>
</Stack>
<HStack color="fg.subtle">
<Icon size="sm">
<LuLineChart />
</Icon>
<Text textStyle="xs">2.5M Downloads</Text>
</HStack>
</Stack>
</Stack>
</HoverCardContent>
</HoverCardRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `hover-card` snippet
```
npx @chakra-ui/cli snippet add hover-card
```
The snippet includes component compositions based on the `HoverCard` component.
## [Usage]()
```
import {
HoverCardArrow,
HoverCardContent,
HoverCardRoot,
HoverCardTrigger,
} from "@/components/ui/hover-card"
```
```
<HoverCardRoot>
<HoverCardTrigger />
<HoverCardContent>
<HoverCardArrow />
</HoverCardContent>
</HoverCardRoot>
```
## [Examples]()
### [Controlled]()
Use the `open` and `onOpenChange` to control the visibility of the hover card.
PreviewCode
[@chakra\_ui]()
**Chakra** is a Sanskrit word that means disk or wheel, referring to energy centers in the body
```
"use client"
import { Box, Link, Strong } from "@chakra-ui/react"
import {
HoverCardArrow,
HoverCardContent,
HoverCardRoot,
HoverCardTrigger,
} from "@/components/ui/hover-card"
import { useState } from "react"
const Demo = () => {
const [open, setOpen] = useState(false)
return (
<HoverCardRoot size="sm" open={open} onOpenChange={(e) => setOpen(e.open)}>
<HoverCardTrigger asChild>
<Link href="#">@chakra_ui</Link>
</HoverCardTrigger>
<HoverCardContent maxWidth="240px">
<HoverCardArrow />
<Box>
<Strong>Chakra</Strong> is a Sanskrit word that means disk or wheel,
referring to energy centers in the body
</Box>
</HoverCardContent>
</HoverCardRoot>
)
}
```
### [Delays]()
Control the open and close delays using the `openDelay` and `closeDelay` props.
PreviewCode
[@chakra\_ui]()
**Chakra** is a Sanskrit word that means disk or wheel, referring to energy centers in the body
```
import { Box, Link, Strong } from "@chakra-ui/react"
import {
HoverCardArrow,
HoverCardContent,
HoverCardRoot,
HoverCardTrigger,
} from "@/components/ui/hover-card"
const Demo = () => {
return (
<HoverCardRoot size="sm" openDelay={1000} closeDelay={100}>
<HoverCardTrigger asChild>
<Link href="#">@chakra_ui</Link>
</HoverCardTrigger>
<HoverCardContent maxWidth="240px">
<HoverCardArrow />
<Box>
<Strong>Chakra</Strong> is a Sanskrit word that means disk or wheel,
referring to energy centers in the body
</Box>
</HoverCardContent>
</HoverCardRoot>
)
}
```
### [Placement]()
Use the `positioning.placement` prop to configure the underlying `floating-ui` positioning logic.
PreviewCode
[@chakra\_ui]()
**Chakra** is a Sanskrit word that means disk or wheel, referring to energy centers in the body
```
import { Box, Link, Strong } from "@chakra-ui/react"
import {
HoverCardArrow,
HoverCardContent,
HoverCardRoot,
HoverCardTrigger,
} from "@/components/ui/hover-card"
const Demo = () => {
return (
<HoverCardRoot size="sm" positioning={{ placement: "top" }}>
<HoverCardTrigger asChild>
<Link href="#">@chakra_ui</Link>
</HoverCardTrigger>
<HoverCardContent maxWidth="240px">
<HoverCardArrow />
<Box>
<Strong>Chakra</Strong> is a Sanskrit word that means disk or wheel,
referring to energy centers in the body
</Box>
</HoverCardContent>
</HoverCardRoot>
)
}
```
## [Accessibility]()
HoverCard should be used solely for supplementary information that is not essential for understanding the context.
It is inaccessible to screen readers and cannot be activated via keyboard, so avoid placing crucial content within it.
## [Props]()
PropDefaultType`closeDelay``'300'`
`number`
The duration from when the mouse leaves the trigger or content until the hover card closes.
`lazyMount``false`
`boolean`
Whether to enable lazy mounting
`openDelay``'700'`
`number`
The duration from when the mouse enters the trigger until the hover card opens.
`unmountOnExit``false`
`boolean`
Whether to unmount on exit.
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
`defaultOpen`
`boolean`
The initial open state of the hover card when it is first rendered. Use when you do not need to control its open state.
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ trigger: string content: string positioner: string arrow: string }>`
The ids of the elements in the popover. Useful for composition.
`immediate`
`boolean`
Whether to synchronize the present change immediately or defer it to the next frame
`onExitComplete`
`() => void`
Function called when the animation ends in the closed state
`onOpenChange`
`(details: OpenChangeDetails) => void`
Function called when the hover card opens or closes.
`open`
`boolean`
Whether the hover card is open
`positioning`
`PositioningOptions`
The user provided options used to position the popover content
`present`
`boolean`
Whether the node is present (controlled by the user)
`as`
`React.ElementType`
The underlying element to render.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
File Upload](https://www.chakra-ui.com/docs/components/file-upload)
[Next
\
Icon](https://www.chakra-ui.com/docs/components/icon) |
https://www.chakra-ui.com/docs/components/empty-state | 1. Components
2. Empty State
# Empty State
Used to indicate when a resource is empty or unavailable.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/empty-state)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-empty-state--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/empty-state.ts)
PreviewCode
### Your cart is empty
Explore our products and add items to your cart
```
import { EmptyState } from "@/components/ui/empty-state"
import { LuShoppingCart } from "react-icons/lu"
const Demo = () => {
return (
<EmptyState
icon={<LuShoppingCart />}
title="Your cart is empty"
description="Explore our products and add items to your cart"
/>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `empty-state` snippet
```
npx @chakra-ui/cli snippet add empty-state
```
The snippet includes a closed component composition for the `EmptyState` component.
## [Usage]()
```
import { EmptyState } from "@/components/ui/empty-state"
```
```
<EmptyState />
```
## [Examples]()
### [Action]()
Here's an example of an empty state with an action button.
PreviewCode
### Start adding tokens
Add a new design token to get started
Create tokenImport
```
import { Group } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import { EmptyState } from "@/components/ui/empty-state"
import { HiColorSwatch } from "react-icons/hi"
const Demo = () => {
return (
<EmptyState
icon={<HiColorSwatch />}
title="Start adding tokens"
description="Add a new design token to get started"
>
<Group>
<Button>Create token</Button>
<Button variant="outline">Import</Button>
</Group>
</EmptyState>
)
}
```
### [List]()
Here's an example of an empty state with a list.
PreviewCode
### No results found
Try adjusting your search
- Try removing filters
- Try different keywords
```
import { List } from "@chakra-ui/react"
import { EmptyState } from "@/components/ui/empty-state"
import { HiColorSwatch } from "react-icons/hi"
const Demo = () => {
return (
<EmptyState
icon={<HiColorSwatch />}
title="No results found"
description="Try adjusting your search"
>
<List.Root variant="marker">
<List.Item>Try removing filters</List.Item>
<List.Item>Try different keywords</List.Item>
</List.Root>
</EmptyState>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'md' | 'lg'`
The size of the component
[Previous
\
Editable](https://www.chakra-ui.com/docs/components/editable)
[Next
\
Field](https://www.chakra-ui.com/docs/components/field) |
https://www.chakra-ui.com/docs/components/image | 1. Components
2. Image
# Image
Used to display images
PreviewCode
![Dan Abramov](https://bit.ly/dan-abramov)
```
import { Image } from "@chakra-ui/react"
export const ImageBasic = () => (
<Image rounded="md" src="https://bit.ly/dan-abramov" alt="Dan Abramov" />
)
```
## [Usage]()
```
import { Image } from "@chakra-ui/react"
```
```
<Image src="..." />
```
## [Examples]()
### [Height]()
Use the `height` prop to change the height of the image component.
PreviewCode
![](https://images.unsplash.com/flagged/photo-1572491259205-506c425b45c3)
```
import { Image } from "@chakra-ui/react"
const Demo = () => {
return (
<Image
height="200px"
src="https://images.unsplash.com/flagged/photo-1572491259205-506c425b45c3"
/>
)
}
```
### [Circular]()
Here's an example of how to render a circular image.
PreviewCode
![Naruto Uzumaki](https://bit.ly/naruto-sage)
```
import { Image } from "@chakra-ui/react"
export const ImageCircular = () => (
<Image
src="https://bit.ly/naruto-sage"
boxSize="150px"
borderRadius="full"
fit="cover"
alt="Naruto Uzumaki"
/>
)
```
### [Aspect Ratio]()
Use the `aspectRatio` prop to change the aspect ratio of the image component.
PreviewCode
![Naruto vs Sasuke](https://wallpapercave.com/uwp/uwp4261619.png)
```
import { Image } from "@chakra-ui/react"
const Demo = () => {
return (
<Image
src="https://wallpapercave.com/uwp/uwp4261619.png"
alt="Naruto vs Sasuke"
aspectRatio={4 / 3}
width="300px"
/>
)
}
```
### [Fit]()
By default, the image applies `object-fit: cover`. Use the `fit` prop to change the fit of the image component.
PreviewCode
![](https://bit.ly/dan-abramov)
```
import { Image } from "@chakra-ui/react"
export const ImageWithFit = () => (
<Image
border="1px solid red"
rounded="md"
h="200px"
w="300px"
fit="contain"
src="https://bit.ly/dan-abramov"
/>
)
```
### [Next.js Image]()
Use the `asChild` prop to render the image as a child of the `Image` component.
```
// import NextImage from "next/image"
<Image asChild>
<NextImage src="..." alt="..." />
</Image>
```
## [Props]()
The `Image` component supports all native props for the `img` element.
[Previous
\
Icon Button](https://www.chakra-ui.com/docs/components/icon-button)
[Next
\
Input](https://www.chakra-ui.com/docs/components/input) |
https://www.chakra-ui.com/docs/components/icon | 1. Components
2. Icon
# Icon
Used to display an svg icon
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/icon)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-icon--basic)
PreviewCode
```
import { Icon } from "@chakra-ui/react"
import { HiHeart } from "react-icons/hi"
export const IconBasic = () => (
<Icon fontSize="2xl" color="pink.700">
<HiHeart />
</Icon>
)
```
## [Usage]()
```
import { Icon } from "@chakra-ui/react"
```
```
<Icon />
```
warning
Chakra doesn't provide any icons out of the box. Use popular icon libraries like [react-icons](https://react-icons.github.io/react-icons/) or [lucide-react](https://lucide.dev/react/)
## [Examples]()
### [React Icons]()
Integrate with popular react icon libraries like `react-icons`
PreviewCode
```
import { Icon } from "@chakra-ui/react"
import { Md3dRotation } from "react-icons/md"
export const IconWithReactIcon = () => (
<Icon fontSize="40px" color="tomato">
<Md3dRotation />
</Icon>
)
```
### [Custom svg]()
Use the `asChild` prop to render custom svg icons within the `Icon` component
PreviewCode
```
import { Icon } from "@chakra-ui/react"
const Demo = () => {
return (
<Icon fontSize="40px" color="red.500">
<svg viewBox="0 0 32 32">
<g fill="currentColor">
<path d="M16,11.5a3,3,0,1,0-3-3A3,3,0,0,0,16,11.5Z" />
<path d="M16.868.044A8.579,8.579,0,0,0,16,0a15.99,15.99,0,0,0-.868,31.956A8.579,8.579,0,0,0,16,32,15.99,15.99,0,0,0,16.868.044ZM16,26.5a3,3,0,1,1,3-3A3,3,0,0,1,16,26.5ZM16,15A8.483,8.483,0,0,0,8.788,27.977,13.986,13.986,0,0,1,16,2a6.5,6.5,0,0,1,0,13Z" />
</g>
</svg>
</Icon>
)
}
```
### [Create Icon]()
Use the `createIcon` utility to create custom icons
PreviewCode
```
"use client"
import { createIcon } from "@chakra-ui/react"
const HeartIcon = createIcon({
displayName: "HeartIcon",
path: (
<>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
fill="currentColor"
d="M19.5 13.572l-7.5 7.428l-7.5 -7.428m0 0a5 5 0 1 1 7.5 -6.566a5 5 0 1 1 7.5 6.572"
/>
</>
),
})
export const IconWithCreateIcon = () => (
<HeartIcon boxSize="40px" color="blue.400" />
)
```
[Previous
\
Hover Card](https://www.chakra-ui.com/docs/components/hover-card)
[Next
\
Icon Button](https://www.chakra-ui.com/docs/components/icon-button) |
https://www.chakra-ui.com/docs/components/icon-button | 1. Components
2. Icon Button
# Icon Button
Used to render an icon within a button
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/button)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-icon-button--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/button.ts)
PreviewCode
```
import { IconButton } from "@chakra-ui/react"
import { LuSearch } from "react-icons/lu"
const Demo = () => {
return (
<IconButton aria-label="Search database">
<LuSearch />
</IconButton>
)
}
```
## [Usage]()
```
import { IconButton } from "@chakra-ui/react"
```
```
<IconButton aria-label="Search database">
<LuSearch />
</IconButton>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the button.
PreviewCode
xs
sm
md
lg
```
import { For, HStack, IconButton, Text, VStack } from "@chakra-ui/react"
import { LuPhone } from "react-icons/lu"
const Demo = () => {
return (
<HStack wrap="wrap" gap="8">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<VStack key={size}>
<IconButton
aria-label="Search database"
variant="outline"
size={size}
>
<LuPhone />
</IconButton>
<Text textStyle="sm">{size}</Text>
</VStack>
)}
</For>
</HStack>
)
}
```
### [Variants]()
Use the `variant` prop to change its visual style
PreviewCode
solid
subtle
surface
outline
ghost
```
import { For, HStack, IconButton, Text, VStack } from "@chakra-ui/react"
import { LuVoicemail } from "react-icons/lu"
const Demo = () => {
return (
<HStack wrap="wrap" gap="8">
<For each={["solid", "subtle", "surface", "outline", "ghost"]}>
{(variant) => (
<VStack key={variant}>
<IconButton
aria-label="Call support"
key={variant}
variant={variant}
>
<LuVoicemail />
</IconButton>
<Text textStyle="sm">{variant}</Text>
</VStack>
)}
</For>
</HStack>
)
}
```
### [Color]()
Use the `colorPalette` prop to change the color of the button
PreviewCode
```
import { For, HStack, IconButton } from "@chakra-ui/react"
import { colorPalettes } from "compositions/lib/color-palettes"
import { LuSearch } from "react-icons/lu"
const Demo = () => {
return (
<HStack wrap="wrap">
<For each={colorPalettes}>
{(c) => (
<IconButton aria-label="Search database" key={c} colorPalette={c}>
<LuSearch />
</IconButton>
)}
</For>
</HStack>
)
}
```
### [Rounded]()
Set `rounded="full"` to make the button fully rounded
PreviewCode
```
import { IconButton } from "@chakra-ui/react"
import { LuVoicemail } from "react-icons/lu"
const Demo = () => {
return (
<IconButton aria-label="Call support" rounded="full">
<LuVoicemail />
</IconButton>
)
}
```
## [Props]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
`variant``'solid'`
`'solid' | 'subtle' | 'surface' | 'outline' | 'ghost' | 'plain'`
The variant of the component
[Previous
\
Icon](https://www.chakra-ui.com/docs/components/icon)
[Next
\
Image](https://www.chakra-ui.com/docs/components/image) |
https://www.chakra-ui.com/docs/components/menu | 1. Components
2. Menu
# Menu
Used to create an accessible dropdown menu
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/menu)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-menu--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/menu.ts)[Ark](https://ark-ui.com/react/docs/components/menu)
PreviewCode
Open
New Text File
New File...
New Window
Open File...
Export
```
import { Button } from "@/components/ui/button"
import {
MenuContent,
MenuItem,
MenuRoot,
MenuTrigger,
} from "@/components/ui/menu"
const Demo = () => {
return (
<MenuRoot>
<MenuTrigger asChild>
<Button variant="outline" size="sm">
Open
</Button>
</MenuTrigger>
<MenuContent>
<MenuItem value="new-txt">New Text File</MenuItem>
<MenuItem value="new-file">New File...</MenuItem>
<MenuItem value="new-win">New Window</MenuItem>
<MenuItem value="open-file">Open File...</MenuItem>
<MenuItem value="export">Export</MenuItem>
</MenuContent>
</MenuRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `menu` snippet
```
npx @chakra-ui/cli snippet add menu
```
The snippet includes a closed component composition for the `Menu` component.
## [Usage]()
```
import {
MenuContent,
MenuItem,
MenuRoot,
MenuTrigger,
} from "@/components/ui/menu"
```
```
<MenuRoot>
<MenuTrigger />
<MenuContent>
<MenuItem value="..." />
</MenuContent>
</MenuRoot>
```
## [Examples]()
### [Command]()
Use the `MenuItemCommand` component to display a command in the menu.
PreviewCode
Open
New Text File `⌘E`
New File... `⌘N`
New Window `⌘⇧N`
Open File... `⌘O`
Export `⌘S`
```
import { Button } from "@/components/ui/button"
import {
MenuContent,
MenuItem,
MenuItemCommand,
MenuRoot,
MenuTrigger,
} from "@/components/ui/menu"
const Demo = () => {
return (
<MenuRoot>
<MenuTrigger asChild>
<Button variant="outline" size="sm">
Open
</Button>
</MenuTrigger>
<MenuContent>
<MenuItem value="new-txt-a">
New Text File <MenuItemCommand>⌘E</MenuItemCommand>
</MenuItem>
<MenuItem value="new-file-a">
New File... <MenuItemCommand>⌘N</MenuItemCommand>
</MenuItem>
<MenuItem value="new-win-a">
New Window <MenuItemCommand>⌘⇧N</MenuItemCommand>
</MenuItem>
<MenuItem value="open-file-a">
Open File... <MenuItemCommand>⌘O</MenuItemCommand>
</MenuItem>
<MenuItem value="export-a">
Export <MenuItemCommand>⌘S</MenuItemCommand>
</MenuItem>
</MenuContent>
</MenuRoot>
)
}
```
### [Context menu]()
Use the `MenuContextTrigger` component to create a context menu.
PreviewCode
Right click here
New Text File
New File...
New Window
Open File...
Export
```
import { Center } from "@chakra-ui/react"
import {
MenuContent,
MenuContextTrigger,
MenuItem,
MenuRoot,
} from "@/components/ui/menu"
const Demo = () => {
return (
<MenuRoot>
<MenuContextTrigger w="full">
<Center
width="full"
height="40"
userSelect="none"
borderWidth="2px"
borderStyle="dashed"
rounded="lg"
padding="4"
>
Right click here
</Center>
</MenuContextTrigger>
<MenuContent>
<MenuItem value="new-txt">New Text File</MenuItem>
<MenuItem value="new-file">New File...</MenuItem>
<MenuItem value="new-win">New Window</MenuItem>
<MenuItem value="open-file">Open File...</MenuItem>
<MenuItem value="export">Export</MenuItem>
</MenuContent>
</MenuRoot>
)
}
```
### [Group]()
Use the `MenuItemGroup` component to group related menu items.
PreviewCode
Edit
Styles
Bold
Underline
* * *
Align
Left
Middle
Right
```
import { Button } from "@/components/ui/button"
import {
MenuContent,
MenuItem,
MenuItemGroup,
MenuRoot,
MenuSeparator,
MenuTrigger,
} from "@/components/ui/menu"
const Demo = () => {
return (
<MenuRoot>
<MenuTrigger asChild>
<Button variant="outline">Edit</Button>
</MenuTrigger>
<MenuContent>
<MenuItemGroup title="Styles">
<MenuItem value="bold">Bold</MenuItem>
<MenuItem value="underline">Underline</MenuItem>
</MenuItemGroup>
<MenuSeparator />
<MenuItemGroup title="Align">
<MenuItem value="left">Left</MenuItem>
<MenuItem value="middle">Middle</MenuItem>
<MenuItem value="right">Right</MenuItem>
</MenuItemGroup>
</MenuContent>
</MenuRoot>
)
}
```
### [Danger Item]()
Here's an example of how to style a menu item that is used to delete an item.
PreviewCode
Open Menu
Rename
Export
Delete...
```
import { Button } from "@/components/ui/button"
import {
MenuContent,
MenuItem,
MenuRoot,
MenuTrigger,
} from "@/components/ui/menu"
const Demo = () => {
return (
<MenuRoot>
<MenuTrigger asChild>
<Button variant="outline" size="sm">
Open Menu
</Button>
</MenuTrigger>
<MenuContent>
<MenuItem value="rename">Rename</MenuItem>
<MenuItem value="export">Export</MenuItem>
<MenuItem
value="delete"
color="fg.error"
_hover={{ bg: "bg.error", color: "fg.error" }}
>
Delete...
</MenuItem>
</MenuContent>
</MenuRoot>
)
}
```
### [Submenu]()
Here's an example of how to create a submenu.
PreviewCode
Open
New Text File
New File...
Open Recent
Panda
Ark UI
Chakra v3
Open File...
Export
```
import { Button } from "@/components/ui/button"
import {
MenuContent,
MenuItem,
MenuRoot,
MenuTrigger,
MenuTriggerItem,
} from "@/components/ui/menu"
const Demo = () => {
return (
<MenuRoot>
<MenuTrigger asChild>
<Button variant="outline" size="sm">
Open
</Button>
</MenuTrigger>
<MenuContent>
<MenuItem value="new-txt">New Text File</MenuItem>
<MenuItem value="new-file">New File...</MenuItem>
<MenuRoot positioning={{ placement: "right-start", gutter: 2 }}>
<MenuTriggerItem value="open-recent">Open Recent</MenuTriggerItem>
<MenuContent>
<MenuItem value="panda">Panda</MenuItem>
<MenuItem value="ark">Ark UI</MenuItem>
<MenuItem value="chakra">Chakra v3</MenuItem>
</MenuContent>
</MenuRoot>
<MenuItem value="open-file">Open File...</MenuItem>
<MenuItem value="export">Export</MenuItem>
</MenuContent>
</MenuRoot>
)
}
```
### [Links]()
Pass the `asChild` prop to the `MenuItem` component to render a link.
PreviewCode
Select Anime
[Naruto](https://www.crunchyroll.com/naruto)[One Piece](https://www.crunchyroll.com/one-piece)[Attack on Titan](https://www.crunchyroll.com/attack-on-titan)
```
import { Button } from "@/components/ui/button"
import {
MenuContent,
MenuItem,
MenuRoot,
MenuTrigger,
} from "@/components/ui/menu"
const Demo = () => {
return (
<MenuRoot>
<MenuTrigger asChild>
<Button size="sm" variant="outline">
Select Anime
</Button>
</MenuTrigger>
<MenuContent>
<MenuItem asChild value="naruto">
<a
href="https://www.crunchyroll.com/naruto"
target="_blank"
rel="noreferrer"
>
Naruto
</a>
</MenuItem>
<MenuItem asChild value="one-piece">
<a
href="https://www.crunchyroll.com/one-piece"
target="_blank"
rel="noreferrer"
>
One Piece
</a>
</MenuItem>
<MenuItem asChild value="attack-on-titan">
<a
href="https://www.crunchyroll.com/attack-on-titan"
target="_blank"
rel="noreferrer"
>
Attack on Titan
</a>
</MenuItem>
</MenuContent>
</MenuRoot>
)
}
```
### [With Radio]()
Here's an example of how to create a menu with radio.
PreviewCode
Sort
Ascending
Descending
```
"use client"
import { Button } from "@/components/ui/button"
import {
MenuContent,
MenuRadioItem,
MenuRadioItemGroup,
MenuRoot,
MenuTrigger,
} from "@/components/ui/menu"
import { useState } from "react"
import { HiSortAscending } from "react-icons/hi"
const Demo = () => {
const [value, setValue] = useState("asc")
return (
<MenuRoot>
<MenuTrigger asChild>
<Button variant="outline" size="sm">
<HiSortAscending /> Sort
</Button>
</MenuTrigger>
<MenuContent minW="10rem">
<MenuRadioItemGroup
value={value}
onValueChange={(e) => setValue(e.value)}
>
<MenuRadioItem value="asc">Ascending</MenuRadioItem>
<MenuRadioItem value="desc">Descending</MenuRadioItem>
</MenuRadioItemGroup>
</MenuContent>
</MenuRoot>
)
}
```
### [Icon and Command]()
Compose the menu to include icons and commands.
PreviewCode
Edit
Cut
`⌘X`
Copy
`⌘C`
Paste
`⌘V`
```
import { Box } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
MenuContent,
MenuItem,
MenuItemCommand,
MenuRoot,
MenuTrigger,
} from "@/components/ui/menu"
import { LuClipboardPaste, LuCopy, LuScissors } from "react-icons/lu"
const Demo = () => {
return (
<MenuRoot>
<MenuTrigger asChild>
<Button variant="outline">Edit</Button>
</MenuTrigger>
<MenuContent>
<MenuItem value="cut" valueText="cut">
<LuScissors />
<Box flex="1">Cut</Box>
<MenuItemCommand>⌘X</MenuItemCommand>
</MenuItem>
<MenuItem value="copy" valueText="copy">
<LuCopy />
<Box flex="1">Copy</Box>
<MenuItemCommand>⌘C</MenuItemCommand>
</MenuItem>
<MenuItem value="paste" valueText="paste">
<LuClipboardPaste />
<Box flex="1">Paste</Box>
<MenuItemCommand>⌘V</MenuItemCommand>
</MenuItem>
</MenuContent>
</MenuRoot>
)
}
```
### [Placement]()
Use the `positioning.placement` prop to control the placement of the menu.
PreviewCode
Open
New Text File
New File...
New Window
Open File...
Export
```
import { Button } from "@/components/ui/button"
import {
MenuContent,
MenuItem,
MenuRoot,
MenuTrigger,
} from "@/components/ui/menu"
const Demo = () => {
return (
<MenuRoot positioning={{ placement: "right-start" }}>
<MenuTrigger asChild>
<Button variant="outline" size="sm">
Open
</Button>
</MenuTrigger>
<MenuContent>
<MenuItem value="new-txt">New Text File</MenuItem>
<MenuItem value="new-file">New File...</MenuItem>
<MenuItem value="new-win">New Window</MenuItem>
<MenuItem value="open-file">Open File...</MenuItem>
<MenuItem value="export">Export</MenuItem>
</MenuContent>
</MenuRoot>
)
}
```
### [Mixed Layout]()
Here's an example of how to create a mixed layout of menu items. In this layout, the top horizontal menu includes common menu items.
PreviewCode
Open
Cut
Copy
Paste
Look Up
Translate
Share
```
import { Box, Group } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
MenuContent,
MenuItem,
MenuRoot,
MenuTrigger,
} from "@/components/ui/menu"
import {
LuClipboard,
LuCopy,
LuFileSearch,
LuMessageSquare,
LuScissors,
LuShare,
} from "react-icons/lu"
const horizontalMenuItems = [
{ label: "Cut", value: "cut", icon: <LuScissors /> },
{ label: "Copy", value: "copy", icon: <LuCopy /> },
{ label: "Paste", value: "paste", icon: <LuClipboard /> },
]
const verticalMenuItems = [
{ label: "Look Up", value: "look-up", icon: <LuFileSearch /> },
{ label: "Translate", value: "translate", icon: <LuMessageSquare /> },
{ label: "Share", value: "share", icon: <LuShare /> },
]
const Demo = () => {
return (
<MenuRoot>
<MenuTrigger asChild>
<Button variant="outline" size="sm">
Open
</Button>
</MenuTrigger>
<MenuContent>
<Group grow gap="0">
{horizontalMenuItems.map((item) => (
<MenuItem
key={item.value}
value={item.value}
width="14"
gap="1"
flexDirection="column"
justifyContent="center"
>
{item.icon}
{item.label}
</MenuItem>
))}
</Group>
{verticalMenuItems.map((item) => (
<MenuItem key={item.value} value={item.value}>
<Box flex="1">{item.label}</Box>
{item.icon}
</MenuItem>
))}
</MenuContent>
</MenuRoot>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`closeOnSelect``true`
`boolean`
Whether to close the menu when an option is selected
`composite``true`
`boolean`
Whether the menu is a composed with other composite widgets like a combobox or tabs
`lazyMount``false`
`boolean`
Whether to enable lazy mounting
`loopFocus``false`
`boolean`
Whether to loop the keyboard navigation.
`typeahead``true`
`boolean`
Whether the pressing printable characters should trigger typeahead navigation
`unmountOnExit``false`
`boolean`
Whether to unmount on exit.
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`variant``'subtle'`
`'subtle' | 'solid'`
The variant of the component
`size``'md'`
`'sm' | 'md'`
The size of the component
`anchorPoint`
`Point`
The positioning point for the menu. Can be set by the context menu trigger or the button trigger.
`aria-label`
`string`
The accessibility label for the menu
`defaultOpen`
`boolean`
The initial open state of the menu when it is first rendered. Use when you do not need to control its open state.
`highlightedValue`
`string`
The value of the highlighted menu item.
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ trigger: string contextTrigger: string content: string groupLabel(id: string): string group(id: string): string positioner: string arrow: string }>`
The ids of the elements in the menu. Useful for composition.
`immediate`
`boolean`
Whether to synchronize the present change immediately or defer it to the next frame
`onEscapeKeyDown`
`(event: KeyboardEvent) => void`
Function called when the escape key is pressed
`onExitComplete`
`() => void`
Function called when the animation ends in the closed state
`onFocusOutside`
`(event: FocusOutsideEvent) => void`
Function called when the focus is moved outside the component
`onHighlightChange`
`(details: HighlightChangeDetails) => void`
Function called when the highlighted menu item changes.
`onInteractOutside`
`(event: InteractOutsideEvent) => void`
Function called when an interaction happens outside the component
`onOpenChange`
`(details: OpenChangeDetails) => void`
Function called when the menu opens or closes
`onPointerDownOutside`
`(event: PointerDownOutsideEvent) => void`
Function called when the pointer is pressed down outside the component
`onSelect`
`(details: SelectionDetails) => void`
Function called when a menu item is selected.
`open`
`boolean`
Whether the menu is open
`positioning`
`PositioningOptions`
The options used to dynamically position the menu
`present`
`boolean`
Whether the node is present (controlled by the user)
`as`
`React.ElementType`
The underlying element to render.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`unstyled`
`boolean`
Whether to remove the component's style.
### [Item]()
PropDefaultType`value`*
`string`
The unique value of the menu item option.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`closeOnSelect`
`boolean`
Whether the menu should be closed when the option is selected.
`disabled`
`boolean`
Whether the menu item is disabled
`valueText`
`string`
The textual value of the option. Used in typeahead navigation of the menu. If not provided, the text content of the menu item will be used.
[Previous
\
Input](https://www.chakra-ui.com/docs/components/input)
[Next
\
Number Input](https://www.chakra-ui.com/docs/components/number-input) |
https://www.chakra-ui.com/docs/components/field | 1. Components
2. Field
# Field
Used to add labels, help text, and error messages to form fields.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/field)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-field--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/field.ts)[Ark](https://ark-ui.com/react/docs/components/field)
PreviewCode
Email
```
import { Input } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<Field label="Email">
<Input placeholder="[email protected]" />
</Field>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `field` snippet
```
npx @chakra-ui/cli snippet add field
```
The snippet includes a closed component composition for the `Field` component.
## [Usage]()
```
import { Field } from "@/components/ui/field"
```
```
<Field>
<Input />
</Field>
```
## [Examples]()
### [Error Text]()
Use the `invalid` and `errorText` to indicate that the field is invalid.
PreviewCode
EmailThis is an error text
```
import { Input } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<Field label="Email" invalid errorText="This is an error text">
<Input placeholder="[email protected]" />
</Field>
)
}
```
### [Helper Text]()
Use the `helperText` prop to add helper text to the field.
PreviewCode
EmailThis is a helper text
```
import { Input } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<Field label="Email" helperText="This is a helper text">
<Input placeholder="[email protected]" />
</Field>
)
}
```
### [Horizontal]()
Use the `orientation="horizontal"` prop to align the label and input horizontally.
PreviewCode
Name
Email
Hide email
```
import { Input, Stack } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
import { Switch } from "@/components/ui/switch"
const Demo = () => {
return (
<Stack gap="8" maxW="sm" css={{ "--field-label-width": "96px" }}>
<Field orientation="horizontal" label="Name">
<Input placeholder="John Doe" flex="1" />
</Field>
<Field orientation="horizontal" label="Email">
<Input placeholder="[email protected]" flex="1" />
</Field>
<Field orientation="horizontal" label="Hide email">
<Switch />
</Field>
</Stack>
)
}
```
### [Disabled]()
Use the `disabled` prop to disable the field.
PreviewCode
Email
```
import { Input } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<Field label="Email" disabled>
<Input placeholder="[email protected]" />
</Field>
)
}
```
### [Textarea]()
Here's how to use the field component with a textarea.
PreviewCode
Email
```
import { Textarea } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<Field label="Email">
<Textarea placeholder="Email" />
</Field>
)
}
```
### [Native Select]()
Here's how to use the field component with a native select.
PreviewCode
Email
Option 1Option 2Option 3
```
import { Field } from "@/components/ui/field"
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
const Demo = () => {
return (
<Field label="Email">
<NativeSelectRoot>
<NativeSelectField items={["Option 1", "Option 2", "Option 3"]} />
</NativeSelectRoot>
</Field>
)
}
```
### [Required]()
Use the `required` prop to indicate that the field is required.
PreviewCode
Email*
```
import { Input } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<Field label="Email" required>
<Input placeholder="[email protected]" />
</Field>
)
}
```
### [Optional]()
Use the `optionalText` prop to indicate that the field is optional.
PreviewCode
EmailOptional
```
import { Badge, Input } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<Field
label="Email"
optionalText={
<Badge size="xs" variant="surface">
Optional
</Badge>
}
>
<Input placeholder="[email protected]" />
</Field>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`disabled`
`boolean`
Indicates whether the field is disabled.
`ids`
`ElementIds`
The ids of the field parts.
`invalid`
`boolean`
Indicates whether the field is invalid.
`readOnly`
`boolean`
Indicates whether the field is read-only.
`required`
`boolean`
Indicates whether the field is required.
`as`
`React.ElementType`
The underlying element to render.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Empty State](https://www.chakra-ui.com/docs/components/empty-state)
[Next
\
Fieldset](https://www.chakra-ui.com/docs/components/fieldset) |
https://www.chakra-ui.com/docs/components/input | 1. Components
2. Input
# Input
Used to get user input in a text field.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/input)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-input--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/input.ts)
PreviewCode
```
import { Input } from "@chakra-ui/react"
const Demo = () => {
return <Input placeholder="Enter your email" />
}
```
## [Usage]()
```
import { Input } from "@chakra-ui/react"
```
```
<Input placeholder="..." />
```
## [Examples]()
### [Variants]()
Use the `variant` prop to change the visual style of the input.
PreviewCode
```
import { Input, Stack } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack gap="4">
<Input placeholder="Subtle" variant="subtle" />
<Input placeholder="Outline" variant="outline" />
<Input placeholder="Flushed" variant="flushed" />
</Stack>
)
}
```
### [Sizes]()
Use the `size` prop to change the size of the input.
PreviewCode
```
import { Input, Stack } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack gap="4">
<Input placeholder="size (xs)" size="xs" />
<Input placeholder="size (sm)" size="sm" />
<Input placeholder="size (md)" size="md" />
<Input placeholder="size (lg)" size="lg" />
</Stack>
)
}
```
### [Helper Text]()
Pair the input with the `Field` component to add helper text.
PreviewCode
Email\*We'll never share your email.
```
import { Input } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<Field label="Email" required helperText="We'll never share your email.">
<Input placeholder="Enter your email" />
</Field>
)
}
```
### [Error Text]()
Pair the input with the `Field` component to add error text.
PreviewCode
EmailThis field is required
```
import { Input } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<Field invalid label="Email" errorText="This field is required">
<Input placeholder="Enter your email" />
</Field>
)
}
```
### [Field]()
Compose the input with the `Field` component to add a label, helper text, and error text.
PreviewCode
Email*
Email*
```
import { HStack, Input } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<HStack gap="10" width="full">
<Field label="Email" required>
<Input placeholder="[email protected]" variant="subtle" />
</Field>
<Field label="Email" required>
<Input placeholder="[email protected]" variant="outline" />
</Field>
</HStack>
)
}
```
### [Hook Form]()
Here's an example of how to integrate the input with `react-hook-form`.
PreviewCode
First name
Last name
Submit
```
"use client"
import { Button, Input, Stack } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
import { useForm } from "react-hook-form"
interface FormValues {
firstName: string
lastName: string
}
const Demo = () => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm<FormValues>()
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Stack gap="4" align="flex-start" maxW="sm">
<Field
label="First name"
invalid={!!errors.firstName}
errorText={errors.firstName?.message}
>
<Input
{...register("firstName", { required: "First name is required" })}
/>
</Field>
<Field
label="Last name"
invalid={!!errors.lastName}
errorText={errors.lastName?.message}
>
<Input
{...register("lastName", { required: "Last name is required" })}
/>
</Field>
<Button type="submit">Submit</Button>
</Stack>
</form>
)
}
```
### [Left and Right Element]()
Pair the input with the `InputElement` component to add an element to the left or right of the input.
PreviewCode
https://
```
import { HStack, Input } from "@chakra-ui/react"
import { InputGroup } from "@/components/ui/input-group"
import { LuUser } from "react-icons/lu"
const Demo = () => {
return (
<HStack gap="10" width="full">
<InputGroup flex="1" startElement={<LuUser />}>
<Input placeholder="Username" />
</InputGroup>
<InputGroup flex="1" startElement="https://">
<Input ps="4.75em" placeholder="yoursite.com" />
</InputGroup>
</HStack>
)
}
```
PreviewCode
`⌘K`
https://
.com.org.net
```
import { HStack, Input, Kbd } from "@chakra-ui/react"
import { InputGroup } from "@/components/ui/input-group"
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
import { LuSearch } from "react-icons/lu"
const DomainSelect = () => (
<NativeSelectRoot size="xs" variant="plain" width="auto" me="-1">
<NativeSelectField defaultValue=".com" fontSize="sm">
<option value=".com">.com</option>
<option value=".org">.org</option>
<option value=".net">.net</option>
</NativeSelectField>
</NativeSelectRoot>
)
const Demo = () => {
return (
<HStack gap="10" width="full">
<InputGroup
flex="1"
startElement={<LuSearch />}
endElement={<Kbd>⌘K</Kbd>}
>
<Input placeholder="Search contacts" />
</InputGroup>
<InputGroup
flex="1"
startElement="https://"
endElement={<DomainSelect />}
>
<Input ps="4.75em" pe="0" placeholder="yoursite.com" />
</InputGroup>
</HStack>
)
}
```
### [Addon]()
Use the `InputAddon` and `Group` components to add an addon to the input.
PreviewCode
https://
.com
```
import { Group, Input, InputAddon, Stack } from "@chakra-ui/react"
export const InputWithAddon = () => (
<Stack gap="10">
<Group attached>
<InputAddon>https://</InputAddon>
<Input placeholder="Phone number..." />
</Group>
<Group attached>
<Input placeholder="Placeholder" />
<InputAddon>.com</InputAddon>
</Group>
</Stack>
)
```
### [Disabled]()
Use the `disabled` prop to disable the input.
PreviewCode
```
import { Input } from "@chakra-ui/react"
const Demo = () => {
return <Input disabled placeholder="disabled" />
}
```
### [Placeholder Style]()
Use the `_placeholder` prop to style the placeholder text.
PreviewCode
```
import { Input } from "@chakra-ui/react"
const Demo = () => {
return (
<Input
color="teal"
placeholder="custom placeholder"
_placeholder={{ color: "inherit" }}
/>
)
}
```
### [Floating Label]()
Here's an example of how to build a floating label to the input.
PreviewCode
Email
```
import { Box, Field, Input, defineStyle } from "@chakra-ui/react"
const Demo = () => {
return (
<Field.Root>
<Box pos="relative" w="full">
<Input className="peer" placeholder="" />
<Field.Label css={floatingStyles}>Email</Field.Label>
</Box>
</Field.Root>
)
}
const floatingStyles = defineStyle({
pos: "absolute",
bg: "bg",
px: "0.5",
top: "-3",
insetStart: "2",
fontWeight: "normal",
pointerEvents: "none",
transition: "position",
_peerPlaceholderShown: {
color: "fg.muted",
top: "2.5",
insetStart: "3",
},
_peerFocusVisible: {
color: "fg",
top: "-3",
insetStart: "2",
},
})
```
### [Mask]()
Here's an example of using the `use-mask-input` library to mask the input shape.
PreviewCode
```
"use client"
import { Input } from "@chakra-ui/react"
import { withMask } from "use-mask-input"
const Demo = () => {
return (
<Input placeholder="(99) 99999-9999" ref={withMask("(99) 99999-9999")} />
)
}
```
## [Props]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'lg' | 'md' | 'sm' | 'xs'`
The size of the component
`variant``'outline'`
`'outline' | 'filled' | 'flushed'`
The variant of the component
[Previous
\
Image](https://www.chakra-ui.com/docs/components/image)
[Next
\
Menu](https://www.chakra-ui.com/docs/components/menu) |
https://www.chakra-ui.com/docs/components/file-upload | 1. Components
2. File Upload
# File Upload
Used to select and upload files from their device.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/file-upload)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-file-upload--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/file-upload.ts)[Ark](https://ark-ui.com/react/docs/components/file-upload)
PreviewCode
Upload file
```
import { Button } from "@/components/ui/button"
import {
FileUploadList,
FileUploadRoot,
FileUploadTrigger,
} from "@/components/ui/file-upload"
import { HiUpload } from "react-icons/hi"
const Demo = () => {
return (
<FileUploadRoot>
<FileUploadTrigger asChild>
<Button variant="outline" size="sm">
<HiUpload /> Upload file
</Button>
</FileUploadTrigger>
<FileUploadList />
</FileUploadRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `file-upload` snippet
```
npx @chakra-ui/cli snippet add file-upload
```
The snippet includes a closed component composition for the `FileUpload` component.
## [Usage]()
```
import {
FileUploadList,
FileUploadRoot,
FileUploadTrigger,
} from "@/components/ui/file-upload"
```
```
<FileUploadRoot>
<FileUploadTrigger>
<Button>
<HiUpload /> Upload file
</Button>
</FileUploadTrigger>
<FileUploadList />
</FileUploadRoot>
```
## [Examples]()
### [Directory]()
Use the `directory` prop to allow selecting a directory instead of a file.
PreviewCode
Upload file
```
import { Button } from "@/components/ui/button"
import {
FileUploadList,
FileUploadRoot,
FileUploadTrigger,
} from "@/components/ui/file-upload"
import { HiUpload } from "react-icons/hi"
const Demo = () => {
return (
<FileUploadRoot directory>
<FileUploadTrigger asChild>
<Button variant="outline" size="sm">
<HiUpload /> Upload file
</Button>
</FileUploadTrigger>
<FileUploadList />
</FileUploadRoot>
)
}
```
### [Media Capture]()
Use the `capture` prop to select and upload files from different environments and media types.
**Note:** This is [not fully supported](https://caniuse.com/mdn-api_htmlinputelement_capture) in all browsers.
PreviewCode
Open Camera
```
import { Button } from "@/components/ui/button"
import {
FileUploadList,
FileUploadRoot,
FileUploadTrigger,
} from "@/components/ui/file-upload"
import { HiCamera } from "react-icons/hi"
const Demo = () => {
return (
<FileUploadRoot capture="environment">
<FileUploadTrigger asChild>
<Button variant="outline" size="sm">
<HiCamera /> Open Camera
</Button>
</FileUploadTrigger>
<FileUploadList />
</FileUploadRoot>
)
}
```
### [Multiple Files]()
Upload multiple files at once by using the `maxFiles` prop.
PreviewCode
Upload file
```
import { Button } from "@/components/ui/button"
import {
FileUploadList,
FileUploadRoot,
FileUploadTrigger,
} from "@/components/ui/file-upload"
import { HiUpload } from "react-icons/hi"
const Demo = () => {
return (
<FileUploadRoot maxFiles={5}>
<FileUploadTrigger asChild>
<Button variant="outline" size="sm">
<HiUpload /> Upload file
</Button>
</FileUploadTrigger>
<FileUploadList showSize clearable />
</FileUploadRoot>
)
}
```
### [Dropzone]()
Drop multiple files inside the dropzone and use the `maxFiles` prop to set the number of files that can be uploaded at once.
PreviewCode
Drag and drop here to upload
.png, .jpg up to 5MB
```
import {
FileUploadDropzone,
FileUploadList,
FileUploadRoot,
} from "@/components/ui/file-upload"
const Demo = () => {
return (
<FileUploadRoot maxW="xl" alignItems="stretch" maxFiles={10}>
<FileUploadDropzone
label="Drag and drop here to upload"
description=".png, .jpg up to 5MB"
/>
<FileUploadList />
</FileUploadRoot>
)
}
```
### [Input]()
Use the `FileInput` component to create a trigger that looks like a text input.
PreviewCode
Upload fileSelect file(s)
```
import {
FileInput,
FileUploadLabel,
FileUploadRoot,
} from "@/components/ui/file-upload"
const Demo = () => {
return (
<FileUploadRoot gap="1" maxWidth="300px">
<FileUploadLabel>Upload file</FileUploadLabel>
<FileInput />
</FileUploadRoot>
)
}
```
### [Clearable]()
Here's an example of a clearable file upload input.
PreviewCode
Upload file
Select file(s)
```
import { CloseButton } from "@/components/ui/close-button"
import {
FileInput,
FileUploadClearTrigger,
FileUploadLabel,
FileUploadRoot,
} from "@/components/ui/file-upload"
import { InputGroup } from "@/components/ui/input-group"
import { LuFileUp } from "react-icons/lu"
const Demo = () => {
return (
<FileUploadRoot gap="1" maxWidth="300px">
<FileUploadLabel>Upload file</FileUploadLabel>
<InputGroup
w="full"
startElement={<LuFileUp />}
endElement={
<FileUploadClearTrigger asChild>
<CloseButton
me="-1"
size="xs"
variant="plain"
focusVisibleRing="inside"
focusRingWidth="2px"
pointerEvents="auto"
color="fg.subtle"
/>
</FileUploadClearTrigger>
}
>
<FileInput />
</InputGroup>
</FileUploadRoot>
)
}
```
### [Accepted Files]()
Define the accepted files for upload using the `accept` prop.
PreviewCode
Upload file
```
import { Button } from "@/components/ui/button"
import {
FileUploadList,
FileUploadRoot,
FileUploadTrigger,
} from "@/components/ui/file-upload"
import { HiUpload } from "react-icons/hi"
const Demo = () => {
return (
<FileUploadRoot accept={["image/png"]}>
<FileUploadTrigger asChild>
<Button variant="outline" size="sm">
<HiUpload /> Upload file
</Button>
</FileUploadTrigger>
<FileUploadList />
</FileUploadRoot>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`allowDrop``true`
`boolean`
Whether to allow drag and drop in the dropzone element
`locale``'\'en-US\''`
`string`
The current locale. Based on the BCP 47 definition.
`maxFiles``'1'`
`number`
The maximum number of files
`maxFileSize``'Infinity'`
`number`
The maximum file size in bytes
`minFileSize``'0'`
`number`
The minimum file size in bytes
`accept`
`Record<string, string[]> | FileMimeType | FileMimeType[]`
The accept file types
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`capture`
`'user' | 'environment'`
The default camera to use when capturing media
`directory`
`boolean`
Whether to accept directories, only works in webkit browsers
`disabled`
`boolean`
Whether the file input is disabled
`ids`
`Partial<{ root: string dropzone: string hiddenInput: string trigger: string label: string item(id: string): string itemName(id: string): string itemSizeText(id: string): string itemPreview(id: string): string }>`
The ids of the elements. Useful for composition.
`invalid`
`boolean`
Whether the file input is invalid
`name`
`string`
The name of the underlying file input
`onFileAccept`
`(details: FileAcceptDetails) => void`
Function called when the file is accepted
`onFileChange`
`(details: FileChangeDetails) => void`
Function called when the value changes, whether accepted or rejected
`onFileReject`
`(details: FileRejectDetails) => void`
Function called when the file is rejected
`required`
`boolean`
Whether the file input is required
`translations`
`IntlTranslations`
The localized messages to use.
`validate`
`(file: File) => FileError[] | null`
Function to validate a file
`as`
`React.ElementType`
The underlying element to render.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Fieldset](https://www.chakra-ui.com/docs/components/fieldset)
[Next
\
Hover Card](https://www.chakra-ui.com/docs/components/hover-card) |
https://www.chakra-ui.com/docs/components/pagination | 1. Components
2. Pagination
# Pagination
Used to navigate through a series of pages.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/pagination)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-pagination--basic)[Ark](https://ark-ui.com/react/docs/components/pagination)
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `pagination` snippet
```
npx @chakra-ui/cli snippet add pagination
```
The snippet includes a closed component composition for the `Pagination` component.
## [Usage]()
```
import {
PaginationItems,
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
```
```
<PaginationRoot>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationPageText />
<PaginationNextTrigger />
</PaginationRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the pagination.
info
The pagination sizes are mapped to the `Button` component sizes.
PreviewCode
1235
1235
1235
1235
```
import { For, HStack, Stack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<Stack gap="8">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<PaginationRoot
key={size}
count={10}
pageSize={2}
defaultPage={1}
size={size}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)}
</For>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to control the variant of the pagination items and ellipsis.
The variant matches the `Button` component variant.
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1} variant="solid">
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Controlled]()
Use the `page` and `onPageChange` props to control the current page.
PreviewCode
1234510
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const Demo = () => {
const [page, setPage] = useState(1)
return (
<PaginationRoot
count={20}
pageSize={2}
page={page}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Sibling Count]()
Use `siblingCount` to control the number of sibling pages to show before and after the current page.
PreviewCode
18910111220
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={200} pageSize={10} defaultPage={10} siblingCount={2}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Compact]()
Use the `PaginationPageText` to create a compact pagination. This can be useful for mobile views.
PreviewCode
1 of 10
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack gap="4">
<PaginationPrevTrigger />
<PaginationPageText />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [As Link]()
Use the `getHref` prop to create a pagination that navigates via links. This will use the `LinkButton` component to create the links.
info
Edit the `LinkButton` component to point to the correct framework link component if needed.
PreviewCode
[]()[1](https://www.chakra-ui.com/docs/components/pagination?page=1)[2](https://www.chakra-ui.com/docs/components/pagination?page=2)[3](https://www.chakra-ui.com/docs/components/pagination?page=3)[4](https://www.chakra-ui.com/docs/components/pagination?page=4)[5](https://www.chakra-ui.com/docs/components/pagination?page=5)[10](https://www.chakra-ui.com/docs/components/pagination?page=10)[](https://www.chakra-ui.com/docs/components/pagination?page=2)
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot
count={20}
pageSize={2}
defaultPage={1}
getHref={(page) => `?page=${page}`}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Attached]()
Here's an example of composing the pagination with the `Group` component to attach the pagination items and triggers.
PreviewCode
1235
```
import { Group } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={10} pageSize={2} defaultPage={1} variant="solid">
<Group attached>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</Group>
</PaginationRoot>
)
}
```
### [Count Text]()
Pass `format=long` to the `PaginationPageText` component to show the count text
PreviewCode
1 - 5 of 50
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={50} pageSize={5} defaultPage={1} maxW="240px">
<HStack gap="4">
<PaginationPageText format="long" flex="1" />
<PaginationPrevTrigger />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Data Driven]()
Here's an example of controlling the pagination state and using the state to chunk the data.
PreviewCode
Lorem ipsum dolor sit amet 1
Lorem ipsum dolor sit amet 2
Lorem ipsum dolor sit amet 3
Lorem ipsum dolor sit amet 4
Lorem ipsum dolor sit amet 5
1234510
```
"use client"
import { HStack, Stack, Text } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const pageSize = 5
const count = 50
const items = new Array(count)
.fill(0)
.map((_, index) => `Lorem ipsum dolor sit amet ${index + 1}`)
const Demo = () => {
const [page, setPage] = useState(1)
const startRange = (page - 1) * pageSize
const endRange = startRange + pageSize
const visibleItems = items.slice(startRange, endRange)
return (
<Stack gap="4">
<Stack>
{visibleItems.map((item) => (
<Text key={item}>{item}</Text>
))}
</Stack>
<PaginationRoot
page={page}
count={count}
pageSize={pageSize}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
</Stack>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`count`*
`number`
Total number of data items
`page``'1'`
`number`
The active page
`pageSize``'10'`
`number`
Number of data items per page
`siblingCount``'1'`
`number`
Number of pages to show beside active page
`type``'\'button\''`
`'button' | 'link'`
The type of the trigger element
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultPage`
`number`
The initial page of the pagination when it is first rendered. Use when you do not need to control the state of the pagination.
`ids`
`Partial<{ root: string ellipsis(index: number): string prevTrigger: string nextTrigger: string item(page: number): string }>`
The ids of the elements in the accordion. Useful for composition.
`onPageChange`
`(details: PageChangeDetails) => void`
Called when the page number is changed
`onPageSizeChange`
`(details: PageSizeChangeDetails) => void`
Called when the page size is changed
`translations`
`IntlTranslations`
Specifies the localized strings that identifies the accessibility elements and their states
[Previous
\
Number Input](https://www.chakra-ui.com/docs/components/number-input)
[Next
\
Password Input](https://www.chakra-ui.com/docs/components/password-input) |
https://www.chakra-ui.com/docs/components/number-input | 1. Components
2. Number Input
# Number Input
Used to enter a number, and increment or decrement the value using stepper buttons.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/number-input)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-numberinput--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/number-input.ts)[Ark](https://ark-ui.com/react/docs/components/number-input)
PreviewCode
```
import { NumberInputField, NumberInputRoot } from "@/components/ui/number-input"
const Demo = () => {
return (
<NumberInputRoot defaultValue="10" width="200px">
<NumberInputField />
</NumberInputRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `number-input` snippet
```
npx @chakra-ui/cli snippet add number-input
```
The snippet includes a closed component composition for the `NumberInput` component.
## [Usage]()
```
import {
NumberInputField,
NumberInputLabel,
NumberInputRoot,
} from "@/components/ui/number-input"
```
```
<NumberInputRoot>
<NumberInputLabel />
<NumberInputField />
</NumberInputRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the number input.
PreviewCode
```
import { For, Stack } from "@chakra-ui/react"
import { NumberInputField, NumberInputRoot } from "@/components/ui/number-input"
const Demo = () => {
return (
<Stack gap="5" width="200px">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<NumberInputRoot size={size} key={size} defaultValue="10">
<NumberInputField />
</NumberInputRoot>
)}
</For>
</Stack>
)
}
```
### [Formatting]()
Use the `formatOptions` prop to format the number input value. The value of this maps to `Intl.NumberFormatOptions` and is applied based on the current locale.
PreviewCode
```
import { Stack } from "@chakra-ui/react"
import { NumberInputField, NumberInputRoot } from "@/components/ui/number-input"
const Demo = () => {
return (
<Stack gap="5" maxW="200px">
<NumberInputRoot
defaultValue="5"
step={0.01}
formatOptions={{
style: "percent",
}}
>
<NumberInputField />
</NumberInputRoot>
<NumberInputRoot
defaultValue="45"
formatOptions={{
style: "currency",
currency: "EUR",
currencyDisplay: "code",
currencySign: "accounting",
}}
>
<NumberInputField />
</NumberInputRoot>
<NumberInputRoot
defaultValue="4"
formatOptions={{
style: "unit",
unit: "inch",
unitDisplay: "long",
}}
>
<NumberInputField />
</NumberInputRoot>
</Stack>
)
}
```
### [Min and Max]()
Use the `min` and `max` props to set the minimum and maximum values of the number input.
If value entered is less than `min` or greater than `max`, the value will be clamped to the nearest boundary on blur, or enter key press.
PreviewCode
```
import { NumberInputField, NumberInputRoot } from "@/components/ui/number-input"
const Demo = () => {
return (
<NumberInputRoot width="200px" defaultValue="10" min={5} max={50}>
<NumberInputField />
</NumberInputRoot>
)
}
```
### [Step]()
Use the `step` prop to change the increment or decrement interval of the number input.
PreviewCode
```
import { NumberInputField, NumberInputRoot } from "@/components/ui/number-input"
const Demo = () => {
return (
<NumberInputRoot maxW="200px" defaultValue="2" step={3}>
<NumberInputField />
</NumberInputRoot>
)
}
```
### [Controlled]()
Use the `value` and `onValueChange` props to control the value of the number input.
PreviewCode
```
"use client"
import { NumberInputField, NumberInputRoot } from "@/components/ui/number-input"
import { useState } from "react"
const Demo = () => {
const [value, setValue] = useState("10")
return (
<NumberInputRoot
maxW="200px"
value={value}
onValueChange={(e) => setValue(e.value)}
>
<NumberInputField />
</NumberInputRoot>
)
}
```
### [Mobile Stepper]()
Use the `StepperInput` component to create a stepper input for mobile devices.
You can also apply `spinOnPress: false` to disable the spin functionality.
PreviewCode
3
```
import { StepperInput } from "@/components/ui/stepper-input"
const Demo = () => {
return <StepperInput defaultValue="3" />
}
```
### [Mouse Wheel]()
Use the `allowMouseWheel` prop to enable or disable the mouse wheel to change
PreviewCode
```
import { NumberInputField, NumberInputRoot } from "@/components/ui/number-input"
const Demo = () => {
return (
<NumberInputRoot defaultValue="10" width="200px" allowMouseWheel>
<NumberInputField />
</NumberInputRoot>
)
}
```
### [Disabled]()
Use the `disabled` prop to disable the number input.
PreviewCode
```
import { NumberInputField, NumberInputRoot } from "@/components/ui/number-input"
const Demo = () => {
return (
<NumberInputRoot defaultValue="10" width="200px" disabled>
<NumberInputField />
</NumberInputRoot>
)
}
```
### [Invalid]()
Use the `Field` component and pass the `invalid` prop to indicate that the number input is invalid.
PreviewCode
Enter Number
The entry is invalid
```
import { Field } from "@/components/ui/field"
import { NumberInputField, NumberInputRoot } from "@/components/ui/number-input"
const Demo = () => {
return (
<Field label="Enter Number" invalid errorText="The entry is invalid">
<NumberInputRoot defaultValue="10" width="200px">
<NumberInputField />
</NumberInputRoot>
</Field>
)
}
```
### [Helper Text]()
Use the `Field` component and pass the `helperText` prop to add helper text to the number input.
PreviewCode
Enter Number
Enter a number between 1 and 10
```
import { Field } from "@/components/ui/field"
import { NumberInputField, NumberInputRoot } from "@/components/ui/number-input"
const Demo = () => {
return (
<Field label="Enter Number" helperText="Enter a number between 1 and 10">
<NumberInputRoot width="200px">
<NumberInputField />
</NumberInputRoot>
</Field>
)
}
```
### [Hook Form]()
Here is an example of how to use the `NumberInput` component with `react-hook-form`.
PreviewCode
Number
Submit
```
"use client"
import { Button } from "@chakra-ui/react"
import { zodResolver } from "@hookform/resolvers/zod"
import { Field } from "@/components/ui/field"
import { NumberInputField, NumberInputRoot } from "@/components/ui/number-input"
import { Controller, useForm } from "react-hook-form"
import { z } from "zod"
const formSchema = z.object({
number: z.string({ message: "Number is required" }),
})
type FormValues = z.infer<typeof formSchema>
const Demo = () => {
const {
control,
handleSubmit,
formState: { errors },
} = useForm<FormValues>({
resolver: zodResolver(formSchema),
})
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Field
label="Number"
invalid={!!errors.number}
errorText={errors.number?.message}
>
<Controller
name="number"
control={control}
render={({ field }) => (
<NumberInputRoot
disabled={field.disabled}
name={field.name}
value={field.value}
onValueChange={({ value }) => {
field.onChange(value)
}}
>
<NumberInputField onBlur={field.onBlur} />
</NumberInputRoot>
)}
/>
</Field>
<Button size="sm" type="submit" mt="4">
Submit
</Button>
</form>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`allowOverflow``true`
`boolean`
Whether to allow the value overflow the min/max range
`clampValueOnBlur``true`
`boolean`
Whether to clamp the value when the input loses focus (blur)
`focusInputOnChange``true`
`boolean`
Whether to focus input when the value changes
`inputMode``'\'decimal\''`
`InputMode`
Hints at the type of data that might be entered by the user. It also determines the type of keyboard shown to the user on mobile devices
`locale``'\'en-US\''`
`string`
The current locale. Based on the BCP 47 definition.
`max``'Number.MAX_SAFE_INTEGER'`
`number`
The maximum value of the number input
`min``'Number.MIN_SAFE_INTEGER'`
`number`
The minimum value of the number input
`pattern``'\'[0-9]*(.[0-9]+)?\''`
`string`
The pattern used to check the <input> element's value against
`spinOnPress``true`
`boolean`
Whether to spin the value when the increment/decrement button is pressed
`step``'1'`
`number`
The amount to increment or decrement the value by
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
`variant``'outline'`
`'outline' | 'filled' | 'flushed'`
The variant of the component
`allowMouseWheel`
`boolean`
Whether to allow mouse wheel to change the value
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultValue`
`string`
The initial value of the number input when it is first rendered. Use when you do not need to control the state of the number input.
`disabled`
`boolean`
Whether the number input is disabled.
`form`
`string`
The associate form of the input element.
`formatOptions`
`NumberFormatOptions`
The options to pass to the \`Intl.NumberFormat\` constructor
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ root: string label: string input: string incrementTrigger: string decrementTrigger: string scrubber: string }>`
The ids of the elements in the number input. Useful for composition.
`invalid`
`boolean`
Whether the number input value is invalid.
`name`
`string`
The name attribute of the number input. Useful for form submission.
`onFocusChange`
`(details: FocusChangeDetails) => void`
Function invoked when the number input is focused
`onValueChange`
`(details: ValueChangeDetails) => void`
Function invoked when the value changes
`onValueInvalid`
`(details: ValueInvalidDetails) => void`
Function invoked when the value overflows or underflows the min/max range
`readOnly`
`boolean`
Whether the number input is readonly
`required`
`boolean`
Whether the number input is required
`translations`
`IntlTranslations`
Specifies the localized strings that identifies the accessibility elements and their states
`value`
`string`
The value of the input
[Previous
\
Menu](https://www.chakra-ui.com/docs/components/menu)
[Next
\
Pagination](https://www.chakra-ui.com/docs/components/pagination) |
https://www.chakra-ui.com/docs/components/password-input | 1. Components
2. Password Input
# Password Input
Used to collect passwords.
PreviewCode
```
import { PasswordInput } from "@/components/ui/password-input"
const Demo = () => {
return <PasswordInput />
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `password-input` snippet
```
npx @chakra-ui/cli snippet add password-input
```
The snippet includes a closed component composition for the `PasswordInput` component.
## [Usage]()
```
import {
PasswordInput,
PasswordStrengthMeter,
} from "@/components/ui/password-input"
```
```
<PasswordInput />
<PasswordStrengthMeter />
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the password input.
info
The password input sizes are mapped to the `Input` component sizes.
PreviewCode
```
import { Stack } from "@chakra-ui/react"
import { PasswordInput } from "@/components/ui/password-input"
const Demo = () => {
return (
<Stack maxW="300px">
<PasswordInput placeholder="xs" size="xs" />
<PasswordInput placeholder="sm" size="sm" />
<PasswordInput placeholder="md" size="md" />
<PasswordInput placeholder="lg" size="lg" />
</Stack>
)
}
```
### [Controlled]()
Use the `value` and `onChange` props to control the current page.
PreviewCode
```
"use client"
import { PasswordInput } from "@/components/ui/password-input"
import { useState } from "react"
const Demo = () => {
const [value, setValue] = useState("")
return (
<PasswordInput value={value} onChange={(e) => setValue(e.target.value)} />
)
}
```
### [Hook Form]()
Here's an example of how to use the `PasswordInput` component with `react-hook-form`.
PreviewCode
Username
Password
Submit
```
"use client"
import { Button, Input, Stack } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
import { PasswordInput } from "@/components/ui/password-input"
import { useForm } from "react-hook-form"
interface FormValues {
username: string
password: string
}
const Demo = () => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm<FormValues>()
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Stack gap="4" align="flex-start" maxW="sm">
<Field
label="Username"
invalid={!!errors.username}
errorText={errors.username?.message}
>
<Input
{...register("username", { required: "Username is required" })}
/>
</Field>
<Field
label="Password"
invalid={!!errors.password}
errorText={errors.password?.message}
>
<PasswordInput
{...register("password", { required: "Password is required" })}
/>
</Field>
<Button type="submit">Submit</Button>
</Stack>
</form>
)
}
```
### [Controlled Visibility]()
Use the `visible` and `onVisibleChange` props to control the visibility of the password input.
PreviewCode
Password is hidden
```
"use client"
import { Stack, Text } from "@chakra-ui/react"
import { PasswordInput } from "@/components/ui/password-input"
import { useState } from "react"
const Demo = () => {
const [visible, setVisible] = useState(false)
return (
<Stack>
<PasswordInput
defaultValue="secret"
visible={visible}
onVisibleChange={setVisible}
/>
<Text>Password is {visible ? "visible" : "hidden"}</Text>
</Stack>
)
}
```
### [Strength Indicator]()
Render the `PasswordStrengthMeter` component to show the strength of the password. Compute the `value` prop based on the password input `value`.
PreviewCode
Medium
```
import { Stack } from "@chakra-ui/react"
import {
PasswordInput,
PasswordStrengthMeter,
} from "@/components/ui/password-input"
const Demo = () => {
return (
<Stack maxW="300px">
<PasswordInput />
<PasswordStrengthMeter value={2} />
</Stack>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`defaultVisible``false`
`boolean`
The default visibility state of the password input.
`visible`
`boolean`
The controlled visibility state of the password input.
`onVisibleChange`
`(visible: boolean) => void`
Callback invoked when the visibility state changes.
`visibilityIcon`
`{ on: React.ReactNode; off: React.ReactNode }`
Custom icons for the visibility toggle button.
[Previous
\
Pagination](https://www.chakra-ui.com/docs/components/pagination)
[Next
\
Pin Input](https://www.chakra-ui.com/docs/components/pin-input) |
https://www.chakra-ui.com/docs/components/progress-circle | 1. Components
2. Progress Circle
# Progress Circle
Used to display a task's progress in a circular form.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/progress-circle)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-progress-circle--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/progress-circle.ts)[Ark](https://ark-ui.com/react/docs/components/progress-circular)
PreviewCode
```
import {
ProgressCircleRing,
ProgressCircleRoot,
} from "@/components/ui/progress-circle"
const Demo = () => {
return (
<ProgressCircleRoot value={75}>
<ProgressCircleRing />
</ProgressCircleRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `progress-circle` snippet
```
npx @chakra-ui/cli snippet add progress-circle
```
The snippet includes a closed component composition for the `ProgressCircle` component.
## [Usage]()
```
import {
ProgressCircleRing,
ProgressCircleRoot,
} from "@/components/ui/progress-circle"
```
```
<ProgressCircleRoot>
<ProgressCircleRing />
<ProgressCircleValueText />
</ProgressCircleRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the progress circle component.
PreviewCode
```
import { For, HStack } from "@chakra-ui/react"
import {
ProgressCircleRing,
ProgressCircleRoot,
} from "@/components/ui/progress-circle"
const Demo = () => {
return (
<HStack gap="10">
<For each={["xs", "sm", "md", "lg", "xl"]}>
{(size) => (
<ProgressCircleRoot size={size} value={30}>
<ProgressCircleRing cap="round" />
</ProgressCircleRoot>
)}
</For>
</HStack>
)
}
```
### [Colors]()
Use the `colorPalette` prop to change the color scheme of the component.
PreviewCode
gray
red
green
blue
teal
pink
purple
cyan
orange
yellow
```
import { HStack, Stack, Text } from "@chakra-ui/react"
import { colorPalettes } from "compositions/lib/color-palettes"
import {
ProgressCircleRing,
ProgressCircleRoot,
} from "@/components/ui/progress-circle"
const Demo = () => {
return (
<Stack gap="4" align="flex-start">
{colorPalettes.map((colorPalette) => (
<HStack key={colorPalette} gap="10" px="4">
<Text minW="8ch">{colorPalette}</Text>
<ProgressCircleRoot size="sm" value={30} colorPalette={colorPalette}>
<ProgressCircleRing cap="round" />
</ProgressCircleRoot>
<ProgressCircleRoot size="md" value={30} colorPalette={colorPalette}>
<ProgressCircleRing cap="round" />
</ProgressCircleRoot>
<ProgressCircleRoot size="lg" value={30} colorPalette={colorPalette}>
<ProgressCircleRing cap="round" />
</ProgressCircleRoot>
</HStack>
))}
</Stack>
)
}
```
### [Value Text]()
Render the `ProgressCircleValueText` component to display the progress value.
PreviewCode
5%
5%
5%
```
import { For, HStack } from "@chakra-ui/react"
import {
ProgressCircleRing,
ProgressCircleRoot,
ProgressCircleValueText,
} from "@/components/ui/progress-circle"
const Demo = () => {
return (
<HStack gap="8">
<For each={["md", "lg", "xl"]}>
{(size) => (
<ProgressCircleRoot value={5} size={size}>
<ProgressCircleValueText />
<ProgressCircleRing />
</ProgressCircleRoot>
)}
</For>
</HStack>
)
}
```
### [Custom Thickness]()
Pass the `--thickness` css variable to the `ProgressCircleRing` component to change the thickness of the ring.
PreviewCode
```
import {
ProgressCircleRing,
ProgressCircleRoot,
} from "@/components/ui/progress-circle"
const Demo = () => {
return (
<ProgressCircleRoot value={75}>
<ProgressCircleRing css={{ "--thickness": "2px" }} />
</ProgressCircleRoot>
)
}
```
### [Indeterminate]()
Set the `value` prop to `null` to render the indeterminate state.
PreviewCode
```
import {
ProgressCircleRing,
ProgressCircleRoot,
} from "@/components/ui/progress-circle"
const Demo = () => {
return (
<ProgressCircleRoot value={null} size="sm">
<ProgressCircleRing cap="round" />
</ProgressCircleRoot>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
[Previous
\
Popover](https://www.chakra-ui.com/docs/components/popover)
[Next
\
Progress](https://www.chakra-ui.com/docs/components/progress) |
https://www.chakra-ui.com/docs/components/progress | 1. Components
2. Progress
# Progress
Used to display the progress status for a task.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/progress)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-progress--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/progress.ts)[Ark](https://ark-ui.com/react/docs/components/progress-linear)
PreviewCode
```
import { ProgressBar, ProgressRoot } from "@/components/ui/progress"
const Demo = () => {
return (
<ProgressRoot maxW="240px">
<ProgressBar />
</ProgressRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `progress` snippet
```
npx @chakra-ui/cli snippet add progress
```
The snippet includes a closed component composition for the `Progress` component.
## [Usage]()
```
import { ProgressBar, ProgressRoot } from "@/components/ui/progress"
```
```
<ProgressRoot>
<ProgressLabel />
<ProgressValueText />
<ProgressBar />
</ProgressRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the progress bar.
PreviewCode
```
import { Stack } from "@chakra-ui/react"
import { ProgressBar, ProgressRoot } from "@/components/ui/progress"
const Demo = () => {
return (
<Stack gap="4" maxW="240px">
<ProgressRoot size="xs">
<ProgressBar />
</ProgressRoot>
<ProgressRoot size="sm">
<ProgressBar />
</ProgressRoot>
<ProgressRoot size="md">
<ProgressBar />
</ProgressRoot>
<ProgressRoot size="lg">
<ProgressBar />
</ProgressRoot>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to change the visual style of the progress bar.
PreviewCode
```
import { Stack } from "@chakra-ui/react"
import { ProgressBar, ProgressRoot } from "@/components/ui/progress"
const Demo = () => {
return (
<Stack gap="4" maxW="200px">
<ProgressRoot variant="subtle">
<ProgressBar />
</ProgressRoot>
<ProgressRoot variant="outline">
<ProgressBar />
</ProgressRoot>
</Stack>
)
}
```
### [Colors]()
Use the `colorPalette` prop to change the color of the progress bar.
PreviewCode
gray
red
green
blue
teal
pink
purple
cyan
orange
yellow
```
import { Stack, Text } from "@chakra-ui/react"
import { colorPalettes } from "compositions/lib/color-palettes"
import { ProgressBar, ProgressRoot } from "@/components/ui/progress"
const Demo = () => {
return (
<Stack gap="2" align="flex-start">
{colorPalettes.map((colorPalette) => (
<Stack
align="center"
key={colorPalette}
direction="row"
gap="10"
px="4"
>
<Text minW="8ch">{colorPalette}</Text>
<ProgressRoot
width="120px"
defaultValue={40}
colorPalette={colorPalette}
variant="outline"
>
<ProgressBar />
</ProgressRoot>
<ProgressRoot
width="120px"
defaultValue={40}
colorPalette={colorPalette}
variant="subtle"
>
<ProgressBar />
</ProgressRoot>
</Stack>
))}
</Stack>
)
}
```
### [Inline Label]()
Compose the `ProgressLabel` and `ProgressValueText` components to create an inline label for the progress bar.
PreviewCode
Usage
40%
```
import { HStack } from "@chakra-ui/react"
import {
ProgressBar,
ProgressLabel,
ProgressRoot,
ProgressValueText,
} from "@/components/ui/progress"
const Demo = () => {
return (
<ProgressRoot defaultValue={40} maxW="sm">
<HStack gap="5">
<ProgressLabel>Usage</ProgressLabel>
<ProgressBar flex="1" />
<ProgressValueText>40%</ProgressValueText>
</HStack>
</ProgressRoot>
)
}
```
### [Info tip]()
Use the `info` prop to add a tooltip to the progress bar.
PreviewCode
Uploading
Uploading document to the server
```
import {
ProgressBar,
ProgressLabel,
ProgressRoot,
} from "@/components/ui/progress"
const Demo = () => {
return (
<ProgressRoot maxW="240px">
<ProgressLabel info="Uploading document to the server" mb="2">
Uploading
</ProgressLabel>
<ProgressBar />
</ProgressRoot>
)
}
```
### [Indeterminate]()
Set the value to `null` to show an indeterminate progress bar.
PreviewCode
```
import { ProgressBar, ProgressRoot } from "@/components/ui/progress"
const Demo = () => {
return (
<ProgressRoot maxW="240px" value={null}>
<ProgressBar />
</ProgressRoot>
)
}
```
### [Stripes]()
Set the `striped` prop to `true` to add stripes to the progress bar.
PreviewCode
```
import { ProgressBar, ProgressRoot } from "@/components/ui/progress"
const Demo = () => {
return (
<ProgressRoot maxW="240px" striped>
<ProgressBar />
</ProgressRoot>
)
}
```
### [Animated Stripes]()
Set the `animated` prop to `true` to animate the stripes.
PreviewCode
```
import { ProgressBar, ProgressRoot } from "@/components/ui/progress"
const Demo = () => {
return (
<ProgressRoot maxW="240px" striped animated>
<ProgressBar />
</ProgressRoot>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`max``'100'`
`number`
The maximum allowed value of the progress bar.
`min``'0'`
`number`
The minimum allowed value of the progress bar.
`orientation``'\'horizontal\''`
`Orientation`
The orientation of the element.
`value``'50'`
`number`
The current value of the progress bar.
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`variant``'outline'`
`'outline' | 'subtle'`
The variant of the component
`shape``'rounded'`
`'square' | 'rounded' | 'pill'`
The shape of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`ids`
`Partial<{ root: string; track: string; label: string; circle: string }>`
The ids of the elements in the progress bar. Useful for composition.
`translations`
`IntlTranslations`
The localized messages to use.
`striped`
`'true' | 'false'`
The striped of the component
`animated`
`'true' | 'false'`
The animated of the component
`as`
`React.ElementType`
The underlying element to render.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Progress Circle](https://www.chakra-ui.com/docs/components/progress-circle)
[Next
\
Radio Card](https://www.chakra-ui.com/docs/components/radio-card) |
https://www.chakra-ui.com/docs/components/radio-card | 1. Components
2. Radio Card
# Radio Card
Used to select an option from list
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/radio-card)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-radio-card--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/radio-card.ts)[Ark](https://ark-ui.com/react/docs/components/radio-group)
PreviewCode
Select framework
Next.js
Best for apps
Vite
Best for SPAs
Astro
Best for static sites
```
import { HStack } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
const Demo = () => {
return (
<RadioCardRoot defaultValue="next">
<RadioCardLabel>Select framework</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
label={item.title}
description={item.description}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{ value: "next", title: "Next.js", description: "Best for apps" },
{ value: "vite", title: "Vite", description: "Best for SPAs" },
{ value: "astro", title: "Astro", description: "Best for static sites" },
]
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `radio-card` snippet
```
npx @chakra-ui/cli snippet add radio-card
```
The snippet includes a closed component composition for the `RadioCard` component.
## [Usage]()
A RadioCard is a form element with a larger interaction surface represented as a card.
```
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
```
```
<RadioCardRoot>
<RadioCardLabel />
<RadioCardItem />
</RadioCardRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the radio card.
PreviewCode
size = (sm)
Next.js
Vite
size = (md)
Next.js
Vite
size = (lg)
Next.js
Vite
```
import { For, HStack, Stack } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
const Demo = () => {
return (
<Stack gap="8">
<For each={["sm", "md", "lg"]}>
{(size) => (
<RadioCardRoot key={size} size={size} defaultValue="next">
<RadioCardLabel>size = ({size})</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
label={item.title}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)}
</For>
</Stack>
)
}
const items = [
{ value: "next", title: "Next.js" },
{ value: "vite", title: "Vite" },
]
```
### [Colors]()
Use the `colorPalette` prop to change the color of the radio card.
PreviewCode
Select Framework
Next.js
Vite
Select Framework
Next.js
Vite
Select Framework
Next.js
Vite
Select Framework
Next.js
Vite
Select Framework
Next.js
Vite
Select Framework
Next.js
Vite
Select Framework
Next.js
Vite
Select Framework
Next.js
Vite
Select Framework
Next.js
Vite
Select Framework
Next.js
Vite
```
import { For, HStack, Stack } from "@chakra-ui/react"
import { colorPalettes } from "compositions/lib/color-palettes"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
const Demo = () => {
return (
<Stack gap="8">
<For each={colorPalettes}>
{(colorPalette) => (
<RadioCardRoot
key={colorPalette}
colorPalette={colorPalette}
defaultValue="next"
>
<RadioCardLabel>Select Framework</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
label={item.title}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)}
</For>
</Stack>
)
}
const items = [
{ value: "next", title: "Next.js" },
{ value: "vite", title: "Vite" },
]
```
### [Icon]()
Here's an example of using a label, description and icon within the `RadioCardItem`.
PreviewCode
Select permission
Allow
This user can access the system
Deny
This user will be denied access to the system
Lock
This user will be locked out of the system
```
import { HStack, Icon } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
import { LuArrowRight, LuCircleOff, LuLock } from "react-icons/lu"
const Demo = () => {
return (
<RadioCardRoot defaultValue="next">
<RadioCardLabel>Select permission</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
icon={
<Icon fontSize="2xl" color="fg.muted" mb="2">
{item.icon}
</Icon>
}
label={item.title}
description={item.description}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{
icon: <LuArrowRight />,
value: "allow",
title: "Allow",
description: "This user can access the system",
},
{
icon: <LuCircleOff />,
value: "deny",
title: "Deny",
description: "This user will be denied access to the system",
},
{
icon: <LuLock />,
value: "lock",
title: "Lock",
description: "This user will be locked out of the system",
},
]
```
### [No Indicator]()
Here's an example of setting the `indicator` prop to `null` to hide the indicator.
PreviewCode
Payment method
Paypal
Apple Pay
Card
```
import { HStack, Icon } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
import { RiAppleFill, RiBankCardFill, RiPaypalFill } from "react-icons/ri"
const Demo = () => {
return (
<RadioCardRoot
orientation="horizontal"
align="center"
justify="center"
maxW="lg"
defaultValue="paypal"
>
<RadioCardLabel>Payment method</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
label={item.title}
icon={
<Icon fontSize="2xl" color="fg.subtle">
{item.icon}
</Icon>
}
indicator={false}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{ value: "paypal", title: "Paypal", icon: <RiPaypalFill /> },
{ value: "apple-pay", title: "Apple Pay", icon: <RiAppleFill /> },
{ value: "card", title: "Card", icon: <RiBankCardFill /> },
]
```
### [No Indicator (Vertical)]()
Here's an example of a RadioCard with no indicator and content aligned vertically.
PreviewCode
Payment method
Paypal
Apple Pay
Card
```
import { HStack, Icon } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
import { RiAppleFill, RiBankCardFill, RiPaypalFill } from "react-icons/ri"
const Demo = () => {
return (
<RadioCardRoot
orientation="vertical"
align="center"
maxW="400px"
defaultValue="paypal"
>
<RadioCardLabel>Payment method</RadioCardLabel>
<HStack>
{items.map((item) => (
<RadioCardItem
label={item.title}
icon={
<Icon fontSize="2xl" color="fg.muted">
{item.icon}
</Icon>
}
indicator={false}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{ value: "paypal", title: "Paypal", icon: <RiPaypalFill /> },
{ value: "apple-pay", title: "Apple Pay", icon: <RiAppleFill /> },
{ value: "card", title: "Card", icon: <RiBankCardFill /> },
]
```
### [Centered]()
Here's an example of a RadioCard with centered text.
PreviewCode
Select contract type
Fixed Rate
Milestone
Hourly
```
import { HStack, Icon } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
import { LuClock, LuDollarSign, LuTrendingUp } from "react-icons/lu"
const Demo = () => {
return (
<RadioCardRoot orientation="vertical" align="center" defaultValue="next">
<RadioCardLabel>Select contract type</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
icon={
<Icon fontSize="2xl" color="fg.muted" mb="2">
{item.icon}
</Icon>
}
label={item.title}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{ icon: <LuDollarSign />, value: "fixed", title: "Fixed Rate" },
{ icon: <LuTrendingUp />, value: "milestone", title: "Milestone" },
{ icon: <LuClock />, value: "hourly", title: "Hourly" },
]
```
### [Composition]()
Here's an example of composing the RadioCard with the `Group` component.
PreviewCode
How well do you know React?
Advanced
I love complex things
Professional
I can hack simple things
Beginner
I don't write code
```
import { Group } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
const Demo = () => {
return (
<RadioCardRoot defaultValue="next" gap="4" maxW="sm">
<RadioCardLabel>How well do you know React?</RadioCardLabel>
<Group attached orientation="vertical">
{items.map((item) => (
<RadioCardItem
width="full"
indicatorPlacement="start"
label={item.title}
description={item.description}
key={item.value}
value={item.value}
/>
))}
</Group>
</RadioCardRoot>
)
}
const items = [
{
value: "advanced",
title: "Advanced",
description: "I love complex things",
},
{
value: "professional",
title: "Professional",
description: "I can hack simple things",
},
{
value: "beginner",
title: "Beginner",
description: "I don't write code",
},
]
```
### [Addon]()
Pass the `addon` prop to the `RadioCardItem` component to add metadata below the item content.
PreviewCode
Select framework
Next.js
Best for apps
Some addon text
Vite
Best for SPAs
Some addon text
Astro
Best for static sites
Some addon text
```
import { HStack } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
const Demo = () => {
return (
<RadioCardRoot defaultValue="next">
<RadioCardLabel>Select framework</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
label={item.title}
description={item.description}
key={item.value}
value={item.value}
addon="Some addon text"
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{ value: "next", title: "Next.js", description: "Best for apps" },
{ value: "vite", title: "Vite", description: "Best for SPAs" },
{ value: "astro", title: "Astro", description: "Best for static sites" },
]
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'sm' | 'md' | 'lg'`
The size of the component
`variant``'outline'`
`'plain' | 'subtle' | 'outline'`
The variant of the component
`as`
`React.ElementType`
The underlying element to render.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Progress](https://www.chakra-ui.com/docs/components/progress)
[Next
\
Radio](https://www.chakra-ui.com/docs/components/radio) |
https://www.chakra-ui.com/docs/components/popover | 1. Components
2. Popover
# Popover
Used to show detailed information inside a pop-up
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/popover)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-popover--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/popover.ts)[Ark](https://ark-ui.com/react/docs/components/popover)
PreviewCode
Click me
Naruto Form
Naruto is a Japanese manga series written and illustrated by Masashi Kishimoto.
```
import { Input, Text } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
PopoverArrow,
PopoverBody,
PopoverContent,
PopoverRoot,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"
const Demo = () => {
return (
<PopoverRoot>
<PopoverTrigger asChild>
<Button size="sm" variant="outline">
Click me
</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverBody>
<PopoverTitle fontWeight="medium">Naruto Form</PopoverTitle>
<Text my="4">
Naruto is a Japanese manga series written and illustrated by Masashi
Kishimoto.
</Text>
<Input placeholder="Your fav. character" size="sm" />
</PopoverBody>
</PopoverContent>
</PopoverRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `popover` snippet
```
npx @chakra-ui/cli snippet add popover
```
The snippet includes component compositions based on the `Popover` component.
## [Usage]()
```
import {
PopoverBody,
PopoverContent,
PopoverRoot,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"
```
```
<PopoverRoot>
<PopoverTrigger />
<PopoverContent>
<PopoverBody>
<PopoverTitle />
</PopoverBody>
</PopoverContent>
</PopoverRoot>
```
## [Examples]()
### [Controlled]()
Use the `open` and `onOpenChange` to control the visibility of the popover.
PreviewCode
Click me
This is a popover with the same width as the trigger button
```
"use client"
import { Button } from "@/components/ui/button"
import {
PopoverArrow,
PopoverBody,
PopoverContent,
PopoverRoot,
PopoverTrigger,
} from "@/components/ui/popover"
import { useState } from "react"
const Demo = () => {
const [open, setOpen] = useState(false)
return (
<PopoverRoot open={open} onOpenChange={(e) => setOpen(e.open)}>
<PopoverTrigger asChild>
<Button size="sm" variant="outline">
Click me
</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverBody>
This is a popover with the same width as the trigger button
</PopoverBody>
</PopoverContent>
</PopoverRoot>
)
}
```
### [Sizes]()
Use the `size` prop to change the size of the popover component.
PreviewCode
Click me
Naruto Form
Naruto is a Japanese manga series written and illustrated by Masashi Kishimoto.
Click me
Naruto Form
Naruto is a Japanese manga series written and illustrated by Masashi Kishimoto.
Click me
Naruto Form
Naruto is a Japanese manga series written and illustrated by Masashi Kishimoto.
Click me
Naruto Form
Naruto is a Japanese manga series written and illustrated by Masashi Kishimoto.
```
import { For, Input, Stack, Text } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
PopoverArrow,
PopoverBody,
PopoverContent,
PopoverRoot,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"
const Demo = () => {
return (
<Stack align="center" direction="row" gap="10">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<PopoverRoot key={size} size={size}>
<PopoverTrigger asChild>
<Button size={size} variant="outline">
Click me
</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverBody>
<PopoverTitle fontWeight="medium">Naruto Form</PopoverTitle>
<Text my="4">
Naruto is a Japanese manga series written and illustrated by
Masashi Kishimoto.
</Text>
<Input placeholder="Your fav. character" size={size} />
</PopoverBody>
</PopoverContent>
</PopoverRoot>
)}
</For>
</Stack>
)
}
```
### [Lazy Mount]()
Use the `lazyMounted` and/or `unmountOnExit` prop to defer the mounting of the popover content until it's opened.
PreviewCode
Click me
```
import { Text } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
PopoverArrow,
PopoverBody,
PopoverContent,
PopoverRoot,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"
const Demo = () => {
return (
<PopoverRoot lazyMount unmountOnExit>
<PopoverTrigger asChild>
<Button size="sm" variant="outline">
Click me
</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverBody>
<PopoverTitle fontWeight="medium">Naruto Form</PopoverTitle>
<Text my="4">
Naruto is a Japanese manga series written and illustrated by Masashi
Kishimoto.
</Text>
</PopoverBody>
</PopoverContent>
</PopoverRoot>
)
}
```
### [Placement]()
Use the `positioning.placement` prop to configure the underlying `floating-ui` positioning logic.
PreviewCode
Click me
Some content
```
import { Button } from "@/components/ui/button"
import {
PopoverArrow,
PopoverBody,
PopoverContent,
PopoverRoot,
PopoverTrigger,
} from "@/components/ui/popover"
const Demo = () => {
return (
<PopoverRoot positioning={{ placement: "bottom-end" }}>
<PopoverTrigger asChild>
<Button size="sm" variant="outline">
Click me
</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverBody>Some content</PopoverBody>
</PopoverContent>
</PopoverRoot>
)
}
```
### [Offset]()
Use the `positioning.offset` prop to adjust the position of the popover content.
PreviewCode
Open
This is a popover with the same width as the trigger button
```
import { Button } from "@/components/ui/button"
import {
PopoverBody,
PopoverContent,
PopoverRoot,
PopoverTrigger,
} from "@/components/ui/popover"
const Demo = () => {
return (
<PopoverRoot positioning={{ offset: { crossAxis: 0, mainAxis: 0 } }}>
<PopoverTrigger asChild>
<Button size="sm" variant="outline">
Open
</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverBody>
This is a popover with the same width as the trigger button
</PopoverBody>
</PopoverContent>
</PopoverRoot>
)
}
```
### [Same Width]()
Use the `positioning.sameWidth` prop to make the popover content the same width as the trigger.
PreviewCode
Click me
This is a popover with the same width as the trigger button
```
import { Button } from "@/components/ui/button"
import {
PopoverArrow,
PopoverBody,
PopoverContent,
PopoverRoot,
PopoverTrigger,
} from "@/components/ui/popover"
const Demo = () => {
return (
<PopoverRoot positioning={{ sameWidth: true }}>
<PopoverTrigger asChild>
<Button size="sm" variant="outline" minW="xs">
Click me
</Button>
</PopoverTrigger>
<PopoverContent width="auto">
<PopoverArrow />
<PopoverBody>
This is a popover with the same width as the trigger button
</PopoverBody>
</PopoverContent>
</PopoverRoot>
)
}
```
### [Nested Popover]()
When nesting overlay elements like popover, select, menu, inside of the popover, set `portalled=false` on them.
Here's an example of a popover inside another popover.
PreviewCode
Click me
Naruto is a Japanese manga series written and illustrated by Masashi Kishimoto.
Open Nested Popover
Some nested popover content
```
import { Text } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
PopoverArrow,
PopoverBody,
PopoverContent,
PopoverRoot,
PopoverTrigger,
} from "@/components/ui/popover"
const Demo = () => {
return (
<PopoverRoot>
<PopoverTrigger asChild>
<Button size="sm" variant="outline">
Click me
</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverBody>
<Text mb="4">
Naruto is a Japanese manga series written and illustrated by Masashi
Kishimoto.
</Text>
<PopoverRoot>
<PopoverTrigger asChild>
<Button variant="outline" size="xs">
Open Nested Popover
</Button>
</PopoverTrigger>
<PopoverContent portalled={false}>
<PopoverArrow />
<PopoverBody>Some nested popover content</PopoverBody>
</PopoverContent>
</PopoverRoot>
</PopoverBody>
</PopoverContent>
</PopoverRoot>
)
}
```
### [Initial Focus]()
Use the `initialFocusEl` prop to set the initial focus of the popover content.
PreviewCode
Click me
This is a popover with the same width as the trigger button
```
"use client"
import { Box, Group } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
PopoverArrow,
PopoverBody,
PopoverCloseTrigger,
PopoverContent,
PopoverFooter,
PopoverHeader,
PopoverRoot,
PopoverTrigger,
} from "@/components/ui/popover"
import { useRef } from "react"
const Demo = () => {
const ref = useRef<HTMLButtonElement>(null)
return (
<PopoverRoot initialFocusEl={() => ref.current}>
<PopoverTrigger asChild>
<Button size="sm" variant="outline">
Click me
</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverHeader>Manage Your Channels</PopoverHeader>
<PopoverArrow />
<PopoverBody>
This is a popover with the same width as the trigger button
</PopoverBody>
<PopoverFooter>
<Box fontSize="sm" flex="1">
Step 2 of 4
</Box>
<Group>
<Button size="sm" ref={ref}>
Prev
</Button>
<Button size="sm">Next</Button>
</Group>
</PopoverFooter>
<PopoverCloseTrigger />
</PopoverContent>
</PopoverRoot>
)
}
```
### [Form]()
Here's an example of a popover with a form inside.
PreviewCode
Click me
Width
Height
Comments
```
import { Input, Stack, Textarea } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import { Field } from "@/components/ui/field"
import {
PopoverArrow,
PopoverBody,
PopoverCloseTrigger,
PopoverContent,
PopoverRoot,
PopoverTrigger,
} from "@/components/ui/popover"
const Demo = () => {
return (
<PopoverRoot>
<PopoverTrigger asChild>
<Button size="sm" variant="outline">
Click me
</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverBody>
<Stack gap="4">
<Field label="Width">
<Input placeholder="40px" />
</Field>
<Field label="Height">
<Input placeholder="32px" />
</Field>
<Field label="Comments">
<Textarea placeholder="Start typing..." />
</Field>
</Stack>
</PopoverBody>
<PopoverCloseTrigger />
</PopoverContent>
</PopoverRoot>
)
}
```
### [Custom Background]()
Use the `--popover-bg` CSS variable to change the background color of the popover content and its arrow.
PreviewCode
Click me
Naruto Form
Naruto is a Japanese manga series written and illustrated by Masashi Kishimoto.
```
import { Input, Text } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
PopoverArrow,
PopoverBody,
PopoverContent,
PopoverRoot,
PopoverTitle,
PopoverTrigger,
} from "@/components/ui/popover"
const Demo = () => {
return (
<PopoverRoot>
<PopoverTrigger asChild>
<Button size="sm" variant="outline">
Click me
</Button>
</PopoverTrigger>
<PopoverContent css={{ "--popover-bg": "lightblue" }}>
<PopoverArrow />
<PopoverBody>
<PopoverTitle fontWeight="medium">Naruto Form</PopoverTitle>
<Text my="4">
Naruto is a Japanese manga series written and illustrated by Masashi
Kishimoto.
</Text>
<Input bg="bg" placeholder="Your fav. character" size="sm" />
</PopoverBody>
</PopoverContent>
</PopoverRoot>
)
}
```
### [Without Snippet]()
If you don't want to use the snippet, you can use the `Popover` component from the `@chakra-ui/react` package.
PreviewCode
Click me
Naruto Form
Naruto is a Japanese manga series written and illustrated by Masashi Kishimoto.
```
import { Button, Input, Popover, Portal, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Popover.Root>
<Popover.Trigger asChild>
<Button size="sm" variant="outline">
Click me
</Button>
</Popover.Trigger>
<Portal>
<Popover.Positioner>
<Popover.Content>
<Popover.Arrow>
<Popover.ArrowTip />
</Popover.Arrow>
<Popover.Body>
<Popover.Title fontWeight="medium">Naruto Form</Popover.Title>
<Text my="4">
Naruto is a Japanese manga series written and illustrated by
Masashi Kishimoto.
</Text>
<Input placeholder="Your fav. character" size="sm" />
</Popover.Body>
</Popover.Content>
</Popover.Positioner>
</Portal>
</Popover.Root>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`autoFocus``true`
`boolean`
Whether to automatically set focus on the first focusable content within the popover when opened.
`closeOnEscape``true`
`boolean`
Whether to close the popover when the escape key is pressed.
`closeOnInteractOutside``true`
`boolean`
Whether to close the popover when the user clicks outside of the popover.
`lazyMount``false`
`boolean`
Whether to enable lazy mounting
`modal``false`
`boolean`
Whether the popover should be modal. When set to \`true\`: - interaction with outside elements will be disabled - only popover content will be visible to screen readers - scrolling is blocked - focus is trapped within the popover
`portalled``true`
`boolean`
Whether the popover is portalled. This will proxy the tabbing behavior regardless of the DOM position of the popover content.
`unmountOnExit``false`
`boolean`
Whether to unmount on exit.
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
`defaultOpen`
`boolean`
The initial open state of the popover when it is first rendered. Use when you do not need to control its open state.
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ anchor: string trigger: string content: string title: string description: string closeTrigger: string positioner: string arrow: string }>`
The ids of the elements in the popover. Useful for composition.
`immediate`
`boolean`
Whether to synchronize the present change immediately or defer it to the next frame
`initialFocusEl`
`() => HTMLElement | null`
The element to focus on when the popover is opened.
`onEscapeKeyDown`
`(event: KeyboardEvent) => void`
Function called when the escape key is pressed
`onExitComplete`
`() => void`
Function called when the animation ends in the closed state
`onFocusOutside`
`(event: FocusOutsideEvent) => void`
Function called when the focus is moved outside the component
`onInteractOutside`
`(event: InteractOutsideEvent) => void`
Function called when an interaction happens outside the component
`onOpenChange`
`(details: OpenChangeDetails) => void`
Function invoked when the popover opens or closes
`onPointerDownOutside`
`(event: PointerDownOutsideEvent) => void`
Function called when the pointer is pressed down outside the component
`open`
`boolean`
Whether the popover is open
`persistentElements`
`(() => Element | null)[]`
Returns the persistent elements that: - should not have pointer-events disabled - should not trigger the dismiss event
`positioning`
`PositioningOptions`
The user provided options used to position the popover content
`present`
`boolean`
Whether the node is present (controlled by the user)
`as`
`React.ElementType`
The underlying element to render.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Pin Input](https://www.chakra-ui.com/docs/components/pin-input)
[Next
\
Progress Circle](https://www.chakra-ui.com/docs/components/progress-circle) |
https://www.chakra-ui.com/docs/components/segmented-control | 1. Components
2. Segmented Control
# Segmented Control
Used to pick one choice from a linear set of options
[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-segmented-control--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/segmented-group.ts)[Ark](https://ark-ui.com/react/docs/components/segment-group)
PreviewCode
ReactVueSolid
```
import { SegmentedControl } from "@/components/ui/segmented-control"
const Demo = () => {
return (
<SegmentedControl defaultValue="React" items={["React", "Vue", "Solid"]} />
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `segmented-control` snippet
```
npx @chakra-ui/cli snippet add segmented-control
```
The snippet includes a closed component composition for the `SegmentGroup` component.
## [Usage]()
```
import { SegmentedControl } from "@/components/ui/segmented-control"
```
```
<SegmentedControl items={[]} />
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the segmented control.
PreviewCode
ReactVueSolid
size = xs
ReactVueSolid
size = sm
ReactVueSolid
size = md
ReactVueSolid
size = lg
```
import { For, Stack, Text, VStack } from "@chakra-ui/react"
import { SegmentedControl } from "@/components/ui/segmented-control"
const Demo = () => {
return (
<Stack gap="5" align="flex-start">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<VStack key={size} align="flex-start">
<SegmentedControl
size={size}
defaultValue="React"
items={["React", "Vue", "Solid"]}
/>
<Text>size = {size}</Text>
</VStack>
)}
</For>
</Stack>
)
}
```
### [Controlled]()
Use the `value` and `onValueChange` props to control the selected item.
PreviewCode
ReactVueSolid
```
"use client"
import { SegmentedControl } from "@/components/ui/segmented-control"
import { useState } from "react"
const Demo = () => {
const [value, setValue] = useState("React")
return (
<SegmentedControl
value={value}
onValueChange={(e) => setValue(e.value)}
items={["React", "Vue", "Solid"]}
/>
)
}
```
### [Hook Form]()
Here's an example of how to use the `SegmentedControl` with `react-hook-form`.
PreviewCode
Font size
smmdlg
Submit
```
"use client"
import { Button, Stack } from "@chakra-ui/react"
import { zodResolver } from "@hookform/resolvers/zod"
import { Field } from "@/components/ui/field"
import { SegmentedControl } from "@/components/ui/segmented-control"
import { Controller, useForm } from "react-hook-form"
import { z } from "zod"
const formSchema = z.object({
fontSize: z.string({ message: "Font size is required" }),
})
type FormValues = z.infer<typeof formSchema>
const Demo = () => {
const {
handleSubmit,
formState: { errors },
control,
} = useForm<FormValues>({
defaultValues: { fontSize: "md" },
resolver: zodResolver(formSchema),
})
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Stack gap="4" align="flex-start">
<Controller
control={control}
name="fontSize"
render={({ field }) => (
<Field
label="Font size"
invalid={!!errors.fontSize}
errorText={errors.fontSize?.message}
>
<SegmentedControl
onBlur={field.onBlur}
name={field.name}
value={field.value}
items={["sm", "md", "lg"]}
onValueChange={({ value }) => field.onChange(value)}
/>
</Field>
)}
/>
<Button size="sm" type="submit">
Submit
</Button>
</Stack>
</form>
)
}
```
### [Disabled]()
Use the `disabled` prop to disable the segmented control.
PreviewCode
ReactVueSolid
```
import { SegmentedControl } from "@/components/ui/segmented-control"
const Demo = () => {
return (
<SegmentedControl
disabled
defaultValue="React"
items={["React", "Vue", "Solid"]}
/>
)
}
```
### [Disabled Item]()
Use the `disabled` prop on the item to disable it.
PreviewCode
ReactVueSolid
```
import { SegmentedControl } from "@/components/ui/segmented-control"
const Demo = () => {
return (
<SegmentedControl
defaultValue="React"
items={[
{ label: "React", value: "React" },
{ label: "Vue", value: "Vue", disabled: true },
{ label: "Solid", value: "Solid" },
]}
/>
)
}
```
### [Icon]()
Render the `label` as a `ReactNode` to render an icon.
PreviewCode
Table
Board
List
```
import { HStack } from "@chakra-ui/react"
import { SegmentedControl } from "@/components/ui/segmented-control"
import { LuGrid, LuList, LuTable } from "react-icons/lu"
const Demo = () => {
return (
<SegmentedControl
defaultValue="table"
items={[
{
value: "table",
label: (
<HStack>
<LuTable />
Table
</HStack>
),
},
{
value: "board",
label: (
<HStack>
<LuGrid />
Board
</HStack>
),
},
{
value: "list",
label: (
<HStack>
<LuList />
List
</HStack>
),
},
]}
/>
)
}
```
### [Card]()
Here's an example of how to use the `SegmentedControl` within a `Card`.
PreviewCode
## Find your dream home
Bedrooms
Any1233+
Beds
Any122+
Bathrooms
Any123
Reset 20 results
```
import { Button, Card, Heading } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
import { SegmentedControl } from "@/components/ui/segmented-control"
import { LuSearch } from "react-icons/lu"
const Demo = () => {
return (
<Card.Root width="320px">
<Card.Header>
<Heading size="lg">Find your dream home</Heading>
</Card.Header>
<Card.Body gap="6">
<Field label="Bedrooms">
<SegmentedControl
defaultValue="Any"
items={["Any", "1", "2", "3", "3+"]}
/>
</Field>
<Field label="Beds">
<SegmentedControl defaultValue="1" items={["Any", "1", "2", "2+"]} />
</Field>
<Field label="Bathrooms">
<SegmentedControl defaultValue="3" items={["Any", "1", "2", "3"]} />
</Field>
</Card.Body>
<Card.Footer justifyContent="space-between" mt="3">
<Button variant="surface">Reset</Button>
<Button>
<LuSearch /> 20 results
</Button>
</Card.Footer>
</Card.Root>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'sm' | 'md' | 'lg'`
The size of the component
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultValue`
`string`
The initial value of the segment group when it is first rendered. Use when you do not need to control the state of the segment group.
`disabled`
`boolean`
If \`true\`, the radio group will be disabled
`form`
`string`
The associate form of the underlying input.
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ root: string label: string indicator: string item(value: string): string itemLabel(value: string): string itemControl(value: string): string itemHiddenInput(value: string): string }>`
The ids of the elements in the radio. Useful for composition.
`name`
`string`
The name of the input fields in the radio (Useful for form submission).
`onValueChange`
`(details: ValueChangeDetails) => void`
Function called once a radio is checked
`orientation`
`'horizontal' | 'vertical'`
Orientation of the radio group
`readOnly`
`boolean`
Whether the checkbox is read-only
`value`
`string`
The value of the checked radio
[Previous
\
Rating](https://www.chakra-ui.com/docs/components/rating)
[Next
\
Select (Native)](https://www.chakra-ui.com/docs/components/native-select) |
https://www.chakra-ui.com/docs/components/radio | 1. Components
2. Radio
# Radio
Used to select one option from several options
[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-radio--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/radio-group.ts)[Ark](https://ark-ui.com/react/docs/components/radio)
PreviewCode
Option 1Option 2Option 3
```
import { HStack } from "@chakra-ui/react"
import { Radio, RadioGroup } from "@/components/ui/radio"
const Demo = () => {
return (
<RadioGroup defaultValue="1">
<HStack gap="6">
<Radio value="1">Option 1</Radio>
<Radio value="2">Option 2</Radio>
<Radio value="3">Option 3</Radio>
</HStack>
</RadioGroup>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `radio` snippet
```
npx @chakra-ui/cli snippet add radio
```
The snippet includes a closed component composition for the `RadioGroup`
## [Usage]()
```
import { Radio, RadioGroup } from "@/components/ui/radio"
```
```
<RadioGroup>
<Radio />
</RadioGroup>
```
## [Examples]()
### [Controlled]()
Use the `value` and `onValueChange` prop to control the selected radio button
PreviewCode
Option 1Option 2Option 3
```
"use client"
import { HStack } from "@chakra-ui/react"
import { Radio, RadioGroup } from "@/components/ui/radio"
import { useState } from "react"
const Demo = () => {
const [value, setValue] = useState("1")
return (
<RadioGroup value={value} onValueChange={(e) => setValue(e.value)}>
<HStack gap="6">
<Radio value="1">Option 1</Radio>
<Radio value="2">Option 2</Radio>
<Radio value="3">Option 3</Radio>
</HStack>
</RadioGroup>
)
}
```
### [Colors]()
Use the `colorPalette` prop to change the color scheme of the component.
PreviewCode
gray
ReactVueSolid
red
ReactVueSolid
green
ReactVueSolid
blue
ReactVueSolid
teal
ReactVueSolid
pink
ReactVueSolid
purple
ReactVueSolid
cyan
ReactVueSolid
orange
ReactVueSolid
yellow
ReactVueSolid
```
import { HStack, Stack, Text } from "@chakra-ui/react"
import { colorPalettes } from "compositions/lib/color-palettes"
import { Radio, RadioGroup } from "@/components/ui/radio"
const Demo = () => {
return (
<Stack gap="2" align="flex-start">
{colorPalettes.map((colorPalette) => (
<HStack key={colorPalette} gap="10" px="4">
<Text minW="8ch">{colorPalette}</Text>
<RadioGroup
colorPalette={colorPalette}
defaultValue="react"
spaceX="8"
>
<Radio value="react">React</Radio>
<Radio value="vue">Vue</Radio>
<Radio value="solid">Solid</Radio>
</RadioGroup>
</HStack>
))}
</Stack>
)
}
```
### [Sizes]()
Use the `size` prop to change the size of the radio component.
PreviewCode
Radio (sm)
Radio (md)
Radio (lg)
```
import { HStack } from "@chakra-ui/react"
import { Radio, RadioGroup } from "@/components/ui/radio"
const Demo = () => {
return (
<HStack gap="4">
<RadioGroup size="sm">
<Radio value="react">Radio (sm)</Radio>
</RadioGroup>
<RadioGroup size="md">
<Radio value="react">Radio (md)</Radio>
</RadioGroup>
<RadioGroup size="lg">
<Radio value="react">Radio (lg)</Radio>
</RadioGroup>
</HStack>
)
}
```
### [Variants]()
Use the `variant` prop to change the appearance of the radio component.
PreviewCode
Radio (solid)Vue (solid)
Radio (outline)Vue (outline)
Radio (subtle)Vue (subtle)
```
import { For, Stack } from "@chakra-ui/react"
import { Radio, RadioGroup } from "@/components/ui/radio"
const Demo = () => {
return (
<Stack gap="4">
<For each={["solid", "outline", "subtle"]}>
{(variant) => (
<RadioGroup
key={variant}
variant={variant}
defaultValue="react"
spaceX="4"
colorPalette="teal"
>
<Radio value="react" minW="120px">
Radio ({variant})
</Radio>
<Radio value="vue">Vue ({variant})</Radio>
</RadioGroup>
)}
</For>
</Stack>
)
}
```
### [Disabled]()
Use the `disabled` prop to make the radio disabled.
PreviewCode
Option 1Option 2Option 3
```
import { HStack } from "@chakra-ui/react"
import { Radio, RadioGroup } from "@/components/ui/radio"
const Demo = () => {
return (
<RadioGroup defaultValue="2">
<HStack gap="6">
<Radio value="1" disabled>
Option 1
</Radio>
<Radio value="2">Option 2</Radio>
<Radio value="3">Option 3</Radio>
</HStack>
</RadioGroup>
)
}
```
### [Hook Form]()
Use the `Controller` component from `react-hook-form` to control the radio group withing a form
PreviewCode
Select value
Option 1Option 2Option 3
Submit
```
"use client"
import { Button, Fieldset, HStack } from "@chakra-ui/react"
import { zodResolver } from "@hookform/resolvers/zod"
import { Radio, RadioGroup } from "@/components/ui/radio"
import { Controller, useForm } from "react-hook-form"
import { z } from "zod"
const items = [
{ value: "1", label: "Option 1" },
{ value: "2", label: "Option 2" },
{ value: "3", label: "Option 3" },
]
const formSchema = z.object({
value: z.string({ message: "Value is required" }),
})
type FormValues = z.infer<typeof formSchema>
const Demo = () => {
const {
control,
handleSubmit,
formState: { errors },
} = useForm<FormValues>({
resolver: zodResolver(formSchema),
})
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Fieldset.Root invalid={!!errors.value}>
<Fieldset.Legend>Select value</Fieldset.Legend>
<Controller
name="value"
control={control}
render={({ field }) => (
<RadioGroup
name={field.name}
value={field.value}
onValueChange={({ value }) => {
field.onChange(value)
}}
>
<HStack gap="6">
{items.map((item) => (
<Radio
key={item.value}
value={item.value}
inputProps={{ onBlur: field.onBlur }}
>
{item.label}
</Radio>
))}
</HStack>
</RadioGroup>
)}
/>
{errors.value && (
<Fieldset.ErrorText>{errors.value?.message}</Fieldset.ErrorText>
)}
<Button size="sm" type="submit" alignSelf="flex-start">
Submit
</Button>
</Fieldset.Root>
</form>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`variant``'outline'`
`'outline' | 'subtle' | 'classic'`
The variant of the component
`size``'md'`
`'sm' | 'md' | 'lg'`
The size of the component
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultValue`
`string`
The initial value of the radio group when it is first rendered. Use when you do not need to control the state of the radio group.
`disabled`
`boolean`
If \`true\`, the radio group will be disabled
`form`
`string`
The associate form of the underlying input.
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ root: string label: string indicator: string item(value: string): string itemLabel(value: string): string itemControl(value: string): string itemHiddenInput(value: string): string }>`
The ids of the elements in the radio. Useful for composition.
`name`
`string`
The name of the input fields in the radio (Useful for form submission).
`onValueChange`
`(details: ValueChangeDetails) => void`
Function called once a radio is checked
`orientation`
`'horizontal' | 'vertical'`
Orientation of the radio group
`readOnly`
`boolean`
Whether the checkbox is read-only
`value`
`string`
The value of the checked radio
[Previous
\
Radio Card](https://www.chakra-ui.com/docs/components/radio-card)
[Next
\
Rating](https://www.chakra-ui.com/docs/components/rating) |
https://www.chakra-ui.com/docs/components/rating | 1. Components
2. Rating
# Rating
Used to show reviews and ratings in a visual format.
[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-rating--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/rating.ts)[Ark](https://ark-ui.com/react/docs/components/rating-group)
PreviewCode
```
import { Rating } from "@/components/ui/rating"
const Demo = () => {
return <Rating defaultValue={3} size="sm" />
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `rating` snippet
```
npx @chakra-ui/cli snippet add rating
```
The snippet includes a closed component composition for the `RatingGroup` component.
## [Usage]()
```
import { Rating } from "@/components/ui/rating"
```
```
<Rating />
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the rating component.
PreviewCode
```
import { Stack } from "@chakra-ui/react"
import { Rating } from "@/components/ui/rating"
const Demo = () => {
return (
<Stack>
<Rating defaultValue={3} size="xs" />
<Rating defaultValue={3} size="sm" />
<Rating defaultValue={3} size="md" />
<Rating defaultValue={3} size="lg" />
</Stack>
)
}
```
### [Controlled]()
Use the `value` and `onValueChange` prop to control the rating value.
PreviewCode
```
"use client"
import { Rating } from "@/components/ui/rating"
import { useState } from "react"
const Demo = () => {
const [value, setValue] = useState(3)
return <Rating value={value} onValueChange={(e) => setValue(e.value)} />
}
```
### [ReadOnly]()
Use the `readOnly` prop to make the rating component read-only.
PreviewCode
```
import { Rating } from "@/components/ui/rating"
const Demo = () => {
return <Rating readOnly defaultValue={3} size="sm" />
}
```
### [Hook Form]()
Here's an example of how to use rating with `react-hook-form`.
PreviewCode
Rating
Submit
```
"use client"
import { Button, Stack } from "@chakra-ui/react"
import { zodResolver } from "@hookform/resolvers/zod"
import { Field } from "@/components/ui/field"
import { Rating } from "@/components/ui/rating"
import { Controller, useForm } from "react-hook-form"
import { z } from "zod"
const formSchema = z.object({
rating: z.number({ required_error: "Rating is required" }).min(1).max(5),
})
type FormValues = z.infer<typeof formSchema>
const Demo = () => {
const {
handleSubmit,
formState: { errors },
control,
} = useForm<FormValues>({
resolver: zodResolver(formSchema),
})
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Stack gap="4" align="flex-start">
<Field
label="Rating"
invalid={!!errors.rating}
errorText={errors.rating?.message}
>
<Controller
control={control}
name="rating"
render={({ field }) => (
<Rating
name={field.name}
value={field.value}
onValueChange={({ value }) => field.onChange(value)}
/>
)}
/>
</Field>
<Button size="sm" type="submit">
Submit
</Button>
</Stack>
</form>
)
}
```
### [Custom Icon]()
Use the `icon` prop to pass a custom icon to the rating component. This will override the default star icon.
PreviewCode
```
import { Rating } from "@/components/ui/rating"
import { IoHeart } from "react-icons/io5"
const Demo = () => {
return (
<Rating
colorPalette="red"
icon={<IoHeart />}
allowHalf
count={5}
defaultValue={3.5}
/>
)
}
```
### [Half Star]()
Use the `allowHalf` prop to allow half-star ratings.
PreviewCode
```
import { Rating } from "@/components/ui/rating"
const Demo = () => {
return <Rating allowHalf defaultValue={3.5} />
}
```
### [Emoji]()
Compose the rating component with emojis.
PreviewCode
😡😠😐😊😍
```
import { RatingGroup } from "@chakra-ui/react"
const emojiMap: Record<string, string> = {
1: "😡",
2: "😠",
3: "😐",
4: "😊",
5: "😍",
}
const Demo = () => {
return (
<RatingGroup.Root defaultValue={3}>
<RatingGroup.Control>
{Array.from({ length: 5 }).map((_, index) => (
<RatingGroup.Item
key={index}
index={index + 1}
minW="9"
filter={{ base: "grayscale(1)", _checked: "revert" }}
transition="scale 0.1s"
_hover={{ scale: "1.1" }}
>
{emojiMap[index + 1]}
</RatingGroup.Item>
))}
</RatingGroup.Control>
</RatingGroup.Root>
)
}
```
### [Testimonial]()
Use the rating component to show testimonials.
PreviewCode
Sage is a great software engineer. He is very professional and knowledgeable.
MJ![](https://randomuser.me/api/portraits/men/70.jpg)
Matthew Jones
CTO, Company
```
import { HStack, Stack, Text } from "@chakra-ui/react"
import { Avatar } from "@/components/ui/avatar"
import { Rating } from "@/components/ui/rating"
const Demo = () => {
return (
<Stack maxW="320px" gap="4">
<Rating colorPalette="orange" readOnly size="xs" defaultValue={5} />
<Text>
Sage is a great software engineer. He is very professional and
knowledgeable.
</Text>
<HStack gap="4">
<Avatar
name="Matthew Jones"
src="https://randomuser.me/api/portraits/men/70.jpg"
/>
<Stack textStyle="sm" gap="0">
<Text fontWeight="medium">Matthew Jones</Text>
<Text color="fg.muted">CTO, Company</Text>
</Stack>
</HStack>
</Stack>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`count``'5'`
`number`
The total number of ratings.
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
`allowHalf`
`boolean`
Whether to allow half stars.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`autoFocus`
`boolean`
Whether to autofocus the rating.
`defaultValue`
`number`
The initial value of the rating group when it is first rendered. Use when you do not need to control the state of the rating group.
`disabled`
`boolean`
Whether the rating is disabled.
`form`
`string`
The associate form of the underlying input element.
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ root: string label: string hiddenInput: string control: string item(id: string): string }>`
The ids of the elements in the rating. Useful for composition.
`name`
`string`
The name attribute of the rating element (used in forms).
`onHoverChange`
`(details: HoverChangeDetails) => void`
Function to be called when the rating value is hovered.
`onValueChange`
`(details: ValueChangeDetails) => void`
Function to be called when the rating value changes.
`readOnly`
`boolean`
Whether the rating is readonly.
`required`
`boolean`
Whether the rating is required.
`translations`
`IntlTranslations`
Specifies the localized strings that identifies the accessibility elements and their states
`value`
`number`
The current rating value.
`as`
`React.ElementType`
The underlying element to render.
`unstyled`
`boolean`
Whether to remove the component's style.
### [Item]()
PropDefaultType`index`*
`number`
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
[Previous
\
Radio](https://www.chakra-ui.com/docs/components/radio)
[Next
\
Segmented Control](https://www.chakra-ui.com/docs/components/segmented-control) |
https://www.chakra-ui.com/docs/components/native-select | 1. Components
2. Select (Native)
# Select (Native)
Used to pick a value from predefined options.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/native-select)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-native-select--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/native-select.ts)
PreviewCode
Select optionReactVueAngularSvelte
```
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
const Demo = () => {
return (
<NativeSelectRoot size="sm" width="240px">
<NativeSelectField placeholder="Select option">
<option value="react">React</option>
<option value="vue">Vue</option>
<option value="angular">Angular</option>
<option value="svelte">Svelte</option>
</NativeSelectField>
</NativeSelectRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `native-select` snippet
```
npx @chakra-ui/cli snippet add native-select
```
The snippet includes a closed component composition for the `NativeSelect` component.
## [Usage]()
```
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
```
```
<NativeSelectRoot>
<NativeSelectField>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</NativeSelectField>
</NativeSelectRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the select component.
PreviewCode
size (xs)ReactVueAngularSvelte
size (sm)ReactVueAngularSvelte
size (md)ReactVueAngularSvelte
size (lg)ReactVueAngularSvelte
size (xl)ReactVueAngularSvelte
```
import { For, Stack } from "@chakra-ui/react"
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
const Demo = () => {
return (
<Stack gap="4" width="240px">
<For each={["xs", "sm", "md", "lg", "xl"]}>
{(size) => (
<NativeSelectRoot size={size} key={size}>
<NativeSelectField placeholder={`size (${size})`}>
<option value="react">React</option>
<option value="vue">Vue</option>
<option value="angular">Angular</option>
<option value="svelte">Svelte</option>
</NativeSelectField>
</NativeSelectRoot>
)}
</For>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to change the appearance of the select component.
PreviewCode
variant (outline)ReactVueAngularSvelte
variant (subtle)ReactVueAngularSvelte
variant (plain)ReactVueAngularSvelte
```
import { For, Stack } from "@chakra-ui/react"
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
const Demo = () => {
return (
<Stack gap="4" width="240px">
<For each={["outline", "subtle", "plain"]}>
{(variant) => (
<NativeSelectRoot variant={variant} key={variant}>
<NativeSelectField placeholder={`variant (${variant})`}>
<option value="react">React</option>
<option value="vue">Vue</option>
<option value="angular">Angular</option>
<option value="svelte">Svelte</option>
</NativeSelectField>
</NativeSelectRoot>
)}
</For>
</Stack>
)
}
```
### [Items Prop]()
Pass the `items` prop to the `NativeSelectField` component to render a list of options.
PreviewCode
Select optionReactVueAngularSvelte
```
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
const Demo = () => {
return (
<NativeSelectRoot size="sm" width="240px">
<NativeSelectField placeholder="Select option" items={items} />
</NativeSelectRoot>
)
}
const items = [
{ value: "react", label: "React" },
{ value: "vue", label: "Vue" },
{ value: "angular", label: "Angular" },
{ value: "svelte", label: "Svelte" },
]
```
### [Controlled]()
Use the `value` and `onChange` props to control the select component.
PreviewCode
Select optionReactVueAngularSvelte
```
"use client"
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
import { useState } from "react"
const Demo = () => {
const [value, setValue] = useState("")
return (
<NativeSelectRoot size="sm" width="240px">
<NativeSelectField
placeholder="Select option"
value={value}
onChange={(e) => setValue(e.currentTarget.value)}
>
<option value="react">React</option>
<option value="vue">Vue</option>
<option value="angular">Angular</option>
<option value="svelte">Svelte</option>
</NativeSelectField>
</NativeSelectRoot>
)
}
```
### [Hook Form]()
Here is an example of how to use the `NativeSelect` component with `react-hook-form`.
PreviewCode
Framework
Select frameworkReactVueAngularSvelte
Submit
```
"use client"
import { Button } from "@chakra-ui/react"
import { zodResolver } from "@hookform/resolvers/zod"
import { Field } from "@/components/ui/field"
import {
NativeSelectField,
NativeSelectRoot,
} from "@/components/ui/native-select"
import { useForm } from "react-hook-form"
import { z } from "zod"
const formSchema = z.object({
framework: z.string().min(1, { message: "Framework is required" }),
})
type FormValues = z.infer<typeof formSchema>
const Demo = () => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm<FormValues>({
resolver: zodResolver(formSchema),
})
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Field
label="Framework"
invalid={!!errors.framework}
errorText={errors.framework?.message}
>
<NativeSelectRoot size="sm" width="240px">
<NativeSelectField
{...register("framework")}
placeholder="Select framework"
items={["React", "Vue", "Angular", "Svelte"]}
/>
</NativeSelectRoot>
</Field>
<Button size="sm" type="submit" mt="4">
Submit
</Button>
</form>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`variant``'outline'`
`'outline' | 'filled' | 'plain'`
The variant of the component
`size``'md'`
`'lg' | 'md' | 'sm' | 'xs'`
The size of the component
`as`
`React.ElementType`
The underlying element to render.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Segmented Control](https://www.chakra-ui.com/docs/components/segmented-control)
[Next
\
Select](https://www.chakra-ui.com/docs/components/select) |
https://www.chakra-ui.com/docs/components/separator | 1. Components
2. Separator
# Separator
Used to visually separate content
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/separator)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-separator--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/separator.ts)
PreviewCode
First
Second
Third
```
import { Separator, Stack, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack>
<Text>First</Text>
<Separator />
<Text>Second</Text>
<Separator />
<Text>Third</Text>
</Stack>
)
}
```
## [Usage]()
```
import { Separator } from "@chakra-ui/react"
```
```
<Separator />
```
## [Examples]()
### [Variants]()
Use the `variant` prop to change the appearance of the separator.
PreviewCode
```
import { Separator, Stack } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack>
<Separator variant="solid" />
<Separator variant="dashed" />
<Separator variant="dotted" />
</Stack>
)
}
```
### [Sizes]()
Use the `size` prop to change the size of the separator.
PreviewCode
```
import { Separator, Stack } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack gap="4">
<Separator size="xs" />
<Separator size="sm" />
<Separator size="md" />
<Separator size="lg" />
</Stack>
)
}
```
### [Label]()
Use the `label` prop to add a label to the separator.
PreviewCode
Label (start)
Label (end)
Label (center)
```
import { HStack, Separator, Stack, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack>
<HStack>
<Text flexShrink="0">Label (start)</Text>
<Separator flex="1" />
</HStack>
<HStack>
<Separator flex="1" />
<Text flexShrink="0">Label (end)</Text>
</HStack>
<HStack>
<Separator />
<Text flexShrink="0">Label (center)</Text>
<Separator />
</HStack>
</Stack>
)
}
```
### [Vertical]()
Use the `orientation` prop to change the orientation of the separator.
PreviewCode
First
Second
```
import { HStack, Separator, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<HStack gap="4">
<Text>First</Text>
<Separator orientation="vertical" height="4" />
<Text>Second</Text>
</HStack>
)
}
```
## [Props]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`variant``'solid'`
`'solid' | 'dashed' | 'dotted'`
The variant of the component
`orientation``'horizontal'`
`'vertical' | 'horizontal'`
The orientation of the component
`size``'sm'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
[Previous
\
Select](https://www.chakra-ui.com/docs/components/select)
[Next
\
Skeleton](https://www.chakra-ui.com/docs/components/skeleton) |
https://www.chakra-ui.com/docs/components/skeleton | 1. Components
2. Skeleton
# Skeleton
Used to render a placeholder while the content is loading.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/skeleton)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-skeleton--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/skeleton.ts)
PreviewCode
```
import { HStack, Stack } from "@chakra-ui/react"
import { Skeleton, SkeletonCircle } from "@/components/ui/skeleton"
const Demo = () => {
return (
<HStack gap="5">
<SkeletonCircle size="12" />
<Stack flex="1">
<Skeleton height="5" />
<Skeleton height="5" width="80%" />
</Stack>
</HStack>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `skeleton` snippet
```
npx @chakra-ui/cli snippet add skeleton
```
The snippet includes components for skeleton text and circle using the `Skeleton` component.
## [Usage]()
```
import {
Skeleton,
SkeletonCircle,
SkeletonText,
} from "@/components/ui/skeleton"
```
```
<Stack gap="6" maxW="xs">
<HStack width="full">
<SkeletonCircle size="10" />
<SkeletonText noOfLines={2} />
</HStack>
<Skeleton height="200px" />
</Stack>
```
## [Examples]()
### [Feed]()
Use the `Skeleton` component to create a feed skeleton.
PreviewCode
```
import { HStack, Stack } from "@chakra-ui/react"
import {
Skeleton,
SkeletonCircle,
SkeletonText,
} from "@/components/ui/skeleton"
const Demo = () => {
return (
<Stack gap="6" maxW="xs">
<HStack width="full">
<SkeletonCircle size="10" />
<SkeletonText noOfLines={2} />
</HStack>
<Skeleton height="200px" />
</Stack>
)
}
```
### [Text]()
Use the `SkeletonText` component to create a skeleton for text.
PreviewCode
```
import { SkeletonText } from "@/components/ui/skeleton"
const Demo = () => {
return <SkeletonText noOfLines={3} gap="4" />
}
```
### [With Children]()
Use the `loading` prop to show the skeleton while the content is loading.
PreviewCode
Select
Select
```
import { Badge, HStack } from "@chakra-ui/react"
import { Skeleton } from "@/components/ui/skeleton"
const Demo = () => {
return (
<HStack gap="4">
<Skeleton asChild loading={true}>
<Badge>Select</Badge>
</Skeleton>
<Skeleton loading={false}>
<Badge>Select</Badge>
</Skeleton>
</HStack>
)
}
```
### [Variants]()
Use the `variant` prop to change the visual style of the Skeleton.
PreviewCode
pulse
shine
```
import { HStack, Stack, Text } from "@chakra-ui/react"
import { Skeleton } from "@/components/ui/skeleton"
const Demo = () => {
return (
<Stack gap="5">
<HStack gap="5">
<Text width="8ch">pulse</Text>
<Skeleton flex="1" height="5" variant="pulse" />
</HStack>
<HStack gap="5">
<Text width="8ch">shine</Text>
<Skeleton flex="1" height="5" variant="shine" />
</HStack>
</Stack>
)
}
```
### [Content Loading]()
When `loading` is changed to `false`, the Skeleton component will fade in.
PreviewCode
Chakra UI is cool
Toggle
```
"use client"
import { Stack, Text } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import { Skeleton } from "@/components/ui/skeleton"
import { useState } from "react"
const Demo = () => {
const [loading, setLoading] = useState(true)
return (
<Stack align="flex-start" gap="4">
<Skeleton height="6" loading={loading}>
<Text>Chakra UI is cool</Text>
</Skeleton>
<Button size="sm" onClick={() => setLoading((c) => !c)}>
Toggle
</Button>
</Stack>
)
}
```
## [Props]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`loading``true`
`'true' | 'false'`
The loading of the component
`variant``'pulse'`
`'pulse' | 'shine' | 'none'`
The variant of the component
[Previous
\
Separator](https://www.chakra-ui.com/docs/components/separator)
[Next
\
Slider](https://www.chakra-ui.com/docs/components/slider) |
https://www.chakra-ui.com/docs/components/pin-input | 1. Components
2. Pin Input
# Pin Input
Used to capture a pin code or otp from the user
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/pin-input)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-pin-input--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/pin-input.ts)[Ark](https://ark-ui.com/react/docs/components/pin-input)
PreviewCode
```
import { PinInput } from "@/components/ui/pin-input"
const Demo = () => {
return <PinInput />
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `pin-input` snippet
```
npx @chakra-ui/cli snippet add pin-input
```
The snippet includes a closed component composition for the `PinInput` component.
## [Usage]()
```
import { PinInput } from "@/components/ui/pin-input"
```
```
<PinInput />
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the pin input component.
PreviewCode
```
import { Stack } from "@chakra-ui/react"
import { PinInput } from "@/components/ui/pin-input"
const Demo = () => {
return (
<Stack gap="4">
<PinInput size="sm" />
<PinInput size="md" />
<PinInput size="lg" />
</Stack>
)
}
```
### [One time code]()
Use the `otp` prop to make the pin input component behave like a one-time code input. This helps improve the user experience when entering OTP codes.
PreviewCode
```
import { PinInput } from "@/components/ui/pin-input"
const Demo = () => {
return <PinInput otp />
}
```
### [Mask]()
Use the `mask` prop to obscure the entered pin code.
PreviewCode
```
import { PinInput } from "@/components/ui/pin-input"
const Demo = () => {
return <PinInput mask />
}
```
### [Placeholder]()
Use the `placeholder` prop to add a placeholder to the pin input component.
PreviewCode
```
import { PinInput } from "@/components/ui/pin-input"
const Demo = () => {
return <PinInput placeholder="🥳" />
}
```
### [Field]()
Here's an example of how to compose the `Field` and the `PinInput` components
PreviewCode
Enter otp
```
import { Field } from "@/components/ui/field"
import { PinInput } from "@/components/ui/pin-input"
const Demo = () => {
return (
<Field label="Enter otp">
<PinInput />
</Field>
)
}
```
### [Hook Form]()
Here's an example of how to compose the `Field` and the `PinInput` components with `react-hook-form`
PreviewCode
Submit
```
"use client"
import { Button, Stack } from "@chakra-ui/react"
import { zodResolver } from "@hookform/resolvers/zod"
import { Field } from "@/components/ui/field"
import { PinInput } from "@/components/ui/pin-input"
import { Controller, useForm } from "react-hook-form"
import { z } from "zod"
const formSchema = z.object({
pin: z
.array(z.string().min(1), { required_error: "Pin is required" })
.length(4, { message: "Pin must be 4 digits long" }),
})
type FormValues = z.infer<typeof formSchema>
const Demo = () => {
const { handleSubmit, control, formState } = useForm<FormValues>({
resolver: zodResolver(formSchema),
})
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Stack gap="4" align="flex-start" maxW="sm">
<Field
invalid={!!formState.errors.pin}
errorText={formState.errors.pin?.message}
>
<Controller
control={control}
name="pin"
render={({ field }) => (
<PinInput
value={field.value}
onValueChange={(e) => field.onChange(e.value)}
/>
)}
/>
</Field>
<Button type="submit">Submit</Button>
</Stack>
</form>
)
}
```
### [Controlled]()
Use the `value` and `onValueChange` props to control the value of the pin input
PreviewCode
```
"use client"
import { PinInput } from "@/components/ui/pin-input"
import { useState } from "react"
const Demo = () => {
const [value, setValue] = useState(["", "", "", ""])
return <PinInput value={value} onValueChange={(e) => setValue(e.value)} />
}
```
### [Attached]()
Use the `attached` prop to attach the pin input to the input field
PreviewCode
```
import { PinInput } from "@/components/ui/pin-input"
const Demo = () => {
return <PinInput attached />
}
```
### [Alphanumeric]()
Use the `type` prop to allow the user to enter alphanumeric characters. Values can be either `alphanumeric`, `numeric`, or `alphabetic`
PreviewCode
```
import { PinInput } from "@/components/ui/pin-input"
const Demo = () => {
return <PinInput type="alphanumeric" />
}
```
### [Without Snippet]()
If you don't want to use the snippet, you can use the `PinInput` component from the `@chakra-ui/react` package.
PreviewCode
Enter your OTP
```
import { PinInput } from "@chakra-ui/react"
const Demo = () => {
return (
<PinInput.Root>
<PinInput.Label>Enter your OTP</PinInput.Label>
<PinInput.HiddenInput />
<PinInput.Control>
{Array.from({ length: 4 }).map((_, index) => (
<PinInput.Input key={index} index={index} />
))}
</PinInput.Control>
</PinInput.Root>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`placeholder``'\'○\''`
`string`
The placeholder text for the input
`type``'\'numeric\''`
`'numeric' | 'alphabetic' | 'alphanumeric'`
The type of value the pin-input should allow
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'lg' | 'md' | 'sm' | 'xs'`
The size of the component
`variant``'outline'`
`'outline' | 'filled' | 'flushed'`
The variant of the component
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`autoFocus`
`boolean`
Whether to auto-focus the first input.
`blurOnComplete`
`boolean`
Whether to blur the input when the value is complete
`defaultValue`
`string[]`
The initial value of the pin input when it is first rendered. Use when you do not need to control the state of the pin input
`disabled`
`boolean`
Whether the inputs are disabled
`form`
`string`
The associate form of the underlying input element.
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ root: string hiddenInput: string label: string control: string input(id: string): string }>`
The ids of the elements in the pin input. Useful for composition.
`invalid`
`boolean`
Whether the pin input is in the invalid state
`mask`
`boolean`
If \`true\`, the input's value will be masked just like \`type=password\`
`name`
`string`
The name of the input element. Useful for form submission.
`onValueChange`
`(details: ValueChangeDetails) => void`
Function called on input change
`onValueComplete`
`(details: ValueChangeDetails) => void`
Function called when all inputs have valid values
`onValueInvalid`
`(details: ValueInvalidDetails) => void`
Function called when an invalid value is entered
`otp`
`boolean`
If \`true\`, the pin input component signals to its fields that they should use \`autocomplete="one-time-code"\`.
`pattern`
`string`
The regular expression that the user-entered input value is checked against.
`readOnly`
`boolean`
Whether the pin input is in the valid state
`required`
`boolean`
Whether the pin input is required
`selectOnFocus`
`boolean`
Whether to select input value when input is focused
`translations`
`IntlTranslations`
Specifies the localized strings that identifies the accessibility elements and their states
`value`
`string[]`
The value of the the pin input.
[Previous
\
Password Input](https://www.chakra-ui.com/docs/components/password-input)
[Next
\
Popover](https://www.chakra-ui.com/docs/components/popover) |
https://www.chakra-ui.com/docs/components/slider | 1. Components
2. Slider
# Slider
Used to allow users to make selections from a range of values.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/slider)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-slider--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/slider.ts)[Ark](https://ark-ui.com/react/docs/components/slider)
PreviewCode
```
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return <Slider width="200px" defaultValue={[40]} />
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `slider` snippet
```
npx @chakra-ui/cli snippet add slider
```
The snippet includes a closed component composition for the `Slider` component.
## [Usage]()
```
import { Slider } from "@/components/ui/slider"
```
```
<Slider defaultValue={[40]} />
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the slider.
PreviewCode
slider - sm
slider - md
slider - lg
```
import { Stack } from "@chakra-ui/react"
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return (
<Stack width="200px" gap="4">
<Slider defaultValue={[40]} size="sm" label="slider - sm" />
<Slider defaultValue={[40]} size="md" label="slider - md" />
<Slider defaultValue={[40]} size="lg" label="slider - lg" />
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to change the visual style of the slider.
PreviewCode
slider - outline
slider - solid
```
import { Stack } from "@chakra-ui/react"
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return (
<Stack width="200px" gap="4">
<Slider defaultValue={[40]} variant="outline" label="slider - outline" />
<Slider defaultValue={[40]} variant="solid" label="slider - solid" />
</Stack>
)
}
```
### [Colors]()
Use the `colorPalette` prop to change the color of the slider.
PreviewCode
```
import { Stack } from "@chakra-ui/react"
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return (
<Stack gap="4" align="flex-start">
<Slider width="200px" colorPalette="gray" defaultValue={[40]} />
<Slider width="200px" colorPalette="blue" defaultValue={[40]} />
<Slider width="200px" colorPalette="red" defaultValue={[40]} />
<Slider width="200px" colorPalette="green" defaultValue={[40]} />
<Slider width="200px" colorPalette="pink" defaultValue={[40]} />
<Slider width="200px" colorPalette="teal" defaultValue={[40]} />
<Slider width="200px" colorPalette="purple" defaultValue={[40]} />
<Slider width="200px" colorPalette="cyan" defaultValue={[40]} />
</Stack>
)
}
```
### [Label]()
Use the `label` prop to add a label to the slider.
PreviewCode
Quantity
```
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return <Slider label="Quantity" width="200px" defaultValue={[40]} />
}
```
### [Range Slider]()
Set the `value` or `defaultValue` prop to an array to create a range slider.
PreviewCode
```
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return <Slider width="200px" defaultValue={[30, 60]} />
}
```
### [Controlled]()
Use the `value` and `onValueChange` props to control the value of the slider.
PreviewCode
```
"use client"
import { Slider } from "@/components/ui/slider"
import { useState } from "react"
const Demo = () => {
const [value, setValue] = useState([40])
return (
<Slider
maxW="200px"
value={value}
onValueChange={(e) => setValue(e.value)}
/>
)
}
```
### [Hook Form]()
Here's an example of how to integrate a slider with `react-hook-form`.
PreviewCode
Slider: 40
Submit
```
"use client"
import { Stack } from "@chakra-ui/react"
import { zodResolver } from "@hookform/resolvers/zod"
import { Button } from "@/components/ui/button"
import { Field } from "@/components/ui/field"
import { Slider } from "@/components/ui/slider"
import { Controller, useForm } from "react-hook-form"
import { z } from "zod"
const formSchema = z.object({
value: z.array(
z
.number({ message: "Value is required" })
.min(60, { message: "Value must be greater than 60" }),
),
})
type FormValues = z.infer<typeof formSchema>
const Demo = () => {
const {
control,
handleSubmit,
formState: { errors },
} = useForm<FormValues>({
resolver: zodResolver(formSchema),
defaultValues: { value: [40] },
})
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Stack align="flex-start" gap="4" maxW="300px">
<Controller
name="value"
control={control}
render={({ field }) => (
<Field
label={`Slider: ${field.value[0]}`}
invalid={!!errors.value?.length}
errorText={errors.value?.[0]?.message}
>
<Slider
width="full"
onFocusChange={({ focusedIndex }) => {
if (focusedIndex !== -1) return
field.onBlur()
}}
name={field.name}
value={field.value}
onValueChange={({ value }) => {
field.onChange(value)
}}
/>
</Field>
)}
/>
<Button size="sm" type="submit">
Submit
</Button>
</Stack>
</form>
)
}
```
### [Disabled]()
Use the `disabled` prop to disable the slider.
PreviewCode
```
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return <Slider width="200px" disabled defaultValue={[40]} />
}
```
### [Change End]()
Use the `onValueChangeEnd` prop to listen to the end of the slider change.
PreviewCode
`onChange: 50onChangeEnd: 50`
```
"use client"
import { Box, Code, Stack } from "@chakra-ui/react"
import { Slider } from "@/components/ui/slider"
import { useState } from "react"
const initialValue = [50]
const Demo = () => {
const [value, setValue] = useState(initialValue)
const [endValue, setEndValue] = useState(initialValue)
return (
<Box maxW="240px">
<Slider
value={value}
onValueChange={(e) => setValue(e.value)}
onValueChangeEnd={(e) => setEndValue(e.value)}
/>
<Stack mt="3" gap="1">
<Code>
onChange: <b>{value}</b>
</Code>
<Code>
onChangeEnd: <b>{endValue}</b>
</Code>
</Stack>
</Box>
)
}
```
### [Steps]()
Use the `step` prop to set the step value of the slider.
PreviewCode
```
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return <Slider width="200px" defaultValue={[40]} step={10} />
}
```
### [Thumb Contained]()
Use the `thumbAlignment` and `thumbSize` prop to contain the thumb within the track.
PreviewCode
```
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return (
<Slider
width="200px"
thumbAlignment="contain"
thumbSize={{ width: 16, height: 16 }}
defaultValue={[40]}
/>
)
}
```
### [Marks]()
Use the `marks` prop to display marks on the slider.
PreviewCode
size = sm
size = md
size = lg
```
import { For, Stack, Text, VStack } from "@chakra-ui/react"
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return (
<Stack gap="4">
<For each={["sm", "md", "lg"]}>
{(size) => (
<VStack key={size} align="flex-start">
<Slider
key={size}
size={size}
width="200px"
colorPalette="pink"
defaultValue={[40]}
marks={[0, 50, 100]}
/>
<Text>size = {size}</Text>
</VStack>
)}
</For>
</Stack>
)
}
```
You can also add labels to the marks using the `marks` prop.
PreviewCode
0%
50%
100%
```
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return (
<Slider
size="md"
width="200px"
colorPalette="pink"
defaultValue={[40]}
marks={[
{ value: 0, label: "0%" },
{ value: 50, label: "50%" },
{ value: 100, label: "100%" },
]}
/>
)
}
```
### [Vertical]()
Use the `orientation` prop to change the orientation of the slider.
PreviewCode
```
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return <Slider height="200px" orientation="vertical" defaultValue={[40]} />
}
```
### [Vertical with Marks]()
Here's an example of a vertical slider with marks.
PreviewCode
0%
50%
100%
```
import { Slider } from "@/components/ui/slider"
const Demo = () => {
return (
<Slider
height="200px"
orientation="vertical"
colorPalette="pink"
defaultValue={[40]}
marks={[
{ value: 0, label: "0%" },
{ value: 50, label: "50%" },
{ value: 100, label: "100%" },
]}
/>
)
}
```
## [Props]()
PropDefaultType`max``'100'`
`number`
The maximum value of the slider
`min``'0'`
`number`
The minimum value of the slider
`minStepsBetweenThumbs``'0'`
`number`
The minimum permitted steps between multiple thumbs.
`orientation``'horizontal'`
`'vertical' | 'horizontal'`
The orientation of the component
`origin``'\'start\''`
`'center' | 'start'`
The origin of the slider range - "start": Useful when the value represents an absolute value - "center": Useful when the value represents an offset (relative)
`step``'1'`
`number`
The step value of the slider
`thumbAlignment``'\'contain\''`
`'center' | 'contain'`
The alignment of the slider thumb relative to the track - \`center\`: the thumb will extend beyond the bounds of the slider track. - \`contain\`: the thumb will be contained within the bounds of the track.
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
`variant``'outline'`
`'outline' | 'subtle'`
The variant of the component
`aria-label`
`string[]`
The aria-label of each slider thumb. Useful for providing an accessible name to the slider
`aria-labelledby`
`string[]`
The \`id\` of the elements that labels each slider thumb. Useful for providing an accessible name to the slider
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultValue`
`number[]`
The initial value of the slider when it is first rendered. Use when you do not need to control the state of the slider picker.
`disabled`
`boolean`
Whether the slider is disabled
`form`
`string`
The associate form of the underlying input element.
`getAriaValueText`
`(details: ValueTextDetails) => string`
Function that returns a human readable value for the slider thumb
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ root: string thumb(index: number): string hiddenInput(index: number): string control: string track: string range: string label: string valueText: string marker(index: number): string }>`
The ids of the elements in the range slider. Useful for composition.
`invalid`
`boolean`
Whether the slider is invalid
`name`
`string`
The name associated with each slider thumb (when used in a form)
`onFocusChange`
`(details: FocusChangeDetails) => void`
Function invoked when the slider's focused index changes
`onValueChange`
`(details: ValueChangeDetails) => void`
Function invoked when the value of the slider changes
`onValueChangeEnd`
`(details: ValueChangeDetails) => void`
Function invoked when the slider value change is done
`readOnly`
`boolean`
Whether the slider is read-only
`thumbSize`
`{ width: number; height: number }`
The slider thumbs dimensions
`value`
`number[]`
The value of the range slider
[Previous
\
Skeleton](https://www.chakra-ui.com/docs/components/skeleton)
[Next
\
Spinner](https://www.chakra-ui.com/docs/components/spinner) |
https://www.chakra-ui.com/docs/components/spinner | 1. Components
2. Spinner
# Spinner
Used to provide a visual cue that an action is processing
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/spinner)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-spinner--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/spinner.ts)
PreviewCode
```
import { Spinner } from "@chakra-ui/react"
const Demo = () => {
return <Spinner size="sm" />
}
```
## [Usage]()
```
import { Spinner } from "@chakra-ui/react"
```
```
<Spinner />
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the spinner.
PreviewCode
```
import { HStack, Spinner } from "@chakra-ui/react"
const Demo = () => {
return (
<HStack gap="5">
<Spinner size="xs" />
<Spinner size="sm" />
<Spinner size="md" />
<Spinner size="lg" />
<Spinner size="xl" />
</HStack>
)
}
```
### [Colors]()
Use the `colorPalette` prop to change the color scheme of the spinner.
PreviewCode
```
import { Spinner, Stack } from "@chakra-ui/react"
import { colorPalettes } from "compositions/lib/color-palettes"
const Demo = () => {
return (
<Stack gap="2" align="flex-start">
{colorPalettes.map((colorPalette) => (
<Stack
align="center"
key={colorPalette}
direction="row"
gap="10"
px="4"
>
<Spinner
size="sm"
color="colorPalette.600"
colorPalette={colorPalette}
/>
<Spinner
size="md"
color="colorPalette.600"
colorPalette={colorPalette}
/>
<Spinner
size="lg"
color="colorPalette.600"
colorPalette={colorPalette}
/>
</Stack>
))}
</Stack>
)
}
```
### [Custom Color]()
Use the `color` prop to pass a custom color to the spinner.
PreviewCode
```
import { Spinner } from "@chakra-ui/react"
const Demo = () => {
return <Spinner color="teal.500" size="lg" />
}
```
### [Track Color]()
Use the `--spinner-track-color` variable to change the color of the spinner's track.
PreviewCode
```
import { Spinner } from "@chakra-ui/react"
export const SpinnerWithTrackColor = () => (
<Spinner
color="red.500"
css={{ "--spinner-track-color": "colors.gray.200" }}
/>
)
```
### [Custom Speed]()
Use the `animationDuration` prop to change the speed of the spinner.
PreviewCode
```
import { Spinner } from "@chakra-ui/react"
export const SpinnerWithCustomSpeed = () => (
<Spinner color="blue.500" animationDuration="0.8s" />
)
```
### [Thickness]()
Use the `borderWidth` prop to change the thickness of the spinner.
PreviewCode
```
import { Spinner } from "@chakra-ui/react"
export const SpinnerWithCustomThickness = () => (
<Spinner color="blue.500" borderWidth="4px" />
)
```
### [Label]()
Compose the spinner with a label to provide additional context.
PreviewCode
Loading...
```
import { Spinner, Text, VStack } from "@chakra-ui/react"
const Demo = () => {
return (
<VStack colorPalette="teal">
<Spinner color="colorPalette.600" />
<Text color="colorPalette.600">Loading...</Text>
</VStack>
)
}
```
### [Overlay]()
Compose spinner with the `AbsoluteCenter` component to overlay the spinner on top of another component.
PreviewCode
## Some heading text
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac consectetur libero, id ultricies urna. Sed ac consectetur libero, id fames ac ante ipsum primis in faucibus.
```
import { Box, Center, Heading, Spinner, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Box position="relative" aria-busy="true" userSelect="none">
<Heading>Some heading text</Heading>
<Text>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac
consectetur libero, id ultricies urna. Sed ac consectetur libero, id
fames ac ante ipsum primis in faucibus.
</Text>
<Box pos="absolute" inset="0" bg="bg/80">
<Center h="full">
<Spinner color="teal.500" />
</Center>
</Box>
</Box>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg' | 'xl'`
The size of the component
[Previous
\
Slider](https://www.chakra-ui.com/docs/components/slider)
[Next
\
Stat](https://www.chakra-ui.com/docs/components/stat) |
https://www.chakra-ui.com/docs/components/status | 1. Components
2. Status
# Status
Used to indicate the status of a process or state
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/status)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-status--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/status.ts)
PreviewCode
```
import { HStack } from "@chakra-ui/react"
import { Status } from "@/components/ui/status"
const Demo = () => {
return (
<HStack gap="6">
<Status value="error" />
<Status value="info" />
<Status value="warning" />
<Status value="success" />
</HStack>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `status` snippet
```
npx @chakra-ui/cli snippet add status
```
The snippet includes a closed component composition for the `Status` component.
## [Usage]()
```
import { Status } from "@/components/ui/status"
```
```
<Status>Label</Status>
```
## [Examples]()
### [Label]()
Render the label within the status component.
PreviewCode
Error
Info
Warning
Success
```
import { HStack } from "@chakra-ui/react"
import { Status } from "@/components/ui/status"
const Demo = () => {
return (
<HStack gap="6">
<Status value="error">Error</Status>
<Status value="info">Info</Status>
<Status value="warning">Warning</Status>
<Status value="success">Success</Status>
</HStack>
)
}
```
### [Sizes]()
Use the `size` prop to change the size of the status component.
PreviewCode
In Review
Error
Approved
In Review
Error
Approved
In Review
Error
Approved
```
import { For, HStack, Stack } from "@chakra-ui/react"
import { Status } from "@/components/ui/status"
const Demo = () => {
return (
<Stack gap="2" align="flex-start">
<For each={["sm", "md", "lg"]}>
{(size) => (
<HStack key={size} gap="10" px="4">
<Status size={size} width="100px" value="warning">
In Review
</Status>
<Status size={size} width="100px" value="error">
Error
</Status>
<Status size={size} width="100px" value="success">
Approved
</Status>
</HStack>
)}
</For>
</Stack>
)
}
```
## [Props]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'sm' | 'md' | 'lg'`
The size of the component
[Previous
\
Stat](https://www.chakra-ui.com/docs/components/stat)
[Next
\
Steps](https://www.chakra-ui.com/docs/components/steps) |
https://www.chakra-ui.com/docs/components/select | 1. Components
2. Select
# Select
Used to pick a value from predefined options.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/select)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-select--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/select.ts)[Ark](https://ark-ui.com/react/docs/components/select)
PreviewCode
Select framework
Select movie
React.js
Vue.js
Angular
Svelte
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const Demo = () => {
return (
<SelectRoot collection={frameworks} size="sm" width="320px">
<SelectLabel>Select framework</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent>
{frameworks.items.map((movie) => (
<SelectItem item={movie} key={movie.value}>
{movie.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)
}
const frameworks = createListCollection({
items: [
{ label: "React.js", value: "react" },
{ label: "Vue.js", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
],
})
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `select` snippet
```
npx @chakra-ui/cli snippet add select
```
The snippet includes a closed component composition for the `Select` component.
## [Usage]()
```
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
```
```
<SelectRoot>
<SelectLabel />
<SelectTrigger>
<SelectValueText />
</SelectTrigger>
<SelectContent>
<SelectItem />
</SelectContent>
</SelectRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the select component.
PreviewCode
size = xs
Select movie
React.js
Vue.js
Angular
Svelte
size = sm
Select movie
React.js
Vue.js
Angular
Svelte
size = md
Select movie
React.js
Vue.js
Angular
Svelte
size = lg
Select movie
React.js
Vue.js
Angular
Svelte
```
"use client"
import { For, Stack, createListCollection } from "@chakra-ui/react"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const Demo = () => {
return (
<Stack gap="5" width="320px">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<SelectRoot key={size} size={size} collection={frameworks}>
<SelectLabel>size = {size}</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent>
{frameworks.items.map((movie) => (
<SelectItem item={movie} key={movie.value}>
{movie.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)}
</For>
</Stack>
)
}
const frameworks = createListCollection({
items: [
{ label: "React.js", value: "react" },
{ label: "Vue.js", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
],
})
```
### [Variants]()
Use the `variant` prop to change the appearance of the select component.
PreviewCode
Select framework - outline
Select movie
React.js
Vue.js
Angular
Svelte
Select framework - subtle
Select movie
React.js
Vue.js
Angular
Svelte
```
"use client"
import { For, Stack, createListCollection } from "@chakra-ui/react"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const Demo = () => {
return (
<Stack gap="5" width="320px">
<For each={["outline", "subtle"]}>
{(variant) => (
<SelectRoot key={variant} variant={variant} collection={frameworks}>
<SelectLabel>Select framework - {variant}</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent>
{frameworks.items.map((movie) => (
<SelectItem item={movie} key={movie.value}>
{movie.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)}
</For>
</Stack>
)
}
const frameworks = createListCollection({
items: [
{ label: "React.js", value: "react" },
{ label: "Vue.js", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
],
})
```
### [Option Group]()
Use the `SelectItemGroup` component to group select options.
PreviewCode
Select framework
Select movie
Anime
Naruto
One Piece
Dragon Ball
Movies
The Shawshank Redemption
The Godfather
The Dark Knight
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import {
SelectContent,
SelectItem,
SelectItemGroup,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const Demo = () => {
return (
<SelectRoot collection={frameworks} size="sm" width="320px">
<SelectLabel>Select framework</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent>
{categories.map((category) => (
<SelectItemGroup key={category.group} label={category.group}>
{category.items.map((item) => (
<SelectItem item={item} key={item.value}>
{item.label}
</SelectItem>
))}
</SelectItemGroup>
))}
</SelectContent>
</SelectRoot>
)
}
const frameworks = createListCollection({
items: [
{ label: "Naruto", value: "naruto", group: "Anime" },
{ label: "One Piece", value: "one-piece", group: "Anime" },
{ label: "Dragon Ball", value: "dragon-ball", group: "Anime" },
{
label: "The Shawshank Redemption",
value: "the-shawshank-redemption",
group: "Movies",
},
{ label: "The Godfather", value: "the-godfather", group: "Movies" },
{ label: "The Dark Knight", value: "the-dark-knight", group: "Movies" },
],
})
const categories = frameworks.items.reduce(
(acc, item) => {
const group = acc.find((group) => group.group === item.group)
if (group) {
group.items.push(item)
} else {
acc.push({ group: item.group, items: [item] })
}
return acc
},
[] as { group: string; items: (typeof frameworks)["items"] }[],
)
```
### [Controlled]()
Use the `value` and `onValueChange` props to control the select component.
PreviewCode
Select framework
Select movie
React.js
Vue.js
Angular
Svelte
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
import { useState } from "react"
const Demo = () => {
const [value, setValue] = useState<string[]>([])
return (
<SelectRoot
collection={frameworks}
width="320px"
value={value}
onValueChange={(e) => setValue(e.value)}
>
<SelectLabel>Select framework</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent>
{frameworks.items.map((movie) => (
<SelectItem item={movie} key={movie.value}>
{movie.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)
}
const frameworks = createListCollection({
items: [
{ label: "React.js", value: "react" },
{ label: "Vue.js", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
],
})
```
### [Async Loading]()
Here's an example of how to populate the select `collection` from a remote source.
PreviewCode
Select pokemon
Pokemon
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
import { useMemo } from "react"
import { useAsync } from "react-use"
interface Item {
name: string
url: string
}
const Demo = () => {
const state = useAsync(async (): Promise<Item[]> => {
const response = await fetch(`https://pokeapi.co/api/v2/pokemon`)
const data = await response.json()
return data.results
}, [])
const pokemons = useMemo(() => {
return createListCollection({
items: state.value || [],
itemToString: (item) => item.name,
itemToValue: (item) => item.name,
})
}, [state.value])
return (
<SelectRoot collection={pokemons} size="sm" width="320px">
<SelectLabel>Select pokemon</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Pokemon" />
</SelectTrigger>
<SelectContent>
{pokemons.items.map((pokemon) => (
<SelectItem item={pokemon} key={pokemon.name}>
{pokemon.name}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)
}
```
### [Hook Form]()
Here's an example of how to use the `Select` component with `react-hook-form`.
PreviewCode
Rating
Select movie
React.js
Vue.js
Angular
Svelte
Submit
```
"use client"
import { Button, Stack, createListCollection } from "@chakra-ui/react"
import { zodResolver } from "@hookform/resolvers/zod"
import { Field } from "@/components/ui/field"
import {
SelectContent,
SelectItem,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
import { Controller, useForm } from "react-hook-form"
import { z } from "zod"
const formSchema = z.object({
framework: z.string({ message: "Framework is required" }).array(),
})
type FormValues = z.infer<typeof formSchema>
const Demo = () => {
const {
handleSubmit,
formState: { errors },
control,
} = useForm<FormValues>({
resolver: zodResolver(formSchema),
})
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Stack gap="4" align="flex-start">
<Field
label="Rating"
invalid={!!errors.framework}
errorText={errors.framework?.message}
width="320px"
>
<Controller
control={control}
name="framework"
render={({ field }) => (
<SelectRoot
name={field.name}
value={field.value}
onValueChange={({ value }) => field.onChange(value)}
onInteractOutside={() => field.onBlur()}
collection={frameworks}
>
<SelectTrigger>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent>
{frameworks.items.map((movie) => (
<SelectItem item={movie} key={movie.value}>
{movie.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)}
/>
</Field>
<Button size="sm" type="submit">
Submit
</Button>
</Stack>
</form>
)
}
const frameworks = createListCollection({
items: [
{ label: "React.js", value: "react" },
{ label: "Vue.js", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
],
})
```
### [Disabled]()
Use the `disabled` prop to disable the select component.
PreviewCode
Select framework
Select movie
React.js
Vue.js
Angular
Svelte
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const Demo = () => {
return (
<SelectRoot disabled collection={frameworks} size="sm" width="320px">
<SelectLabel>Select framework</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent>
{frameworks.items.map((movie) => (
<SelectItem item={movie} key={movie.value}>
{movie.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)
}
const frameworks = createListCollection({
items: [
{ label: "React.js", value: "react" },
{ label: "Vue.js", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
],
})
```
### [Invalid]()
Here's an example of how to compose the `Select` component with the `Field` component to display an error state.
PreviewCode
Select framework
Select movie
React.js
Vue.js
Angular
Svelte
This is an error
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const Demo = () => {
return (
<Field invalid errorText="This is an error">
<SelectRoot collection={frameworks} size="sm" width="320px">
<SelectLabel>Select framework</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent>
{frameworks.items.map((movie) => (
<SelectItem item={movie} key={movie.value}>
{movie.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
</Field>
)
}
const frameworks = createListCollection({
items: [
{ label: "React.js", value: "react" },
{ label: "Vue.js", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
],
})
```
### [Multiple]()
Use the `multiple` prop to allow multiple selections.
PreviewCode
Select framework
Movie
React.js
Vue.js
Angular
Svelte
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const Demo = () => {
return (
<SelectRoot multiple collection={frameworks} size="sm" width="320px">
<SelectLabel>Select framework</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Movie" />
</SelectTrigger>
<SelectContent>
{frameworks.items.map((movie) => (
<SelectItem item={movie} key={movie.value}>
{movie.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)
}
const frameworks = createListCollection({
items: [
{ label: "React.js", value: "react" },
{ label: "Vue.js", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
],
})
```
### [Positioning]()
Use the `positioning` prop to control the underlying `floating-ui` options of the select component.
PreviewCode
Select framework
Select movie
React.js
Vue.js
Angular
Svelte
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const Demo = () => {
return (
<SelectRoot
collection={frameworks}
size="sm"
width="320px"
positioning={{ placement: "top", flip: false }}
>
<SelectLabel>Select framework</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent>
{frameworks.items.map((movie) => (
<SelectItem item={movie} key={movie.value}>
{movie.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)
}
const frameworks = createListCollection({
items: [
{ label: "React.js", value: "react" },
{ label: "Vue.js", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
],
})
```
### [Within Popover]()
Here's an example of how to use the `Select` within a `Popover` component.
PreviewCode
Select in Popover
Select
React.js
Vue.js
Angular
Svelte
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
PopoverBody,
PopoverContent,
PopoverHeader,
PopoverRoot,
PopoverTrigger,
} from "@/components/ui/popover"
import {
SelectContent,
SelectItem,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const Demo = () => {
return (
<PopoverRoot size="xs">
<PopoverTrigger asChild>
<Button variant="outline" size="sm">
Select in Popover
</Button>
</PopoverTrigger>
<PopoverContent>
<PopoverHeader>Select in Popover</PopoverHeader>
<PopoverBody>
<SelectRoot
collection={frameworks}
size="sm"
positioning={{ sameWidth: true, placement: "bottom" }}
>
<SelectTrigger>
<SelectValueText placeholder="Select" />
</SelectTrigger>
<SelectContent portalled={false} width="full">
{frameworks.items.map((item) => (
<SelectItem item={item} key={item.value}>
{item.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
</PopoverBody>
</PopoverContent>
</PopoverRoot>
)
}
const frameworks = createListCollection({
items: [
{ label: "React.js", value: "react" },
{ label: "Vue.js", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
],
})
```
### [Within Dialog]()
Here's an example of how to use the `Select` within a `Dialog` component.
Due to the focus trap within the dialog, it's important to change the portal target from the document's body to the dialog's content.
PreviewCode
Open Dialog
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
DialogBackdrop,
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
import { useRef } from "react"
const Demo = () => {
const contentRef = useRef<HTMLDivElement>(null)
return (
<DialogRoot>
<DialogBackdrop />
<DialogTrigger asChild>
<Button variant="outline">Open Dialog</Button>
</DialogTrigger>
<DialogContent ref={contentRef}>
<DialogCloseTrigger />
<DialogHeader>
<DialogTitle>Select in Dialog</DialogTitle>
</DialogHeader>
<DialogBody>
<SelectRoot collection={frameworks} size="sm">
<SelectLabel>Select framework</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent portalRef={contentRef}>
{frameworks.items.map((item) => (
<SelectItem item={item} key={item.value}>
{item.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
</DialogBody>
<DialogFooter />
</DialogContent>
</DialogRoot>
)
}
const frameworks = createListCollection({
items: [
{ label: "React.js", value: "react" },
{ label: "Vue.js", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
],
})
```
### [Avatar Select]()
Here's an example of how to compose the `Select` and the `Avatar`.
PreviewCode
Select member
JJ![](https://images.unsplash.com/photo-1531746020798-e6953c6e8e04?w=100)
Jessica Jones
JJ![](https://images.unsplash.com/photo-1531746020798-e6953c6e8e04?w=100)
Jessica Jones
KJ![](https://images.unsplash.com/photo-1523477800337-966dbabe060b?w=100)
Kenneth Johnson
KW![](https://images.unsplash.com/photo-1609712409631-dbbb050746d1?w=100)
Kate Wilson
```
"use client"
import { HStack, createListCollection } from "@chakra-ui/react"
import { Avatar } from "@/components/ui/avatar"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const SelectValueItem = () => (
<SelectValueText placeholder="Select movie">
{(items: Array<{ name: string; avatar: string }>) => {
const { name, avatar } = items[0]
return (
<HStack>
<Avatar name={name} size="xs" src={avatar} />
{name}
</HStack>
)
}}
</SelectValueText>
)
const Demo = () => {
return (
<SelectRoot
collection={members}
size="sm"
width="240px"
defaultValue={["jessica_jones"]}
positioning={{ sameWidth: true }}
>
<SelectLabel>Select member</SelectLabel>
<SelectTrigger>
<SelectValueItem />
</SelectTrigger>
<SelectContent portalled={false}>
{members.items.map((item) => (
<SelectItem item={item} key={item.id} justifyContent="flex-start">
<Avatar name={item.name} src={item.avatar} size="xs" />
{item.name}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)
}
const members = createListCollection({
items: [
{
name: "Jessica Jones",
id: "jessica_jones",
avatar:
"https://images.unsplash.com/photo-1531746020798-e6953c6e8e04?w=100",
},
{
name: "Kenneth Johnson",
id: "kenneth_johnson",
avatar:
"https://images.unsplash.com/photo-1523477800337-966dbabe060b?w=100",
},
{
name: "Kate Wilson",
id: "kate_wilson",
avatar:
"https://images.unsplash.com/photo-1609712409631-dbbb050746d1?w=100",
},
],
itemToString: (item) => item.name,
itemToValue: (item) => item.id,
})
```
### [Clear Trigger]()
Pass the `clearable` prop to the `SelectTrigger`.
PreviewCode
Select fav. anime
Spirited Away
Spirited Away
My Neighbor Totoro
Akira
Princess Mononoke
Grave of the Fireflies
Howl's Moving Castle
Ghost in the Shell
Naruto
Hunter x Hunter
The Wind Rises
Kiki's Delivery Service
Perfect Blue
The Girl Who Leapt Through Time
Weathering with You
Ponyo
5 Centimeters per Second
A Silent Voice
Paprika
Wolf Children
Redline
The Tale of the Princess Kaguya
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const Demo = () => {
return (
<SelectRoot
collection={animeMovies}
defaultValue={["spirited_away"]}
size="sm"
width="320px"
>
<SelectLabel>Select fav. anime</SelectLabel>
<SelectTrigger clearable>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent>
{animeMovies.items.map((movie) => (
<SelectItem item={movie} key={movie.value}>
{movie.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)
}
const animeMovies = createListCollection({
items: [
{ label: "Spirited Away", value: "spirited_away" },
{ label: "My Neighbor Totoro", value: "my_neighbor_totoro" },
{ label: "Akira", value: "akira" },
{ label: "Princess Mononoke", value: "princess_mononoke" },
{ label: "Grave of the Fireflies", value: "grave_of_the_fireflies" },
{ label: "Howl's Moving Castle", value: "howls_moving_castle" },
{ label: "Ghost in the Shell", value: "ghost_in_the_shell" },
{ label: "Naruto", value: "naruto" },
{ label: "Hunter x Hunter", value: "hunter_x_hunter" },
{ label: "The Wind Rises", value: "the_wind_rises" },
{ label: "Kiki's Delivery Service", value: "kikis_delivery_service" },
{ label: "Perfect Blue", value: "perfect_blue" },
{
label: "The Girl Who Leapt Through Time",
value: "the_girl_who_leapt_through_time",
},
{ label: "Weathering with You", value: "weathering_with_you" },
{ label: "Ponyo", value: "ponyo" },
{ label: "5 Centimeters per Second", value: "5_centimeters_per_second" },
{ label: "A Silent Voice", value: "a_silent_voice" },
{ label: "Paprika", value: "paprika" },
{ label: "Wolf Children", value: "wolf_children" },
{ label: "Redline", value: "redline" },
{
label: "The Tale of the Princess Kaguya",
value: "the_tale_of_the_princess_kaguya",
},
],
})
```
### [Overflow]()
PreviewCode
Select anime
Select movie
Spirited Away
My Neighbor Totoro
Akira
Princess Mononoke
Grave of the Fireflies
Howl's Moving Castle
Ghost in the Shell
Naruto
Hunter x Hunter
The Wind Rises
Kiki's Delivery Service
Perfect Blue
The Girl Who Leapt Through Time
Weathering with You
Ponyo
5 Centimeters per Second
A Silent Voice
Paprika
Wolf Children
Redline
The Tale of the Princess Kaguya
```
"use client"
import { createListCollection } from "@chakra-ui/react"
import {
SelectContent,
SelectItem,
SelectLabel,
SelectRoot,
SelectTrigger,
SelectValueText,
} from "@/components/ui/select"
const Demo = () => {
return (
<SelectRoot collection={animeMovies} size="sm" width="240px">
<SelectLabel>Select anime</SelectLabel>
<SelectTrigger>
<SelectValueText placeholder="Select movie" />
</SelectTrigger>
<SelectContent>
{animeMovies.items.map((movie) => (
<SelectItem item={movie} key={movie.value}>
{movie.label}
</SelectItem>
))}
</SelectContent>
</SelectRoot>
)
}
const animeMovies = createListCollection({
items: [
{ label: "Spirited Away", value: "spirited_away" },
{ label: "My Neighbor Totoro", value: "my_neighbor_totoro" },
{ label: "Akira", value: "akira" },
{ label: "Princess Mononoke", value: "princess_mononoke" },
{ label: "Grave of the Fireflies", value: "grave_of_the_fireflies" },
{ label: "Howl's Moving Castle", value: "howls_moving_castle" },
{ label: "Ghost in the Shell", value: "ghost_in_the_shell" },
{ label: "Naruto", value: "naruto" },
{ label: "Hunter x Hunter", value: "hunter_x_hunter" },
{ label: "The Wind Rises", value: "the_wind_rises" },
{ label: "Kiki's Delivery Service", value: "kikis_delivery_service" },
{ label: "Perfect Blue", value: "perfect_blue" },
{
label: "The Girl Who Leapt Through Time",
value: "the_girl_who_leapt_through_time",
},
{ label: "Weathering with You", value: "weathering_with_you" },
{ label: "Ponyo", value: "ponyo" },
{ label: "5 Centimeters per Second", value: "5_centimeters_per_second" },
{ label: "A Silent Voice", value: "a_silent_voice" },
{ label: "Paprika", value: "paprika" },
{ label: "Wolf Children", value: "wolf_children" },
{ label: "Redline", value: "redline" },
{
label: "The Tale of the Princess Kaguya",
value: "the_tale_of_the_princess_kaguya",
},
],
})
```
## [Props]()
### [Root]()
PropDefaultType`items`*
`T[] | readonly T[]`
The options of the select
`closeOnSelect``true`
`boolean`
Whether the select should close after an item is selected
`composite``true`
`boolean`
Whether the select is a composed with other composite widgets like tabs or combobox
`lazyMount``false`
`boolean`
Whether to enable lazy mounting
`loopFocus``false`
`boolean`
Whether to loop the keyboard navigation through the options
`unmountOnExit``false`
`boolean`
Whether to unmount on exit.
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`variant``'outline'`
`'outline' | 'filled'`
The variant of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultOpen`
`boolean`
The initial open state of the select when it is first rendered. Use when you do not need to control its open state.
`defaultValue`
`string[]`
The initial value of the select when it is first rendered. Use when you do not need to control the state of the select.
`disabled`
`boolean`
Whether the select is disabled
`form`
`string`
The associate form of the underlying select.
`highlightedValue`
`string`
The key of the highlighted item
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ root: string content: string control: string trigger: string clearTrigger: string label: string hiddenSelect: string positioner: string item(id: string | number): string itemGroup(id: string | number): string itemGroupLabel(id: string | number): string }>`
The ids of the elements in the select. Useful for composition.
`immediate`
`boolean`
Whether to synchronize the present change immediately or defer it to the next frame
`invalid`
`boolean`
Whether the select is invalid
`isItemDisabled`
`(item: T) => boolean`
Whether the item is disabled
`itemToString`
`(item: T) => string`
The label of the item
`itemToValue`
`(item: T) => string`
The value of the item
`multiple`
`boolean`
Whether to allow multiple selection
`name`
`string`
The \`name\` attribute of the underlying select.
`onExitComplete`
`() => void`
Function called when the animation ends in the closed state
`onFocusOutside`
`(event: FocusOutsideEvent) => void`
Function called when the focus is moved outside the component
`onHighlightChange`
`(details: HighlightChangeDetails<T>) => void`
The callback fired when the highlighted item changes.
`onInteractOutside`
`(event: InteractOutsideEvent) => void`
Function called when an interaction happens outside the component
`onOpenChange`
`(details: OpenChangeDetails) => void`
Function called when the popup is opened
`onPointerDownOutside`
`(event: PointerDownOutsideEvent) => void`
Function called when the pointer is pressed down outside the component
`onValueChange`
`(details: ValueChangeDetails<T>) => void`
The callback fired when the selected item changes.
`open`
`boolean`
Whether the select menu is open
`positioning`
`PositioningOptions`
The positioning options of the menu.
`present`
`boolean`
Whether the node is present (controlled by the user)
`readOnly`
`boolean`
Whether the select is read-only
`required`
`boolean`
Whether the select is required
`scrollToIndexFn`
`(details: ScrollToIndexDetails) => void`
Function to scroll to a specific index
`value`
`string[]`
The keys of the selected items
`as`
`React.ElementType`
The underlying element to render.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Select (Native)](https://www.chakra-ui.com/docs/components/native-select)
[Next
\
Separator](https://www.chakra-ui.com/docs/components/separator) |
https://www.chakra-ui.com/docs/components/switch | 1. Components
2. Switch
# Switch
Used to capture a binary state
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/switch)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-switch--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/switch.ts)[Ark](https://ark-ui.com/react/docs/components/switch)
PreviewCode
Activate Chakra
```
import { Switch } from "@/components/ui/switch"
const Demo = () => {
return <Switch>Activate Chakra</Switch>
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `switch` snippet
```
npx @chakra-ui/cli snippet add switch
```
The snippet includes a closed component composition for the `Switch` component.
## [Usage]()
```
import { Switch } from "@/components/ui/switch"
```
```
<Switch>Label</Switch>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the switch component.
PreviewCode
```
import { HStack } from "@chakra-ui/react"
import { Switch } from "@/components/ui/switch"
const Demo = () => {
return (
<HStack gap="8">
<Switch size="xs" />
<Switch size="sm" />
<Switch size="md" />
<Switch size="lg" />
</HStack>
)
}
```
### [Variants]()
Use the `variant` prop to change the visual style of the switch.
PreviewCode
```
import { HStack } from "@chakra-ui/react"
import { Switch } from "@/components/ui/switch"
const Demo = () => {
return (
<HStack gap="8">
<Switch variant="raised" />
<Switch variant="solid" />
</HStack>
)
}
```
### [Colors]()
Use the `colorPalette` prop to change the color scheme of the component.
PreviewCode
gray
red
green
blue
teal
pink
purple
cyan
orange
yellow
```
import { Stack, Text } from "@chakra-ui/react"
import { colorPalettes } from "compositions/lib/color-palettes"
import { Switch } from "@/components/ui/switch"
const Demo = () => {
return (
<Stack gap="2" align="flex-start">
{colorPalettes.map((colorPalette) => (
<Stack
align="center"
key={colorPalette}
direction="row"
gap="10"
px="4"
>
<Text minW="8ch">{colorPalette}</Text>
<Switch colorPalette={colorPalette} />
<Switch colorPalette={colorPalette} defaultChecked />
</Stack>
))}
</Stack>
)
}
```
### [Controlled]()
Use the `checked` and `onCheckedChange` prop to control the state of the switch.
PreviewCode
```
"use client"
import { Switch } from "@/components/ui/switch"
import { useState } from "react"
const Demo = () => {
const [checked, setChecked] = useState(false)
return (
<Switch checked={checked} onCheckedChange={(e) => setChecked(e.checked)} />
)
}
```
### [Hook Form]()
Here's an example of integrating the switch with `react-hook-form`.
PreviewCode
Activate Chakra
Submit
```
"use client"
import { Button, Stack } from "@chakra-ui/react"
import { zodResolver } from "@hookform/resolvers/zod"
import { Field } from "@/components/ui/field"
import { Switch } from "@/components/ui/switch"
import { Controller, useForm } from "react-hook-form"
import { z } from "zod"
const formSchema = z.object({
active: z.boolean({ message: "Active is required" }),
})
type FormData = z.infer<typeof formSchema>
const Demo = () => {
const {
handleSubmit,
control,
formState: { errors },
} = useForm<FormData>({
resolver: zodResolver(formSchema),
})
return (
<form onSubmit={handleSubmit((data) => console.log(data))}>
<Stack align="flex-start">
<Controller
name="active"
control={control}
render={({ field }) => (
<Field invalid={!!errors.active} errorText={errors.active?.message}>
<Switch
name={field.name}
checked={field.value}
onCheckedChange={({ checked }) => field.onChange(checked)}
inputProps={{ onBlur: field.onBlur }}
>
Activate Chakra
</Switch>
</Field>
)}
/>
<Button size="sm" type="submit" mt="4">
Submit
</Button>
</Stack>
</form>
)
}
```
### [Disabled]()
Use the `disabled` prop to disable the switch.
PreviewCode
Activate Chakra
```
import { Switch } from "@/components/ui/switch"
const Demo = () => {
return <Switch disabled>Activate Chakra</Switch>
}
```
### [Invalid]()
Use the `invalid` prop to indicate an error state for the switch.
PreviewCode
Activate Chakra
```
import { Switch } from "@/components/ui/switch"
const Demo = () => {
return <Switch invalid>Activate Chakra</Switch>
}
```
### [Tooltip]()
Here's an example of a switch with a tooltip.
PreviewCode
Switch with tooltip
This is a tooltip
```
import { Switch } from "@/components/ui/switch"
import { Tooltip } from "@/components/ui/tooltip"
import { useId } from "react"
const Demo = () => {
const id = useId()
return (
<Tooltip ids={{ trigger: id }} content="This is a tooltip">
<Switch ids={{ root: id }}>Switch with tooltip </Switch>
</Tooltip>
)
}
```
### [Track Label]()
Use the `trackLabel` prop to display different label based on the checked state.
PreviewCode
```
import { Icon } from "@chakra-ui/react"
import { Switch } from "@/components/ui/switch"
import { FaMoon, FaSun } from "react-icons/fa"
const Demo = () => {
return (
<Switch
colorPalette="blue"
size="lg"
trackLabel={{
on: (
<Icon color="yellow.400">
<FaSun />
</Icon>
),
off: (
<Icon color="gray.400">
<FaMoon />
</Icon>
),
}}
/>
)
}
```
### [Thumb Label]()
Use the `thumbLabel` prop to add an icon to the switch thumb.
PreviewCode
Switch me
```
import { Switch } from "@/components/ui/switch"
import { HiCheck, HiX } from "react-icons/hi"
const Demo = () => {
return (
<Switch size="lg" thumbLabel={{ on: <HiCheck />, off: <HiX /> }}>
Switch me
</Switch>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`value``'\'on\''`
`string | number`
The value of switch input. Useful for form submission.
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`variant``'solid'`
`'solid' | 'raised'`
The variant of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`checked`
`boolean`
Whether the switch is checked.
`disabled`
`boolean`
Whether the switch is disabled.
`ids`
`Partial<{ root: string hiddenInput: string control: string label: string thumb: string }>`
The ids of the elements in the switch. Useful for composition.
`invalid`
`boolean`
If \`true\`, the switch is marked as invalid.
`label`
`string`
Specifies the localized strings that identifies the accessibility elements and their states
`name`
`string`
The name of the input field in a switch (Useful for form submission).
`onCheckedChange`
`(details: CheckedChangeDetails) => void`
Function to call when the switch is clicked.
`readOnly`
`boolean`
Whether the switch is read-only
`required`
`boolean`
If \`true\`, the switch input is marked as required,
`as`
`React.ElementType`
The underlying element to render.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Steps](https://www.chakra-ui.com/docs/components/steps)
[Next
\
Tabs](https://www.chakra-ui.com/docs/components/tabs) |
https://www.chakra-ui.com/docs/components/steps | 1. Components
2. Steps
# Steps
Used to indicate progress through a multi-step process
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/steps)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-steps--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/steps.ts)[Ark](https://ark-ui.com/react/docs/components/steps)
PreviewCode
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
```
import { Group } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
StepsCompletedContent,
StepsContent,
StepsItem,
StepsList,
StepsNextTrigger,
StepsPrevTrigger,
StepsRoot,
} from "@/components/ui/steps"
const Demo = () => {
return (
<StepsRoot defaultValue={1} count={3}>
<StepsList>
<StepsItem index={0} title="Step 1" />
<StepsItem index={1} title="Step 2" />
<StepsItem index={2} title="Step 3" />
</StepsList>
<StepsContent index={0}>Step 1</StepsContent>
<StepsContent index={1}>Step 2</StepsContent>
<StepsContent index={2}>Step 3</StepsContent>
<StepsCompletedContent>All steps are complete!</StepsCompletedContent>
<Group>
<StepsPrevTrigger asChild>
<Button variant="outline" size="sm">
Prev
</Button>
</StepsPrevTrigger>
<StepsNextTrigger asChild>
<Button variant="outline" size="sm">
Next
</Button>
</StepsNextTrigger>
</Group>
</StepsRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `steps` snippet
```
npx @chakra-ui/cli snippet add steps
```
The snippet includes a closed component composition for the `Steps` component.
## [Usage]()
```
import {
StepsCompletedContent,
StepsContent,
StepsItem,
StepsList,
StepsNextTrigger,
StepsPrevTrigger,
StepsRoot,
} from "@/components/ui/steps"
```
```
<StepsRoot>
<StepsList>
<StepsItem />
</StepsList>
<StepsContent />
<StepsCompleteContent />
<StepsPrevTrigger />
<StepsNextTrigger />
</StepsRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the steps component.
PreviewCode
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
```
import { For, Group, Stack } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
StepsCompletedContent,
StepsContent,
StepsItem,
StepsList,
StepsNextTrigger,
StepsPrevTrigger,
StepsRoot,
} from "@/components/ui/steps"
const Demo = () => {
return (
<Stack gap="16">
<For each={["sm", "md", "lg"]}>
{(size) => (
<StepsRoot key={size} size={size} count={3}>
<StepsList>
<StepsItem index={0} title="Step 1" />
<StepsItem index={1} title="Step 2" />
<StepsItem index={2} title="Step 3" />
</StepsList>
<StepsContent index={0}>Step 1</StepsContent>
<StepsContent index={1}>Step 2</StepsContent>
<StepsContent index={2}>Step 3</StepsContent>
<StepsCompletedContent>
All steps are complete!
</StepsCompletedContent>
<Group>
<StepsPrevTrigger asChild>
<Button variant="outline" size="sm">
Prev
</Button>
</StepsPrevTrigger>
<StepsNextTrigger asChild>
<Button variant="outline" size="sm">
Next
</Button>
</StepsNextTrigger>
</Group>
</StepsRoot>
)}
</For>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to change the appearance of the steps component.
PreviewCode
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
```
import { For, Group, Stack } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
StepsCompletedContent,
StepsContent,
StepsItem,
StepsList,
StepsNextTrigger,
StepsPrevTrigger,
StepsRoot,
} from "@/components/ui/steps"
const Demo = () => {
return (
<Stack gap="16">
<For each={["subtle", "solid"]}>
{(variant) => (
<StepsRoot key={variant} variant={variant} count={3}>
<StepsList>
<StepsItem index={0} title="Step 1" />
<StepsItem index={1} title="Step 2" />
<StepsItem index={2} title="Step 3" />
</StepsList>
<StepsContent index={0}>Step 1</StepsContent>
<StepsContent index={1}>Step 2</StepsContent>
<StepsContent index={2}>Step 3</StepsContent>
<StepsCompletedContent>
All steps are complete!
</StepsCompletedContent>
<Group>
<StepsPrevTrigger asChild>
<Button variant="outline" size="sm">
Prev
</Button>
</StepsPrevTrigger>
<StepsNextTrigger asChild>
<Button variant="outline" size="sm">
Next
</Button>
</StepsNextTrigger>
</Group>
</StepsRoot>
)}
</For>
</Stack>
)
}
```
### [Colors]()
Use the `colorPalette` prop to change the color scheme of the component.
PreviewCode
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
```
import { For, Group, Stack } from "@chakra-ui/react"
import { colorPalettes } from "compositions/lib/color-palettes"
import { Button } from "@/components/ui/button"
import {
StepsCompletedContent,
StepsContent,
StepsItem,
StepsList,
StepsNextTrigger,
StepsPrevTrigger,
StepsRoot,
} from "@/components/ui/steps"
const Demo = () => {
return (
<Stack gap="10" width="full">
<For each={colorPalettes}>
{(colorPalette) => (
<StepsRoot
key={colorPalette}
defaultValue={1}
count={3}
colorPalette={colorPalette}
>
<StepsList>
<StepsItem index={0} title="Step 1" />
<StepsItem index={1} title="Step 2" />
<StepsItem index={2} title="Step 3" />
</StepsList>
<StepsContent index={0}>Step 1</StepsContent>
<StepsContent index={1}>Step 2</StepsContent>
<StepsContent index={2}>Step 3</StepsContent>
<StepsCompletedContent>
All steps are complete!
</StepsCompletedContent>
<Group>
<StepsPrevTrigger asChild>
<Button variant="outline" size="sm">
Prev
</Button>
</StepsPrevTrigger>
<StepsNextTrigger asChild>
<Button variant="outline" size="sm">
Next
</Button>
</StepsNextTrigger>
</Group>
</StepsRoot>
)}
</For>
</Stack>
)
}
```
### [Vertical]()
Use the `orientation` prop to change the orientation of the steps component.
PreviewCode
1. 1
Step 1
2. 2
Step 2
3. 3
Step 3
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
```
import { Group, Stack } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
StepsCompletedContent,
StepsContent,
StepsItem,
StepsList,
StepsNextTrigger,
StepsPrevTrigger,
StepsRoot,
} from "@/components/ui/steps"
const Demo = () => {
return (
<StepsRoot orientation="vertical" height="400px" defaultValue={1} count={3}>
<StepsList>
<StepsItem index={0} title="Step 1" />
<StepsItem index={1} title="Step 2" />
<StepsItem index={2} title="Step 3" />
</StepsList>
<Stack>
<StepsContent index={0}>Step 1</StepsContent>
<StepsContent index={1}>Step 2</StepsContent>
<StepsContent index={2}>Step 3</StepsContent>
<StepsCompletedContent>All steps are complete!</StepsCompletedContent>
<Group>
<StepsPrevTrigger asChild>
<Button variant="outline" size="sm">
Prev
</Button>
</StepsPrevTrigger>
<StepsNextTrigger asChild>
<Button variant="outline" size="sm">
Next
</Button>
</StepsNextTrigger>
</Group>
</Stack>
</StepsRoot>
)
}
```
### [Icon]()
Pass the `icon` prop to the `StepsItem` component to display an icon.
PreviewCode
Contact Details
Payment
Book an Appointment
All steps are complete!
PrevNext
```
import { Group } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
StepsCompletedContent,
StepsContent,
StepsItem,
StepsList,
StepsNextTrigger,
StepsPrevTrigger,
StepsRoot,
} from "@/components/ui/steps"
import { LuCalendar, LuUser, LuWallet } from "react-icons/lu"
const Demo = () => {
return (
<StepsRoot defaultValue={1} count={3}>
<StepsList>
<StepsItem index={0} icon={<LuUser />} />
<StepsItem index={1} icon={<LuWallet />} />
<StepsItem index={2} icon={<LuCalendar />} />
</StepsList>
<StepsContent index={0}>Contact Details</StepsContent>
<StepsContent index={1}>Payment</StepsContent>
<StepsContent index={2}>Book an Appointment</StepsContent>
<StepsCompletedContent>All steps are complete!</StepsCompletedContent>
<Group>
<StepsPrevTrigger asChild>
<Button variant="outline" size="sm">
Prev
</Button>
</StepsPrevTrigger>
<StepsNextTrigger asChild>
<Button variant="outline" size="sm">
Next
</Button>
</StepsNextTrigger>
</Group>
</StepsRoot>
)
}
```
### [Description]()
Pass the `description` prop to the `StepsItem` component to display a description.
PreviewCode
1. 1
Step 1
This step
2. 2
Step 2
That step
3. 3
Step 3
Final step
Step 1
Step 2
Step 3
All steps are complete!
PrevNext
```
import { Group } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
StepsCompletedContent,
StepsContent,
StepsItem,
StepsList,
StepsNextTrigger,
StepsPrevTrigger,
StepsRoot,
} from "@/components/ui/steps"
const Demo = () => {
return (
<StepsRoot defaultValue={1} count={3}>
<StepsList>
<StepsItem index={0} title="Step 1" description="This step" />
<StepsItem index={1} title="Step 2" description="That step" />
<StepsItem index={2} title="Step 3" description="Final step" />
</StepsList>
<StepsContent index={0}>Step 1</StepsContent>
<StepsContent index={1}>Step 2</StepsContent>
<StepsContent index={2}>Step 3</StepsContent>
<StepsCompletedContent>All steps are complete!</StepsCompletedContent>
<Group>
<StepsPrevTrigger asChild>
<Button variant="outline" size="sm">
Prev
</Button>
</StepsPrevTrigger>
<StepsNextTrigger asChild>
<Button variant="outline" size="sm">
Next
</Button>
</StepsNextTrigger>
</Group>
</StepsRoot>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`orientation``'horizontal'`
`'vertical' | 'horizontal'`
The orientation of the component
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`variant``'solid'`
`'solid' | 'subtle'`
The variant of the component
`size``'md'`
`'sm' | 'md' | 'lg'`
The size of the component
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`count`
`number`
The total number of steps
`defaultStep`
`number`
The initial value of the step
`ids`
`ElementIds`
The custom ids for the stepper elements
`linear`
`boolean`
If \`true\`, the stepper requires the user to complete the steps in order
`onStepChange`
`(details: StepChangeDetails) => void`
Callback to be called when the value changes
`onStepComplete`
`VoidFunction`
Callback to be called when a step is completed
`step`
`number`
The current value of the stepper
`as`
`React.ElementType`
The underlying element to render.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Status](https://www.chakra-ui.com/docs/components/status)
[Next
\
Switch](https://www.chakra-ui.com/docs/components/switch) |
https://www.chakra-ui.com/docs/components/textarea | 1. Components
2. Textarea
# Textarea
Used to enter multiple lines of text.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/textarea)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-textarea--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/textarea.ts)
PreviewCode
```
import { Textarea } from "@chakra-ui/react"
const Demo = () => {
return <Textarea placeholder="Comment..." />
}
```
## [Usage]()
```
import { Textarea } from "@chakra-ui/react"
```
```
<Textarea placeholder="..." />
```
## [Examples]()
### [Variants]()
Use the `variant` prop to change the appearance of the textarea.
PreviewCode
```
import { Stack, Textarea } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack gap="4">
<Textarea variant="outline" placeholder="outline" />
<Textarea variant="subtle" placeholder="subtle" />
<Textarea variant="flushed" placeholder="flushed" />
</Stack>
)
}
```
### [Sizes]()
Use the `size` prop to change the size of the textarea.
PreviewCode
```
import { Stack, Textarea } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack gap="4">
<Textarea size="xs" placeholder="XSmall size" />
<Textarea size="sm" placeholder="Small size" />
<Textarea size="md" placeholder="Medium size" />
<Textarea size="lg" placeholder="Large size" />
<Textarea size="xl" placeholder="XLarge size" />
</Stack>
)
}
```
### [Helper Text]()
Pair the textarea with the `Field` component to add helper text.
PreviewCode
Comment\*Max 500 characters.
Comment\*Max 500 characters.
```
import { HStack, Textarea } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<HStack gap="10" width="full">
<Field label="Comment" required helperText="Max 500 characters.">
<Textarea placeholder="Start typing..." variant="subtle" />
</Field>
<Field label="Comment" required helperText="Max 500 characters.">
<Textarea placeholder="Start typing..." variant="outline" />
</Field>
</HStack>
)
}
```
### [Error Text]()
Pair the textarea with the `Field` component to add error text.
PreviewCode
Comment\*Field is required
Comment\*Field is required
```
import { HStack, Textarea } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<HStack gap="10" width="full">
<Field invalid label="Comment" required errorText="Field is required">
<Textarea placeholder="Start typing..." variant="subtle" />
</Field>
<Field invalid label="Comment" required errorText="Field is required">
<Textarea placeholder="Start typing..." variant="outline" />
</Field>
</HStack>
)
}
```
### [Field]()
Compose the textarea with the `Field` component to add a label, helper text, and error text.
PreviewCode
Email*
Email*
```
import { HStack, Input } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
const Demo = () => {
return (
<HStack gap="10" width="full">
<Field label="Email" required>
<Input placeholder="[email protected]" variant="subtle" />
</Field>
<Field label="Email" required>
<Input placeholder="[email protected]" variant="outline" />
</Field>
</HStack>
)
}
```
### [Hook Form]()
Here's an example of how to integrate the textarea with `react-hook-form`.
PreviewCode
Username
Profile bioA short description of yourself
Submit
```
"use client"
import { Button, Input, Stack, Textarea } from "@chakra-ui/react"
import { Field } from "@/components/ui/field"
import { useForm } from "react-hook-form"
interface FormValues {
username: string
bio: string
}
const Demo = () => {
const {
register,
handleSubmit,
formState: { errors },
} = useForm<FormValues>()
const onSubmit = handleSubmit((data) => console.log(data))
return (
<form onSubmit={onSubmit}>
<Stack gap="4" align="flex-start" maxW="sm">
<Field
label="Username"
invalid={!!errors.username}
errorText={errors.username?.message}
>
<Input
placeholder="@username"
{...register("username", { required: "Username is required" })}
/>
</Field>
<Field
label="Profile bio"
invalid={!!errors.bio}
helperText="A short description of yourself"
errorText={errors.bio?.message}
>
<Textarea
placeholder="I am ..."
{...register("bio", { required: "Bio is required" })}
/>
</Field>
<Button type="submit">Submit</Button>
</Stack>
</form>
)
}
```
### [Resize]()
Use the `resize` prop to control the resize behavior of the textarea.
PreviewCode
```
import { Stack, Textarea } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack gap="4" maxWidth="250px">
<Textarea resize="none" placeholder="Search the docs…" />
<Textarea resize="vertical" placeholder="Search the docs…" />
<Textarea resize="horizontal" placeholder="Search the docs…" />
<Textarea resize="both" placeholder="Search the docs…" />
</Stack>
)
}
```
### [Autoresize]()
Use the `autoresize` prop to make the textarea autoresize vertically as you type.
PreviewCode
```
import { Textarea } from "@chakra-ui/react"
const Demo = () => {
return <Textarea autoresize />
}
```
## [Props]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'lg' | 'md' | 'sm' | 'xs'`
The size of the component
`variant``'outline'`
`'outline' | 'filled' | 'flushed'`
The variant of the component
[Previous
\
Tag](https://www.chakra-ui.com/docs/components/tag)
[Next
\
Timeline](https://www.chakra-ui.com/docs/components/timeline) |
https://www.chakra-ui.com/docs/components/timeline | 1. Components
2. Timeline
# Timeline
Used to display a list of events in chronological order
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/timeline)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-timeline--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/timeline.ts)
PreviewCode
Product Shipped
13th May 2021
We shipped your product via **FedEx** and it should arrive within 3-5 business days.
Order Confirmed
18th May 2021
Order Delivered
20th May 2021, 10:30am
```
import { Text } from "@chakra-ui/react"
import {
TimelineConnector,
TimelineContent,
TimelineDescription,
TimelineItem,
TimelineRoot,
TimelineTitle,
} from "@/components/ui/timeline"
import { LuCheck, LuPackage, LuShip } from "react-icons/lu"
const Demo = () => {
return (
<TimelineRoot maxW="400px">
<TimelineItem>
<TimelineConnector>
<LuShip />
</TimelineConnector>
<TimelineContent>
<TimelineTitle>Product Shipped</TimelineTitle>
<TimelineDescription>13th May 2021</TimelineDescription>
<Text textStyle="sm">
We shipped your product via <strong>FedEx</strong> and it should
arrive within 3-5 business days.
</Text>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineConnector>
<LuCheck />
</TimelineConnector>
<TimelineContent>
<TimelineTitle textStyle="sm">Order Confirmed</TimelineTitle>
<TimelineDescription>18th May 2021</TimelineDescription>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineConnector>
<LuPackage />
</TimelineConnector>
<TimelineContent>
<TimelineTitle textStyle="sm">Order Delivered</TimelineTitle>
<TimelineDescription>20th May 2021, 10:30am</TimelineDescription>
</TimelineContent>
</TimelineItem>
</TimelineRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `timeline` snippet
```
npx @chakra-ui/cli snippet add timeline
```
The snippet includes a closed component composition for the `Timeline` component.
## [Usage]()
```
import { TimelineItem, TimelineRoot } from "@/components/ui/timeline"
```
```
<TimelineRoot>
<TimelineItem />
<TimelineItem />
</TimelineRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the timeline.
PreviewCode
S![](https://bit.ly/sage-adebayo)
sagecreated a new project
sagechanged status from In progress to Completed
S![](https://bit.ly/sage-adebayo)
sagecreated a new project
sagechanged status from In progress to Completed
S![](https://bit.ly/sage-adebayo)
sagecreated a new project
sagechanged status from In progress to Completed
S![](https://bit.ly/sage-adebayo)
sagecreated a new project
sagechanged status from In progress to Completed
```
import { Badge, For, Span, Stack } from "@chakra-ui/react"
import { Avatar } from "@/components/ui/avatar"
import {
TimelineConnector,
TimelineContent,
TimelineItem,
TimelineRoot,
TimelineTitle,
} from "@/components/ui/timeline"
import { LuCheck } from "react-icons/lu"
const Demo = () => {
return (
<Stack gap="8">
<For each={["sm", "md", "lg", "xl"]}>
{(size) => (
<TimelineRoot key={size} size={size}>
<TimelineItem>
<TimelineConnector>
<Avatar
size="full"
name="Sage"
src="https://bit.ly/sage-adebayo"
/>
</TimelineConnector>
<TimelineContent textStyle="xs">
<TimelineTitle>
<Span fontWeight="medium">sage</Span>
created a new project
</TimelineTitle>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineConnector>
<LuCheck />
</TimelineConnector>
<TimelineContent textStyle="xs">
<TimelineTitle mt={size === "sm" ? "-2px" : undefined}>
<Span fontWeight="medium">sage</Span>
changed status from <Badge size="sm">
In progress
</Badge> to{" "}
<Badge colorPalette="teal" size="sm">
Completed
</Badge>
</TimelineTitle>
</TimelineContent>
</TimelineItem>
</TimelineRoot>
)}
</For>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to change the variant of the timeline.
PreviewCode
S![](https://bit.ly/sage-adebayo)
sagecreated a new project
sagechanged status from In progress to Completed
S![](https://bit.ly/sage-adebayo)
sagecreated a new project
sagechanged status from In progress to Completed
S![](https://bit.ly/sage-adebayo)
sagecreated a new project
sagechanged status from In progress to Completed
S![](https://bit.ly/sage-adebayo)
sagecreated a new project
sagechanged status from In progress to Completed
```
import { Badge, For, Span, Stack } from "@chakra-ui/react"
import { Avatar } from "@/components/ui/avatar"
import {
TimelineConnector,
TimelineContent,
TimelineItem,
TimelineRoot,
TimelineTitle,
} from "@/components/ui/timeline"
import { LuCheck } from "react-icons/lu"
const Demo = () => {
return (
<Stack gap="16">
<For each={["subtle", "solid", "outline", "plain"]}>
{(variant) => (
<TimelineRoot variant={variant} key={variant}>
<TimelineItem>
<TimelineConnector>
<Avatar
size="full"
name="Sage"
src="https://bit.ly/sage-adebayo"
/>
</TimelineConnector>
<TimelineContent>
<TimelineTitle>
<Span fontWeight="medium">sage</Span>
created a new project
</TimelineTitle>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineConnector>
<LuCheck />
</TimelineConnector>
<TimelineContent>
<TimelineTitle>
<Span fontWeight="medium">sage</Span>
changed status from <Badge>In progress</Badge> to{" "}
<Badge colorPalette="teal">Completed</Badge>
</TimelineTitle>
</TimelineContent>
</TimelineItem>
</TimelineRoot>
)}
</For>
</Stack>
)
}
```
### [Content Before]()
Here's an example of a timeline with content before the timeline indicator.
PreviewCode
Nov 1994
1
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nov 2010
2
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nov 1994
1
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nov 2010
2
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nov 1994
1
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nov 2010
2
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
```
import { For, Stack, Timeline } from "@chakra-ui/react"
import {
TimelineConnector,
TimelineContent,
TimelineItem,
TimelineRoot,
TimelineTitle,
} from "@/components/ui/timeline"
const Demo = () => {
return (
<Stack gap="8">
<For each={["sm", "md", "lg"]}>
{(size) => (
<TimelineRoot size={size} key={size}>
<TimelineItem>
<TimelineContent width="auto">
<TimelineTitle whiteSpace="nowrap">Nov 1994</TimelineTitle>
</TimelineContent>
<TimelineConnector>1</TimelineConnector>
<Timeline.Content>
<TimelineTitle>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</TimelineTitle>
</Timeline.Content>
</TimelineItem>
<TimelineItem>
<TimelineContent width="auto">
<TimelineTitle whiteSpace="nowrap">Nov 2010</TimelineTitle>
</TimelineContent>
<TimelineConnector>2</TimelineConnector>
<TimelineContent>
<TimelineTitle>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</TimelineTitle>
</TimelineContent>
</TimelineItem>
</TimelineRoot>
)}
</For>
</Stack>
)
}
```
### [Alternating Content]()
Here's an example of a timeline with alternating content.
PreviewCode
Placed Order
Prepared Order
Order Delivered
```
import {
TimelineConnector,
TimelineContent,
TimelineItem,
TimelineRoot,
TimelineTitle,
} from "@/components/ui/timeline"
const Demo = () => {
return (
<TimelineRoot size="sm" variant="outline">
<TimelineItem>
<TimelineContent flex="1" />
<TimelineConnector />
<TimelineContent flex="1">
<TimelineTitle>Placed Order</TimelineTitle>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineContent flex="1" alignItems="flex-end">
<TimelineTitle>Prepared Order</TimelineTitle>
</TimelineContent>
<TimelineConnector />
<TimelineContent flex="1" />
</TimelineItem>
<TimelineItem>
<TimelineContent flex="1" />
<TimelineConnector />
<TimelineContent flex="1">
<TimelineTitle>Order Delivered</TimelineTitle>
</TimelineContent>
</TimelineItem>
</TimelineRoot>
)
}
```
### [Composition]()
Here's an example of how to compose the timeline with other components to create a consistent-looking timeline.
PreviewCode
![](https://i.pravatar.cc/150?u=a)
Lucas Moras has changed3 labels onJan 1, 2024
![](https://i.pravatar.cc/150?u=x)
Jenna Smith removedEnason Jan 12, 2024
![](https://i.pravatar.cc/150?u=y)
Erica commentedon Jan 12, 2024
Lorem ipsum odor amet, consectetuer adipiscing elit. Consectetur consectetur. Arcu. Etiam conubia. Elementum varius. Nostra scelerisque. Hac velit. Taciti. Nascetur velit.
👏 2
![](https://i.pravatar.cc/150?u=o)
```
import { Button, Card, Icon, Input, Span } from "@chakra-ui/react"
import { Avatar } from "@/components/ui/avatar"
import {
TimelineConnector,
TimelineContent,
TimelineItem,
TimelineRoot,
TimelineTitle,
} from "@/components/ui/timeline"
import { LuPen, LuX } from "react-icons/lu"
import LoremIpsum from "react-lorem-ipsum"
const Demo = () => {
return (
<TimelineRoot size="lg" variant="subtle" maxW="md">
<TimelineItem>
<TimelineConnector>
<Icon fontSize="xs">
<LuPen />
</Icon>
</TimelineConnector>
<TimelineContent>
<TimelineTitle>
<Avatar size="2xs" src="https://i.pravatar.cc/150?u=a" />
Lucas Moras <Span color="fg.muted">has changed</Span>
<Span fontWeight="medium">3 labels</Span> on
<Span color="fg.muted">Jan 1, 2024</Span>
</TimelineTitle>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineConnector>
<Icon fontSize="xs">
<LuX />
</Icon>
</TimelineConnector>
<TimelineContent>
<TimelineTitle>
<Avatar size="2xs" src="https://i.pravatar.cc/150?u=x" />
Jenna Smith <Span color="fg.muted">removed</Span>
<Span fontWeight="medium">Enas</Span>
<Span color="fg.muted">on Jan 12, 2024</Span>
</TimelineTitle>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineConnector bg="teal.solid" color="teal.contrast">
<Icon fontSize="xs">
<LuX />
</Icon>
</TimelineConnector>
<TimelineContent gap="4">
<TimelineTitle>
<Avatar size="2xs" src="https://i.pravatar.cc/150?u=y" />
Erica <Span color="fg.muted">commented</Span>
<Span color="fg.muted">on Jan 12, 2024</Span>
</TimelineTitle>
<Card.Root size="sm">
<Card.Body textStyle="sm" lineHeight="tall">
<LoremIpsum p={1} avgWordsPerSentence={2} />
</Card.Body>
<Card.Footer>
<Button size="xs" variant="surface" rounded="md">
👏 2
</Button>
</Card.Footer>
</Card.Root>
</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineConnector>
<Avatar size="full" src="https://i.pravatar.cc/150?u=o" />
</TimelineConnector>
<TimelineContent gap="4" mt="-1" w="full">
<Input size="sm" placeholder="Add comment..." />
</TimelineContent>
</TimelineItem>
</TimelineRoot>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`variant``'solid'`
`'subtle' | 'solid' | 'outline' | 'plain'`
The variant of the component
`size``'md'`
`'sm' | 'md'`
The size of the component
[Previous
\
Textarea](https://www.chakra-ui.com/docs/components/textarea)
[Next
\
Toast](https://www.chakra-ui.com/docs/components/toast) |
https://www.chakra-ui.com/docs/components/tabs | 1. Components
2. Tabs
# Tabs
Used to display content in a tabbed interface
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/tabs)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-tabs--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/tabs.ts)[Ark](https://ark-ui.com/react/docs/components/tabs)
PreviewCode
MembersProjectsSettings
Manage your team members
Manage your projects
Manage your tasks for freelancers
```
import { Tabs } from "@chakra-ui/react"
import { LuCheckSquare, LuFolder, LuUser } from "react-icons/lu"
const Demo = () => {
return (
<Tabs.Root defaultValue="members">
<Tabs.List>
<Tabs.Trigger value="members">
<LuUser />
Members
</Tabs.Trigger>
<Tabs.Trigger value="projects">
<LuFolder />
Projects
</Tabs.Trigger>
<Tabs.Trigger value="tasks">
<LuCheckSquare />
Settings
</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="members">Manage your team members</Tabs.Content>
<Tabs.Content value="projects">Manage your projects</Tabs.Content>
<Tabs.Content value="tasks">
Manage your tasks for freelancers
</Tabs.Content>
</Tabs.Root>
)
}
```
## [Usage]()
```
import { Tabs } from "@chakra-ui/react"
```
```
<Tabs.Root>
<Tabs.List>
<Tabs.Trigger />
<Tabs.Indicator />
</Tabs.List>
<Tabs.Content />
</Tabs.Root>
```
## [Examples]()
### [Variants]()
Use the `variant` prop to change the visual style of the tabs.
PreviewCode
MembersProjectsSettings
Manage your team members
Manage your projects
Manage your tasks for freelancers
MembersProjectsSettings
Manage your team members
Manage your projects
Manage your tasks for freelancers
MembersProjectsSettings
Manage your team members
Manage your projects
Manage your tasks for freelancers
MembersProjectsSettings
Manage your team members
Manage your projects
Manage your tasks for freelancers
MembersProjectsSettings
Manage your team members
Manage your projects
Manage your tasks for freelancers
```
import { For, SimpleGrid, Tabs } from "@chakra-ui/react"
import { LuCheckSquare, LuFolder, LuUser } from "react-icons/lu"
const Demo = () => {
return (
<SimpleGrid columns={2} gap="14" width="full">
<For each={["line", "subtle", "enclosed", "outline", "plain"]}>
{(variant) => (
<Tabs.Root key={variant} defaultValue="members" variant={variant}>
<Tabs.List>
<Tabs.Trigger value="members">
<LuUser />
Members
</Tabs.Trigger>
<Tabs.Trigger value="projects">
<LuFolder />
Projects
</Tabs.Trigger>
<Tabs.Trigger value="tasks">
<LuCheckSquare />
Settings
</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="members">
Manage your team members
</Tabs.Content>
<Tabs.Content value="projects">Manage your projects</Tabs.Content>
<Tabs.Content value="tasks">
Manage your tasks for freelancers
</Tabs.Content>
</Tabs.Root>
)}
</For>
</SimpleGrid>
)
}
```
### [Lazy Mounted]()
Use the `lazyMount` and/or `unmountOnExit` prop to only render the tab content when it is active. This can be useful for performance optimization.
PreviewCode
Tab 1Tab 2Tab 3
Tab 1: Content 0
```
"use client"
import { Tabs } from "@chakra-ui/react"
import { useEffect, useState } from "react"
const Demo = () => {
return (
<Tabs.Root lazyMount unmountOnExit defaultValue="tab-1">
<Tabs.List>
<Tabs.Trigger value="tab-1">Tab 1</Tabs.Trigger>
<Tabs.Trigger value="tab-2">Tab 2</Tabs.Trigger>
<Tabs.Trigger value="tab-3">Tab 3</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="tab-1">
Tab 1: Content <TickValue />
</Tabs.Content>
<Tabs.Content value="tab-2">
Tab 2: Content <TickValue />
</Tabs.Content>
<Tabs.Content value="tab-3">
Tab 3: Content <TickValue />
</Tabs.Content>
</Tabs.Root>
)
}
const TickValue = () => {
const [value, setValue] = useState(0)
useEffect(() => {
const intervalId = window.setInterval(() => {
setValue((v) => v + 1)
}, 1000)
return () => {
window.clearInterval(intervalId)
}
}, [])
return (
<span style={{ fontWeight: "bold", color: "tomato", padding: 4 }}>
{value}
</span>
)
}
```
### [Indicator]()
Render the `Tabs.Indicator` component to display a visual indicator of the active tab.
PreviewCode
MembersProjectsSettings
Manage your team members
Manage your projects
Manage your tasks for freelancers
```
import { Tabs } from "@chakra-ui/react"
import { LuCheckSquare, LuFolder, LuUser } from "react-icons/lu"
const Demo = () => {
return (
<Tabs.Root defaultValue="members" variant="plain">
<Tabs.List bg="bg.muted" rounded="l3" p="1">
<Tabs.Trigger value="members">
<LuUser />
Members
</Tabs.Trigger>
<Tabs.Trigger value="projects">
<LuFolder />
Projects
</Tabs.Trigger>
<Tabs.Trigger value="tasks">
<LuCheckSquare />
Settings
</Tabs.Trigger>
<Tabs.Indicator rounded="l2" />
</Tabs.List>
<Tabs.Content value="members">Manage your team members</Tabs.Content>
<Tabs.Content value="projects">Manage your projects</Tabs.Content>
<Tabs.Content value="tasks">
Manage your tasks for freelancers
</Tabs.Content>
</Tabs.Root>
)
}
```
### [Links]()
Pass the `asChild` to the `Tabs.Trigger` component to render a link as a tab. When a tab is clicked, the link will be navigated to.
PreviewCode
[Members]()[Projects]()
Manage your team members
Manage your projects
```
import { Link, Tabs } from "@chakra-ui/react"
const Demo = () => {
return (
<Tabs.Root defaultValue="members">
<Tabs.List>
<Tabs.Trigger value="members" asChild>
<Link unstyled href="#members">
Members
</Link>
</Tabs.Trigger>
<Tabs.Trigger value="projects" asChild>
<Link unstyled href="#projects">
Projects
</Link>
</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="members">Manage your team members</Tabs.Content>
<Tabs.Content value="projects">Manage your projects</Tabs.Content>
</Tabs.Root>
)
}
```
### [Fitted]()
Use the `fitted` prop to make the tabs fit the width of the container.
PreviewCode
Tab 1Tab 2Tab 3
```
import { Tabs } from "@chakra-ui/react"
const Demo = () => {
return (
<Tabs.Root variant="enclosed" maxW="md" fitted defaultValue={"tab-1"}>
<Tabs.List>
<Tabs.Trigger value="tab-1">Tab 1</Tabs.Trigger>
<Tabs.Trigger value="tab-2">Tab 2</Tabs.Trigger>
<Tabs.Trigger value="tab-3">Tab 3</Tabs.Trigger>
</Tabs.List>
</Tabs.Root>
)
}
```
### [Controlled]()
Use the `value` and `onValueChange` prop to control the active tab.
PreviewCode
First tabSecond tab
First panel
Second panel
```
"use client"
import { Tabs } from "@chakra-ui/react"
import { useState } from "react"
const Demo = () => {
const [value, setValue] = useState<string | null>("first")
return (
<Tabs.Root value={value} onValueChange={(e) => setValue(e.value)}>
<Tabs.List>
<Tabs.Trigger value="first">First tab</Tabs.Trigger>
<Tabs.Trigger value="second">Second tab</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="first">First panel</Tabs.Content>
<Tabs.Content value="second">Second panel</Tabs.Content>
</Tabs.Root>
)
}
```
### [Disabled Tab]()
Set the `disabled` prop on the `Tabs.Trigger` component to disable a tab.
PreviewCode
MembersProjectsSettings
```
import { Tabs } from "@chakra-ui/react"
import { LuCheckSquare, LuFolder, LuUser } from "react-icons/lu"
const Demo = () => {
return (
<Tabs.Root defaultValue="members">
<Tabs.List>
<Tabs.Trigger value="members">
<LuUser />
Members
</Tabs.Trigger>
<Tabs.Trigger value="projects" disabled>
<LuFolder />
Projects
</Tabs.Trigger>
<Tabs.Trigger value="tasks">
<LuCheckSquare />
Settings
</Tabs.Trigger>
</Tabs.List>
{/* content */}
</Tabs.Root>
)
}
```
### [Manual activation]()
By default, the tabs are selected when the arrow keys are pressed. Disable this behavior by setting the `activationBehavior` prop to `manual`.
In this mode, the tabs will only be selected when clicked or the enter key is pressed.
PreviewCode
MembersProjectsSettings
```
import { Tabs } from "@chakra-ui/react"
import { LuCheckSquare, LuFolder, LuUser } from "react-icons/lu"
const Demo = () => {
return (
<Tabs.Root defaultValue="members" activationMode="manual">
<Tabs.List>
<Tabs.Trigger value="members">
<LuUser />
Members
</Tabs.Trigger>
<Tabs.Trigger value="projects" disabled>
<LuFolder />
Projects
</Tabs.Trigger>
<Tabs.Trigger value="tasks">
<LuCheckSquare />
Settings
</Tabs.Trigger>
</Tabs.List>
{/* content */}
</Tabs.Root>
)
}
```
### [Dynamic]()
Here's an example of how to dynamically add and remove tabs.
PreviewCode
Tab Tab Tab Tab Add Tab
## Tab Content 1
Dolore ex esse laboris elit magna esse sunt. Pariatur in veniam Lorem est occaecat do magna nisi mollit ipsum sit adipisicing fugiat ex. Pariatur ullamco exercitation ea qui adipisicing. Id cupidatat aute id ut excepteur exercitation magna pariatur. Mollit irure irure reprehenderit pariatur eiusmod proident Lorem deserunt duis cillum mollit.
## Tab Content 2
Dolore ex esse laboris elit magna esse sunt. Pariatur in veniam Lorem est occaecat do magna nisi mollit ipsum sit adipisicing fugiat ex. Pariatur ullamco exercitation ea qui adipisicing. Id cupidatat aute id ut excepteur exercitation magna pariatur. Mollit irure irure reprehenderit pariatur eiusmod proident Lorem deserunt duis cillum mollit.
## Tab Content 3
Dolore ex esse laboris elit magna esse sunt. Pariatur in veniam Lorem est occaecat do magna nisi mollit ipsum sit adipisicing fugiat ex. Pariatur ullamco exercitation ea qui adipisicing. Id cupidatat aute id ut excepteur exercitation magna pariatur. Mollit irure irure reprehenderit pariatur eiusmod proident Lorem deserunt duis cillum mollit.
## Tab Content 4
Dolore ex esse laboris elit magna esse sunt. Pariatur in veniam Lorem est occaecat do magna nisi mollit ipsum sit adipisicing fugiat ex. Pariatur ullamco exercitation ea qui adipisicing. Id cupidatat aute id ut excepteur exercitation magna pariatur. Mollit irure irure reprehenderit pariatur eiusmod proident Lorem deserunt duis cillum mollit.
```
"use client"
import { Button, Heading, Tabs, Text } from "@chakra-ui/react"
import { CloseButton } from "@/components/ui/close-button"
import { useState } from "react"
import { LuPlus } from "react-icons/lu"
interface Item {
id: string
title: string
content: React.ReactNode
}
const items: Item[] = [
{ id: "1", title: "Tab", content: "Tab Content" },
{ id: "2", title: "Tab", content: "Tab Content" },
{ id: "3", title: "Tab", content: "Tab Content" },
{ id: "4", title: "Tab", content: "Tab Content" },
]
const uuid = () => {
return Math.random().toString(36).substring(2, 15)
}
const Demo = () => {
const [tabs, setTabs] = useState<Item[]>(items)
const [selectedTab, setSelectedTab] = useState<string | null>(items[0].id)
const addTab = () => {
const newTabs = [...tabs]
const uid = uuid()
newTabs.push({
id: uid,
title: `Tab`,
content: `Tab Body`,
})
setTabs(newTabs)
setSelectedTab(newTabs[newTabs.length - 1].id)
}
const removeTab = (id: string) => {
if (tabs.length > 1) {
const newTabs = [...tabs].filter((tab) => tab.id !== id)
setTabs(newTabs)
}
}
return (
<Tabs.Root
value={selectedTab}
variant="outline"
size="sm"
onValueChange={(e) => setSelectedTab(e.value)}
>
<Tabs.List flex="1 1 auto">
{tabs.map((item) => (
<Tabs.Trigger value={item.id} key={item.id}>
{item.title}{" "}
<CloseButton
as="span"
role="button"
size="2xs"
me="-2"
onClick={(e) => {
e.stopPropagation()
removeTab(item.id)
}}
/>
</Tabs.Trigger>
))}
<Button
alignSelf="center"
ms="2"
size="2xs"
variant="ghost"
onClick={addTab}
>
<LuPlus /> Add Tab
</Button>
</Tabs.List>
<Tabs.ContentGroup>
{tabs.map((item) => (
<Tabs.Content value={item.id} key={item.id}>
<Heading size="xl" my="6">
{item.content} {item.id}
</Heading>
<Text>
Dolore ex esse laboris elit magna esse sunt. Pariatur in veniam
Lorem est occaecat do magna nisi mollit ipsum sit adipisicing
fugiat ex. Pariatur ullamco exercitation ea qui adipisicing. Id
cupidatat aute id ut excepteur exercitation magna pariatur. Mollit
irure irure reprehenderit pariatur eiusmod proident Lorem deserunt
duis cillum mollit.
</Text>
</Tabs.Content>
))}
</Tabs.ContentGroup>
</Tabs.Root>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`activationMode``'\'automatic\''`
`'manual' | 'automatic'`
The activation mode of the tabs. Can be \`manual\` or \`automatic\` - \`manual\`: Tabs are activated when clicked or press \`enter\` key. - \`automatic\`: Tabs are activated when receiving focus
`lazyMount``false`
`boolean`
Whether to enable lazy mounting
`loopFocus``true`
`boolean`
Whether the keyboard navigation will loop from last tab to first, and vice versa.
`orientation``'\'horizontal\''`
`'horizontal' | 'vertical'`
The orientation of the tabs. Can be \`horizontal\` or \`vertical\` - \`horizontal\`: only left and right arrow key navigation will work. - \`vertical\`: only up and down arrow key navigation will work.
`unmountOnExit``false`
`boolean`
Whether to unmount on exit.
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'sm' | 'md' | 'lg'`
The size of the component
`variant``'line'`
`'line' | 'subtle' | 'enclosed' | 'outline' | 'plain'`
The variant of the component
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`composite`
`boolean`
Whether the tab is composite
`defaultValue`
`string`
The initial value of the tabs when it is first rendered. Use when you do not need to control the state of the tabs.
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ root: string trigger: string list: string content: string indicator: string }>`
The ids of the elements in the tabs. Useful for composition.
`onFocusChange`
`(details: FocusChangeDetails) => void`
Callback to be called when the focused tab changes
`onValueChange`
`(details: ValueChangeDetails) => void`
Callback to be called when the selected/active tab changes
`translations`
`IntlTranslations`
Specifies the localized strings that identifies the accessibility elements and their states
`value`
`string`
The selected tab id
`fitted`
`'true' | 'false'`
The fitted of the component
`justify`
`'start' | 'center' | 'end'`
The justify of the component
### [Trigger]()
PropDefaultType`value`*
`string`
The value of the tab
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`disabled`
`boolean`
Whether the tab is disabled
### [Content]()
PropDefaultType`value`*
`string`
The value of the tab
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
[Previous
\
Switch](https://www.chakra-ui.com/docs/components/switch)
[Next
\
Table](https://www.chakra-ui.com/docs/components/table) |
https://www.chakra-ui.com/docs/components/table | 1. Components
2. Table
# Table
Used to display data in a tabular format.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/table)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-table--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/table.ts)
PreviewCode
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
```
import { Table } from "@chakra-ui/react"
const Demo = () => {
return (
<Table.Root size="sm">
<Table.Header>
<Table.Row>
<Table.ColumnHeader>Product</Table.ColumnHeader>
<Table.ColumnHeader>Category</Table.ColumnHeader>
<Table.ColumnHeader textAlign="end">Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{items.map((item) => (
<Table.Row key={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
)
}
const items = [
{ id: 1, name: "Laptop", category: "Electronics", price: 999.99 },
{ id: 2, name: "Coffee Maker", category: "Home Appliances", price: 49.99 },
{ id: 3, name: "Desk Chair", category: "Furniture", price: 150.0 },
{ id: 4, name: "Smartphone", category: "Electronics", price: 799.99 },
{ id: 5, name: "Headphones", category: "Accessories", price: 199.99 },
]
```
## [Usage]()
```
import { Table } from "@chakra-ui/react"
```
```
<Table.Root>
<Table.Header>
<Table.Row>
<Table.ColumnHeader />
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell />
</Table.Row>
</Table.Body>
<Table.Footer>
<Table.Row>
<Table.Cell />
</Table.Row>
</Table.Footer>
</Table.Root>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the table.
PreviewCode
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
```
import { For, Stack, Table } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack gap="10">
<For each={["sm", "md", "lg"]}>
{(size) => (
<Table.Root key={size} size={size}>
<Table.Header>
<Table.Row>
<Table.ColumnHeader>Product</Table.ColumnHeader>
<Table.ColumnHeader>Category</Table.ColumnHeader>
<Table.ColumnHeader textAlign="end">Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{items.map((item) => (
<Table.Row key={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
)}
</For>
</Stack>
)
}
const items = [
{ id: 1, name: "Laptop", category: "Electronics", price: 999.99 },
{ id: 2, name: "Coffee Maker", category: "Home Appliances", price: 49.99 },
{ id: 3, name: "Desk Chair", category: "Furniture", price: 150.0 },
{ id: 4, name: "Smartphone", category: "Electronics", price: 799.99 },
{ id: 5, name: "Headphones", category: "Accessories", price: 199.99 },
]
```
### [Variants]()
Use the `variant` prop to change the appearance of the table.
PreviewCode
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
```
import { For, Stack, Table } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack gap="10">
<For each={["line", "outline"]}>
{(variant) => (
<Table.Root key={variant} size="sm" variant={variant}>
<Table.Header>
<Table.Row>
<Table.ColumnHeader>Product</Table.ColumnHeader>
<Table.ColumnHeader>Category</Table.ColumnHeader>
<Table.ColumnHeader textAlign="end">Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{items.map((item) => (
<Table.Row key={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
)}
</For>
</Stack>
)
}
const items = [
{ id: 1, name: "Laptop", category: "Electronics", price: 999.99 },
{ id: 2, name: "Coffee Maker", category: "Home Appliances", price: 49.99 },
{ id: 3, name: "Desk Chair", category: "Furniture", price: 150.0 },
{ id: 4, name: "Smartphone", category: "Electronics", price: 799.99 },
{ id: 5, name: "Headphones", category: "Accessories", price: 199.99 },
]
```
### [Striped]()
Use the `striped` prop to add zebra-stripes to the table.
PreviewCode
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
```
import { Table } from "@chakra-ui/react"
const Demo = () => {
return (
<Table.Root size="sm" striped>
<Table.Header>
<Table.Row>
<Table.ColumnHeader>Product</Table.ColumnHeader>
<Table.ColumnHeader>Category</Table.ColumnHeader>
<Table.ColumnHeader textAlign="end">Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{items.map((item) => (
<Table.Row key={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
)
}
const items = [
{ id: 1, name: "Laptop", category: "Electronics", price: 999.99 },
{ id: 2, name: "Coffee Maker", category: "Home Appliances", price: 49.99 },
{ id: 3, name: "Desk Chair", category: "Furniture", price: 150.0 },
{ id: 4, name: "Smartphone", category: "Electronics", price: 799.99 },
{ id: 5, name: "Headphones", category: "Accessories", price: 199.99 },
]
```
### [Column Border]()
Use the `showColumnBorder` prop to add borders between columns.
PreviewCode
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
```
import { Table } from "@chakra-ui/react"
const Demo = () => {
return (
<Table.Root size="sm" showColumnBorder>
<Table.Header>
<Table.Row>
<Table.ColumnHeader>Product</Table.ColumnHeader>
<Table.ColumnHeader>Category</Table.ColumnHeader>
<Table.ColumnHeader textAlign="end">Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{items.map((item) => (
<Table.Row key={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
)
}
const items = [
{ id: 1, name: "Laptop", category: "Electronics", price: 999.99 },
{ id: 2, name: "Coffee Maker", category: "Home Appliances", price: 49.99 },
{ id: 3, name: "Desk Chair", category: "Furniture", price: 150.0 },
{ id: 4, name: "Smartphone", category: "Electronics", price: 799.99 },
{ id: 5, name: "Headphones", category: "Accessories", price: 199.99 },
]
```
### [Overflow]()
Render the `Table.ScrollArea` component to enable horizontal scrolling.
PreviewCode
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
```
import { Table } from "@chakra-ui/react"
const Demo = () => {
return (
<Table.ScrollArea borderWidth="1px" maxW="xl">
<Table.Root size="sm" variant="outline">
<Table.Header>
<Table.Row>
<Table.ColumnHeader minW="400px">Product</Table.ColumnHeader>
<Table.ColumnHeader minW="400px">Category</Table.ColumnHeader>
<Table.ColumnHeader minW="200px" textAlign="end">
Price
</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{items.map((item) => (
<Table.Row key={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
</Table.ScrollArea>
)
}
const items = [
{ id: 1, name: "Laptop", category: "Electronics", price: 999.99 },
{ id: 2, name: "Coffee Maker", category: "Home Appliances", price: 49.99 },
{ id: 3, name: "Desk Chair", category: "Furniture", price: 150.0 },
{ id: 4, name: "Smartphone", category: "Electronics", price: 799.99 },
{ id: 5, name: "Headphones", category: "Accessories", price: 199.99 },
]
```
### [Sticky Header]()
Use the `stickyHeader` prop to make the table header sticky.
PreviewCode
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
```
import { Table } from "@chakra-ui/react"
const Demo = () => {
return (
<Table.ScrollArea borderWidth="1px" rounded="md" height="160px">
<Table.Root size="sm" stickyHeader>
<Table.Header>
<Table.Row bg="bg.subtle">
<Table.ColumnHeader>Product</Table.ColumnHeader>
<Table.ColumnHeader>Category</Table.ColumnHeader>
<Table.ColumnHeader textAlign="end">Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{items.map((item) => (
<Table.Row key={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
</Table.ScrollArea>
)
}
const items = [
{ id: 1, name: "Laptop", category: "Electronics", price: 999.99 },
{ id: 2, name: "Coffee Maker", category: "Home Appliances", price: 49.99 },
{ id: 3, name: "Desk Chair", category: "Furniture", price: 150.0 },
{ id: 4, name: "Smartphone", category: "Electronics", price: 799.99 },
{ id: 5, name: "Headphones", category: "Accessories", price: 199.99 },
]
```
### [Highlight on Hover]()
Use the `interactive` prop to highlight rows on hover.
PreviewCode
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
```
import { Table } from "@chakra-ui/react"
const Demo = () => {
return (
<Table.Root size="sm" interactive>
<Table.Header>
<Table.Row>
<Table.ColumnHeader>Product</Table.ColumnHeader>
<Table.ColumnHeader>Category</Table.ColumnHeader>
<Table.ColumnHeader textAlign="end">Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{items.map((item) => (
<Table.Row key={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
)
}
const items = [
{ id: 1, name: "Laptop", category: "Electronics", price: 999.99 },
{ id: 2, name: "Coffee Maker", category: "Home Appliances", price: 49.99 },
{ id: 3, name: "Desk Chair", category: "Furniture", price: 150.0 },
{ id: 4, name: "Smartphone", category: "Electronics", price: 799.99 },
{ id: 5, name: "Headphones", category: "Accessories", price: 199.99 },
]
```
### [Pagination]()
Here's an example of how to compose a table with pagination.
PreviewCode
## Products
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
1235
```
import { HStack, Heading, Stack, Table } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<Stack width="full" gap="5">
<Heading size="xl">Products</Heading>
<Table.Root size="sm" variant="outline" striped>
<Table.Header>
<Table.Row>
<Table.ColumnHeader>Product</Table.ColumnHeader>
<Table.ColumnHeader>Category</Table.ColumnHeader>
<Table.ColumnHeader textAlign="end">Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{items.map((item) => (
<Table.Row key={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
<PaginationRoot count={items.length * 5} pageSize={5} page={1}>
<HStack wrap="wrap">
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
</Stack>
)
}
const items = [
{ id: 1, name: "Laptop", category: "Electronics", price: 999.99 },
{ id: 2, name: "Coffee Maker", category: "Home Appliances", price: 49.99 },
{ id: 3, name: "Desk Chair", category: "Furniture", price: 150.0 },
{ id: 4, name: "Smartphone", category: "Electronics", price: 799.99 },
{ id: 5, name: "Headphones", category: "Accessories", price: 199.99 },
]
```
### [Action Bar]()
Here's an example of how to compose a table with an action bar and checkboxes. This is useful for showing actions for selected table rows.
PreviewCode
ProductCategoryPrice
LaptopElectronics$999.99
Coffee MakerHome Appliances$49.99
Desk ChairFurniture$150
SmartphoneElectronics$799.99
HeadphonesAccessories$199.99
```
"use client"
import { Kbd, Table } from "@chakra-ui/react"
import {
ActionBarContent,
ActionBarRoot,
ActionBarSelectionTrigger,
ActionBarSeparator,
} from "@/components/ui/action-bar"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import { useState } from "react"
const Demo = () => {
const [selection, setSelection] = useState<string[]>([])
const hasSelection = selection.length > 0
const indeterminate = hasSelection && selection.length < items.length
const rows = items.map((item) => (
<Table.Row
key={item.name}
data-selected={selection.includes(item.name) ? "" : undefined}
>
<Table.Cell>
<Checkbox
top="1"
aria-label="Select row"
checked={selection.includes(item.name)}
onCheckedChange={(changes) => {
setSelection((prev) =>
changes.checked
? [...prev, item.name]
: selection.filter((name) => name !== item.name),
)
}}
/>
</Table.Cell>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell>${item.price}</Table.Cell>
</Table.Row>
))
return (
<>
<Table.Root>
<Table.Header>
<Table.Row>
<Table.ColumnHeader w="6">
<Checkbox
top="1"
aria-label="Select all rows"
checked={indeterminate ? "indeterminate" : selection.length > 0}
onCheckedChange={(changes) => {
setSelection(
changes.checked ? items.map((item) => item.name) : [],
)
}}
/>
</Table.ColumnHeader>
<Table.ColumnHeader>Product</Table.ColumnHeader>
<Table.ColumnHeader>Category</Table.ColumnHeader>
<Table.ColumnHeader>Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>{rows}</Table.Body>
</Table.Root>
<ActionBarRoot open={hasSelection}>
<ActionBarContent>
<ActionBarSelectionTrigger>
{selection.length} selected
</ActionBarSelectionTrigger>
<ActionBarSeparator />
<Button variant="outline" size="sm">
Delete <Kbd>⌫</Kbd>
</Button>
<Button variant="outline" size="sm">
Share <Kbd>T</Kbd>
</Button>
</ActionBarContent>
</ActionBarRoot>
</>
)
}
const items = [
{ id: 1, name: "Laptop", category: "Electronics", price: 999.99 },
{ id: 2, name: "Coffee Maker", category: "Home Appliances", price: 49.99 },
{ id: 3, name: "Desk Chair", category: "Furniture", price: 150.0 },
{ id: 4, name: "Smartphone", category: "Electronics", price: 799.99 },
{ id: 5, name: "Headphones", category: "Accessories", price: 199.99 },
]
```
### [Column Group]()
Use the `Table.ColumnGroup` component to distribute the column widths using the html `colgroup` element.
warning
The only prop that works for this component is `htmlWidth`
PreviewCode
ProductCategoryPriceLaptopElectronics999.99Coffee MakerHome Appliances49.99Desk ChairFurniture150SmartphoneElectronics799.99HeadphonesAccessories199.99
```
import { Table } from "@chakra-ui/react"
const Demo = () => {
return (
<Table.Root size="sm" variant="outline">
<Table.ColumnGroup>
<Table.Column htmlWidth="50%" />
<Table.Column htmlWidth="40%" />
<Table.Column />
</Table.ColumnGroup>
<Table.Header>
<Table.Row>
<Table.ColumnHeader>Product</Table.ColumnHeader>
<Table.ColumnHeader>Category</Table.ColumnHeader>
<Table.ColumnHeader textAlign="end">Price</Table.ColumnHeader>
</Table.Row>
</Table.Header>
<Table.Body>
{items.map((item) => (
<Table.Row key={item.id}>
<Table.Cell>{item.name}</Table.Cell>
<Table.Cell>{item.category}</Table.Cell>
<Table.Cell textAlign="end">{item.price}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Root>
)
}
const items = [
{ id: 1, name: "Laptop", category: "Electronics", price: 999.99 },
{ id: 2, name: "Coffee Maker", category: "Home Appliances", price: 49.99 },
{ id: 3, name: "Desk Chair", category: "Furniture", price: 150.0 },
{ id: 4, name: "Smartphone", category: "Electronics", price: 799.99 },
{ id: 5, name: "Headphones", category: "Accessories", price: 199.99 },
]
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`variant``'line'`
`'line' | 'outline'`
The variant of the component
`size``'md'`
`'sm' | 'md' | 'lg'`
The size of the component
`interactive`
`'true' | 'false'`
The interactive of the component
`stickyHeader`
`'true' | 'false'`
The stickyHeader of the component
`striped`
`'true' | 'false'`
The striped of the component
`showColumnBorder`
`'true' | 'false'`
The showColumnBorder of the component
`native`
`boolean`
If \`true\`, the table will style its descendants with nested selectors
`as`
`React.ElementType`
The underlying element to render.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Tabs](https://www.chakra-ui.com/docs/components/tabs)
[Next
\
Tag](https://www.chakra-ui.com/docs/components/tag) |
https://www.chakra-ui.com/docs/components/toggle-tip | 1. Components
2. Toggle Tip
# Toggle Tip
Looks like a tooltip, but works like a popover.
PreviewCode
This is some additional information.
```
import { Button } from "@/components/ui/button"
import { ToggleTip } from "@/components/ui/toggle-tip"
import { LuInfo } from "react-icons/lu"
const Demo = () => {
return (
<ToggleTip content="This is some additional information.">
<Button size="xs" variant="ghost">
<LuInfo />
</Button>
</ToggleTip>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `toggle-tip` snippet
```
npx @chakra-ui/cli snippet add toggle-tip
```
The snippet includes a closed component composition for the `Popover` component.
## [Usage]()
```
import { InfoTip, ToggleTip } from "@/components/ui/toggle-tip"
```
```
<ToggleTip content="...">
<button />
</ToggleTip>
```
## [Examples]()
### [Info Tip]()
Use the `InfoTip` component to display an info tip. This component renders an icon button with an info icon by default.
Useful for landing pages to display additional information about a feature.
PreviewCode
File size: 1.45 kB
The file size for content.tsx is 1.45kb
```
import { FormatByte, HStack, Text } from "@chakra-ui/react"
import { InfoTip } from "@/components/ui/toggle-tip"
const Demo = () => {
return (
<HStack justify="center">
<Text textStyle="lg">
File size: <FormatByte value={1450.45} />
</Text>
<InfoTip content="The file size for content.tsx is 1.45kb" />
</HStack>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`autoFocus``true`
`boolean`
Whether to automatically set focus on the first focusable content within the popover when opened.
`closeOnEscape``true`
`boolean`
Whether to close the popover when the escape key is pressed.
`closeOnInteractOutside``true`
`boolean`
Whether to close the popover when the user clicks outside of the popover.
`lazyMount``false`
`boolean`
Whether to enable lazy mounting
`modal``false`
`boolean`
Whether the popover should be modal. When set to \`true\`: - interaction with outside elements will be disabled - only popover content will be visible to screen readers - scrolling is blocked - focus is trapped within the popover
`portalled``true`
`boolean`
Whether the popover is portalled. This will proxy the tabbing behavior regardless of the DOM position of the popover content.
`unmountOnExit``false`
`boolean`
Whether to unmount on exit.
`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'xs' | 'sm' | 'md' | 'lg'`
The size of the component
`defaultOpen`
`boolean`
The initial open state of the popover when it is first rendered. Use when you do not need to control its open state.
`id`
`string`
The unique identifier of the machine.
`ids`
`Partial<{ anchor: string trigger: string content: string title: string description: string closeTrigger: string positioner: string arrow: string }>`
The ids of the elements in the popover. Useful for composition.
`immediate`
`boolean`
Whether to synchronize the present change immediately or defer it to the next frame
`initialFocusEl`
`() => HTMLElement | null`
The element to focus on when the popover is opened.
`onEscapeKeyDown`
`(event: KeyboardEvent) => void`
Function called when the escape key is pressed
`onExitComplete`
`() => void`
Function called when the animation ends in the closed state
`onFocusOutside`
`(event: FocusOutsideEvent) => void`
Function called when the focus is moved outside the component
`onInteractOutside`
`(event: InteractOutsideEvent) => void`
Function called when an interaction happens outside the component
`onOpenChange`
`(details: OpenChangeDetails) => void`
Function invoked when the popover opens or closes
`onPointerDownOutside`
`(event: PointerDownOutsideEvent) => void`
Function called when the pointer is pressed down outside the component
`open`
`boolean`
Whether the popover is open
`persistentElements`
`(() => Element | null)[]`
Returns the persistent elements that: - should not have pointer-events disabled - should not trigger the dismiss event
`positioning`
`PositioningOptions`
The user provided options used to position the popover content
`present`
`boolean`
Whether the node is present (controlled by the user)
`as`
`React.ElementType`
The underlying element to render.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Toast](https://www.chakra-ui.com/docs/components/toast)
[Next
\
Tooltip](https://www.chakra-ui.com/docs/components/tooltip) |
https://www.chakra-ui.com/docs/components/stat | 1. Components
2. Stat
# Stat
Used to display a statistic with a title and value.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/stat)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-stat--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/stat.ts)
PreviewCode
Unique visitors
192.1k
```
import { StatLabel, StatRoot, StatValueText } from "@/components/ui/stat"
const Demo = () => {
return (
<StatRoot>
<StatLabel>Unique visitors</StatLabel>
<StatValueText>192.1k</StatValueText>
</StatRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `stat` snippet
```
npx @chakra-ui/cli snippet add stat
```
The snippet includes a closed component composition for the `Stat` component.
## [Usage]()
```
import { StatLabel, StatRoot, StatValueText } from "@/components/ui/stat"
```
```
<StatRoot>
<StatLabel />
<StatValueText />
<StatHelpText>
<StatUpIndicator />
<StatDownIndicator />
</StatHelpText>
</StatRoot>
```
## [Examples]()
### [Format Options]()
Pass the `formatOptions` to the `StatValueText` component to format the value.
PreviewCode
Revenue
$935.40
```
import { StatLabel, StatRoot, StatValueText } from "@/components/ui/stat"
const Demo = () => {
return (
<StatRoot>
<StatLabel>Revenue</StatLabel>
<StatValueText
value={935.4}
formatOptions={{ style: "currency", currency: "USD" }}
/>
</StatRoot>
)
}
```
### [Indicator]()
Here's an example of how to display a statistic with an indicator.
PreviewCode
Unique visitors
192.1k
1.9%
```
import {
StatDownTrend,
StatLabel,
StatRoot,
StatValueText,
} from "@/components/ui/stat"
const Demo = () => {
return (
<StatRoot>
<StatLabel>Unique visitors</StatLabel>
<StatValueText>192.1k</StatValueText>
<StatDownTrend variant="plain" px="0">
1.9%
</StatDownTrend>
</StatRoot>
)
}
```
### [Info Tip]()
Pass the `info` prop to the `StatLabel` component to display an info tip.
PreviewCode
Unique
Some info
192.1k
```
import { StatLabel, StatRoot, StatValueText } from "@/components/ui/stat"
const Demo = () => {
return (
<StatRoot>
<StatLabel info="Some info">Unique </StatLabel>
<StatValueText>192.1k</StatValueText>
</StatRoot>
)
}
```
### [Value Unit]()
Here's an example of how to display a value with a unit.
PreviewCode
Time to complete
3 hr20 min
```
import {
StatLabel,
StatRoot,
StatValueText,
StatValueUnit,
} from "@/components/ui/stat"
const Demo = () => {
return (
<StatRoot>
<StatLabel>Time to complete</StatLabel>
<StatValueText alignItems="baseline">
3 <StatValueUnit>hr</StatValueUnit>
20 <StatValueUnit>min</StatValueUnit>
</StatValueText>
</StatRoot>
)
}
```
### [Progress Bar]()
Here's an example of how to display a statistic with a progress bar.
PreviewCode
This week
$1,340
+12% from last week
```
import { ProgressBar, ProgressRoot } from "@/components/ui/progress"
import {
StatHelpText,
StatLabel,
StatRoot,
StatValueText,
} from "@/components/ui/stat"
const Demo = () => {
return (
<StatRoot maxW="240px">
<StatLabel>This week</StatLabel>
<StatValueText
value={1340}
formatOptions={{
currency: "USD",
style: "currency",
maximumFractionDigits: 0,
}}
/>
<StatHelpText mb="2">+12% from last week</StatHelpText>
<ProgressRoot>
<ProgressBar />
</ProgressRoot>
</StatRoot>
)
}
```
### [Icon]()
Here's an example of how to display a statistic with an icon.
PreviewCode
Sales
$4.24k
```
import { HStack, Icon } from "@chakra-ui/react"
import { StatLabel, StatRoot, StatValueText } from "@/components/ui/stat"
import { LuDollarSign } from "react-icons/lu"
const Demo = () => {
return (
<StatRoot maxW="240px" borderWidth="1px" p="4" rounded="md">
<HStack justify="space-between">
<StatLabel>Sales</StatLabel>
<Icon color="fg.muted">
<LuDollarSign />
</Icon>
</HStack>
<StatValueText>$4.24k</StatValueText>
</StatRoot>
)
}
```
### [Trend]()
Here's an example of how to display a statistic with a trend indicator.
PreviewCode
Unique
$8,456.40
12%
since last month
```
import { HStack } from "@chakra-ui/react"
import {
StatHelpText,
StatLabel,
StatRoot,
StatUpTrend,
StatValueText,
} from "@/components/ui/stat"
const Demo = () => {
return (
<StatRoot>
<StatLabel>Unique </StatLabel>
<HStack>
<StatValueText
value={8456.4}
formatOptions={{ style: "currency", currency: "USD" }}
/>
<StatUpTrend>12%</StatUpTrend>
</HStack>
<StatHelpText>since last month</StatHelpText>
</StatRoot>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'sm' | 'md' | 'lg'`
The size of the component
`as`
`React.ElementType`
The underlying element to render.
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`unstyled`
`boolean`
Whether to remove the component's style.
[Previous
\
Spinner](https://www.chakra-ui.com/docs/components/spinner)
[Next
\
Status](https://www.chakra-ui.com/docs/components/status) |
https://www.chakra-ui.com/docs/components/tag | 1. Components
2. Tag
# Tag
Used for categorizing or labeling content
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/tag)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-tag--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/tag.ts)
PreviewCode
Plain Tag
Closable Tag
```
import { HStack } from "@chakra-ui/react"
import { Tag } from "@/components/ui/tag"
const Demo = () => {
return (
<HStack>
<Tag>Plain Tag</Tag>
<Tag closable>Closable Tag</Tag>
</HStack>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `tag` snippet
```
npx @chakra-ui/cli snippet add tag
```
The snippet includes a closed component composition for the `Tag` component.
## [Usage]()
```
import { Tag } from "@/components/ui/tag"
```
```
<Tag>Tag here</Tag>
```
## [Examples]()
### [Icon]()
Use the `startElement` prop to add an icon to the tag.
PreviewCode
Tag 2
Top Rated
```
import { HStack } from "@chakra-ui/react"
import { Tag } from "@/components/ui/tag"
import { LuFileBadge, LuUserCircle } from "react-icons/lu"
const Demo = () => {
return (
<HStack>
<Tag startElement={<LuUserCircle />}>Tag 2</Tag>
<Tag startElement={<LuFileBadge />}>Top Rated</Tag>
</HStack>
)
}
```
### [Variants]()
Use the `variant` prop to change the appearance of the tag.
PreviewCode
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
```
import { For, HStack, Stack } from "@chakra-ui/react"
import { Tag } from "@/components/ui/tag"
import { HiCheck } from "react-icons/hi"
const Demo = () => {
return (
<Stack gap="8">
<For each={["subtle", "solid", "outline", "surface"]}>
{(variant) => (
<HStack key={variant}>
<Tag variant={variant}>Gray</Tag>
<Tag variant={variant} closable>
Gray
</Tag>
<Tag endElement={<HiCheck />} variant={variant}>
Gray
</Tag>
</HStack>
)}
</For>
</Stack>
)
}
```
### [Sizes]()
Use the `size` prop to change the size of the tag.
PreviewCode
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
Gray
```
import { For, HStack, Stack } from "@chakra-ui/react"
import { Tag } from "@/components/ui/tag"
import { HiCheck } from "react-icons/hi"
const Demo = () => {
return (
<Stack gap="8">
<For each={["sm", "md", "lg"]}>
{(size) => (
<HStack key={size}>
<Tag size={size}>Gray</Tag>
<Tag size={size} closable>
Gray
</Tag>
<Tag endElement={<HiCheck />} size={size}>
Gray
</Tag>
</HStack>
)}
</For>
</Stack>
)
}
```
### [Colors]()
Use the `colorPalette` prop to change the color of the tag.
PreviewCode
gray
Content
Content
Content
red
Content
Content
Content
green
Content
Content
Content
blue
Content
Content
Content
teal
Content
Content
Content
pink
Content
Content
Content
purple
Content
Content
Content
cyan
Content
Content
Content
orange
Content
Content
Content
yellow
Content
Content
Content
```
import { Stack, Text } from "@chakra-ui/react"
import { colorPalettes } from "compositions/lib/color-palettes"
import { Tag } from "@/components/ui/tag"
import { HiPlus } from "react-icons/hi"
const Demo = () => {
return (
<Stack gap="2" align="flex-start">
{colorPalettes.map((colorPalette) => (
<Stack
align="center"
key={colorPalette}
direction="row"
gap="10"
px="4"
>
<Text minW="8ch">{colorPalette}</Text>
<Tag size="sm" colorPalette={colorPalette}>
Content
</Tag>
<Tag startElement={<HiPlus />} size="sm" colorPalette={colorPalette}>
Content
</Tag>
<Tag size="sm" colorPalette={colorPalette} variant="solid" closable>
Content
</Tag>
</Stack>
))}
</Stack>
)
}
```
### [Closable]()
Use the `closable` prop to make the tag closable.
PreviewCode
Tag 1
Tag 2
```
import { HStack } from "@chakra-ui/react"
import { Tag } from "@/components/ui/tag"
import { LuActivity } from "react-icons/lu"
const Demo = () => {
return (
<HStack>
<Tag startElement={<LuActivity />} closable>
Tag 1
</Tag>
<Tag closable>Tag 2</Tag>
</HStack>
)
}
```
### [Overflow]()
Use the `maxWidth` prop to control the maximum width of the tag. When the content exceeds this width, it will be truncated with an ellipsis.
This is particularly useful when dealing with dynamic or user-generated content where the length might vary.
PreviewCode
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam molestias, laboriosam, quod, quia quidem quae voluptatem natus exercitationem autem quibusdam
```
import { Tag } from "@/components/ui/tag"
const Demo = () => {
return (
<Tag size="sm" colorPalette="blue" maxW="200px" closable>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam
molestias, laboriosam, quod, quia quidem quae voluptatem natus
exercitationem autem quibusdam
</Tag>
)
}
```
### [Avatar]()
The tag component has been designed to work well with the `Avatar` component.
Note: Set the avatar size to `full` to ensure it's sized correctly.
PreviewCode
JD![](https://i.pravatar.cc/300?u=1)
Emily (sm)
JD![](https://i.pravatar.cc/300?u=1)
Emily (md)
JD![](https://i.pravatar.cc/300?u=1)
Emily (lg)
JD![](https://i.pravatar.cc/300?u=1)
Emily (xl)
```
import { For, HStack } from "@chakra-ui/react"
import { Avatar } from "@/components/ui/avatar"
import { Tag } from "@/components/ui/tag"
const Demo = () => {
return (
<HStack>
<For each={["sm", "md", "lg", "xl"]}>
{(size) => (
<Tag
key={size}
rounded="full"
size={size}
startElement={
<Avatar
size="full"
src="https://i.pravatar.cc/300?u=1"
name="John Doe"
/>
}
>
Emily ({size})
</Tag>
)}
</For>
</HStack>
)
}
```
### [Render as button]()
Use the `asChild` prop to render the tag as a button.
Note: Import the Tag from `@chakra-ui/react` to use this prop.
PreviewCode
Fish
```
import { Tag } from "@chakra-ui/react"
import { LuCheck } from "react-icons/lu"
const Demo = () => {
return (
<Tag.Root asChild variant="solid">
<button type="submit">
<Tag.Label>Fish </Tag.Label>
<LuCheck />
</button>
</Tag.Root>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`colorPalette``'gray'`
`'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'`
The color palette of the component
`size``'md'`
`'sm' | 'md' | 'lg'`
The size of the component
`variant``'surface'`
`'subtle' | 'solid' | 'outline' | 'surface'`
The variant of the component
[Previous
\
Table](https://www.chakra-ui.com/docs/components/table)
[Next
\
Textarea](https://www.chakra-ui.com/docs/components/textarea) |
https://www.chakra-ui.com/docs/components/toast | 1. Components
2. Toast
# Toast
Used to display a temporary message to the user
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/toast)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-toast--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/toast.ts)[Ark](https://ark-ui.com/react/docs/components/toast)
PreviewCode
Show Toast
```
"use client"
import { Button } from "@chakra-ui/react"
import { toaster } from "@/components/ui/toaster"
const Demo = () => {
return (
<Button
variant="outline"
size="sm"
onClick={() =>
toaster.create({
description: "File saved successfully",
type: "info",
})
}
>
Show Toast
</Button>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `toaster` snippet
```
npx @chakra-ui/cli snippet add toaster
```
The snippet includes a closed component composition for the `Toast` component.
## [Usage]()
```
import { Toaster, toaster } from "@/components/ui/toaster"
```
First, render the `Toaster` component in your app.
```
<Toaster />
```
Then, create a toast by calling the `toaster` function.
```
toaster.create({
title: "Toast Title",
description: "Toast Description",
})
```
## [Examples]()
### [Persistent Toast]()
Set the `type` prop to `"loading"` to create a persistent toast.
PreviewCode
Show Toast
```
"use client"
import { Button } from "@chakra-ui/react"
import { toaster } from "@/components/ui/toaster"
const Demo = () => {
return (
<Button
variant="outline"
size="sm"
onClick={() =>
toaster.create({
description: "File saved successfully",
type: "loading",
})
}
>
Show Toast
</Button>
)
}
```
### [Types]()
Here's an example of each type of toast.
PreviewCode
successerrorwarninginfo
```
"use client"
import { Button, For, HStack } from "@chakra-ui/react"
import { toaster } from "@/components/ui/toaster"
const Demo = () => {
return (
<HStack>
<For each={["success", "error", "warning", "info"]}>
{(type) => (
<Button
size="sm"
variant="outline"
key={type}
onClick={() =>
toaster.create({
title: `Toast status is ${type}`,
type: type,
})
}
>
{type}
</Button>
)}
</For>
</HStack>
)
}
```
### [With Action]()
Use the `action` and `actionLabel` prop to add an action to the toast.
When the action trigger is clicked, the toast will be closed.
PreviewCode
Click me
```
"use client"
import { Button } from "@chakra-ui/react"
import { toaster } from "@/components/ui/toaster"
const Demo = () => {
return (
<Button
variant="outline"
size="sm"
onClick={() =>
toaster.success({
title: "Update successful",
description: "File saved successfully to the server",
action: {
label: "Undo",
onClick: () => console.log("Undo"),
},
})
}
>
Click me
</Button>
)
}
```
### [Promise]()
Use the `toaster.promise` to create a toast that resolves when the promise is resolved.
Next, you can define the toast options (title, description, etc.) for each state of the promise.
PreviewCode
Show Toast
```
"use client"
import { Button } from "@chakra-ui/react"
import { toaster } from "@/components/ui/toaster"
const Demo = () => {
return (
<Button
variant="outline"
size="sm"
onClick={() => {
const promise = new Promise<void>((resolve) => {
setTimeout(() => resolve(), 5000)
})
toaster.promise(promise, {
success: {
title: "Successfully uploaded!",
description: "Looks great",
},
error: {
title: "Upload failed",
description: "Something wrong with the upload",
},
loading: { title: "Uploading...", description: "Please wait" },
})
}}
>
Show Toast
</Button>
)
}
```
### [Custom Duration]()
Use the `duration` prop to set the duration of the toast.
PreviewCode
Show Toast
```
"use client"
import { Button } from "@chakra-ui/react"
import { toaster } from "@/components/ui/toaster"
const Demo = () => {
return (
<Button
variant="outline"
size="sm"
onClick={() =>
toaster.create({
description: "File saved successfully",
duration: 6000,
})
}
>
Show Toast
</Button>
)
}
```
### [Pause and Play]()
Use the `pause` and `resume` methods on the `toaster` object to pause and play the toast.
Pausing a toast prevents it from timing out, while resuming it will reenable the timeout using the remaining duration.
PreviewCode
Show ToastPause ToastPlay Toast
```
"use client"
import { Button, HStack } from "@chakra-ui/react"
import { toaster } from "@/components/ui/toaster"
import { useId, useState } from "react"
import { HiPause, HiPlay } from "react-icons/hi"
const Demo = () => {
const id = useId()
const [paused, setPaused] = useState(false)
const [shown, setShown] = useState(false)
const show = () => {
toaster.success({
id,
title: "This is a success toast",
onStatusChange: (details) => {
if (details.status === "visible") {
setShown(true)
} else if (details.status === "dismissing") {
setShown(false)
}
},
})
}
const pause = () => {
toaster.pause(id)
setPaused(true)
}
const play = () => {
toaster.resume(id)
setPaused(false)
}
return (
<HStack>
<Button variant="outline" size="sm" onClick={show} disabled={shown}>
Show Toast
</Button>
<Button
variant="outline"
size="sm"
onClick={pause}
disabled={!shown || paused}
>
<HiPause />
Pause Toast
</Button>
<Button
variant="outline"
size="sm"
onClick={play}
disabled={!shown || !paused}
>
<HiPlay />
Play Toast
</Button>
</HStack>
)
}
```
### [Lifecycle]()
Use the `onStatusChange` prop on the `toaster` function to listen for changes to the toast's status.
PreviewCode
Show Toast
```
"use client"
import { Button, HStack, Stack, Text } from "@chakra-ui/react"
import { toaster } from "@/components/ui/toaster"
import { useState } from "react"
const Demo = () => {
const [statusLog, setStatusLog] = useState<[number, string][]>([])
const [dismissed, setDismissed] = useState(true)
return (
<Stack align="flex-start">
<Button
disabled={!dismissed}
variant="outline"
size="sm"
onClick={() =>
toaster.create({
description: "This is a toast",
type: "info",
onStatusChange({ status }) {
setDismissed(status === "unmounted")
setStatusLog((prev) => [[Date.now(), status], ...prev])
},
})
}
>
Show Toast
</Button>
<Stack padding="2" width="full" role="log" borderWidth="1px" minH="100px">
{statusLog.map(([time, toastStatus], i) => {
const date = new Date(time)
return (
<HStack as="pre" fontFamily="mono" textStyle="sm" key={i}>
{date.toLocaleTimeString()}{" "}
<Text fontWeight="bold">{toastStatus}</Text>
</HStack>
)
})}
</Stack>
</Stack>
)
}
```
### [Maximum Visible Toasts]()
Set the `max` prop on the `createToaster` function to define the maximum number of toasts that can be rendered at any one time. Any extra toasts will be queued and rendered when a toast has been dismissed.
@/components/ui/toaster.tsx
```
const toaster = createToaster({
max: 3,
})
```
### [Placement]()
Toasts can be displayed on all four corners of a page. We recommend picking one desired position and configure it in the `createToaster` function.
@/components/ui/toaster.tsx
```
const toaster = createToaster({
placement: "top-end",
})
```
### [Overlapping Toasts]()
By default, toasts are stacked on top of each other. To make the toasts overlap each other, set the `overlap` prop to `true` in the `createToaster` function.
@/components/ui/toaster.tsx
```
const toaster = createToaster({
placement: "top-end",
overlap: true,
})
```
### [Offset]()
Set the `offset` prop in the `createToaster` function to offset the toasts from the edges of the screen.
@/components/ui/toaster.tsx
```
const toaster = createToaster({
offset: "20px",
})
```
Alternatively, you can use the `offset` prop to set the offset for each edge of the screen.
@/components/ui/toaster.tsx
```
const toaster = createToaster({
offset: { left: "20px", top: "20px", right: "20px", bottom: "20px" },
})
```
[Previous
\
Timeline](https://www.chakra-ui.com/docs/components/timeline)
[Next
\
Toggle Tip](https://www.chakra-ui.com/docs/components/toggle-tip) |
https://www.chakra-ui.com/docs/components/tooltip | 1. Components
2. Tooltip
# Tooltip
Used to display additional information when a user hovers over an element.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/tooltip)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-tooltip--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/tooltip.ts)[Ark](https://ark-ui.com/react/docs/components/tooltip)
PreviewCode
Hover me
This is the tooltip content
```
import { Button } from "@chakra-ui/react"
import { Tooltip } from "@/components/ui/tooltip"
const Demo = () => {
return (
<Tooltip content="This is the tooltip content">
<Button variant="outline" size="sm">
Hover me
</Button>
</Tooltip>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `tooltip` snippet
```
npx @chakra-ui/cli snippet add tooltip
```
The snippet includes a closed component composition for the `Tooltip` component.
## [Usage]()
```
import { Tooltip } from "@/components/ui/tooltip"
```
```
<Tooltip content="...">
<button />
</Tooltip>
```
## [Examples]()
### [Arrow]()
Use the `showArrow` prop to show an arrow on the tooltip.
PreviewCode
Hover me
This is the tooltip content
```
import { Button } from "@chakra-ui/react"
import { Tooltip } from "@/components/ui/tooltip"
const Demo = () => {
return (
<Tooltip showArrow content="This is the tooltip content">
<Button variant="outline" size="sm">
Hover me
</Button>
</Tooltip>
)
}
```
### [Placement]()
Use the `positioning.placement` prop to change the position of the tooltip.
PreviewCode
Hover me
This is the tooltip content
```
import { Button } from "@chakra-ui/react"
import { Tooltip } from "@/components/ui/tooltip"
const Demo = () => {
return (
<Tooltip
content="This is the tooltip content"
positioning={{ placement: "right-end" }}
>
<Button variant="outline" size="sm">
Hover me
</Button>
</Tooltip>
)
}
```
### [Offset]()
Use the `positioning.offset` prop to change the offset of the tooltip.
PreviewCode
Hover me
This is the tooltip content
```
import { Button } from "@chakra-ui/react"
import { Tooltip } from "@/components/ui/tooltip"
const Demo = () => {
return (
<Tooltip
content="This is the tooltip content"
positioning={{ offset: { mainAxis: 4, crossAxis: 4 } }}
>
<Button variant="outline" size="sm">
Hover me
</Button>
</Tooltip>
)
}
```
### [Delay]()
Use the `openDelay` and `closeDelay` prop to change the delay of the tooltip.
PreviewCode
Delay (open: 500ms, close: 100ms)
This is the tooltip content
```
import { Button } from "@chakra-ui/react"
import { Tooltip } from "@/components/ui/tooltip"
const Demo = () => {
return (
<Tooltip
content="This is the tooltip content"
openDelay={500}
closeDelay={100}
>
<Button variant="outline" size="sm">
Delay (open: 500ms, close: 100ms)
</Button>
</Tooltip>
)
}
```
### [Custom Background]()
Use the `--tooltip-bg` CSS variable to change the background color of the tooltip.
PreviewCode
3
This is the tooltip content
```
import { Button } from "@/components/ui/button"
import { Tooltip } from "@/components/ui/tooltip"
import { FaBell } from "react-icons/fa"
export const TooltipWithCustomBg = () => (
<Tooltip
showArrow
content="This is the tooltip content"
contentProps={{ css: { "--tooltip-bg": "tomato" } }}
>
<Button variant="outline" size="sm">
<FaBell /> 3
</Button>
</Tooltip>
)
```
### [Controlled]()
Use the `open` and `onOpenChange` prop to control the visibility of the tooltip.
PreviewCode
Show tooltip
Tooltip Content
```
"use client"
import { Button } from "@/components/ui/button"
import { Tooltip } from "@/components/ui/tooltip"
import { useState } from "react"
const Demo = () => {
const [open, setOpen] = useState(false)
return (
<Tooltip
content="Tooltip Content"
open={open}
onOpenChange={(e) => setOpen(e.open)}
>
<Button size="sm">{open ? "Hide" : "Show"} tooltip</Button>
</Tooltip>
)
}
```
### [Interactive]()
Use the `interactive` prop to keep the tooltip open when interacting with its content.
PreviewCode
Hover me
This is the tooltip content
```
import { Button } from "@chakra-ui/react"
import { Tooltip } from "@/components/ui/tooltip"
const Demo = () => {
return (
<Tooltip content="This is the tooltip content" interactive>
<Button variant="outline" size="sm">
Hover me
</Button>
</Tooltip>
)
}
```
### [Disabled]()
Use the `disabled` prop to disable the tooltip. When disabled, the tooltip will not be shown.
PreviewCode
Hover me
```
import { Button } from "@chakra-ui/react"
import { Tooltip } from "@/components/ui/tooltip"
const Demo = () => {
return (
<Tooltip content="This is the tooltip content" disabled>
<Button variant="outline" size="sm">
Hover me
</Button>
</Tooltip>
)
}
```
### [With Avatar]()
Here's an example of how to use the `Tooltip` component with an `Avatar` component.
PreviewCode
SA![](https://bit.ly/sage-adebayo)
Segun Adebayo is online
```
import { Avatar } from "@/components/ui/avatar"
import { Tooltip } from "@/components/ui/tooltip"
import { useId } from "react"
const Demo = () => {
const id = useId()
return (
<Tooltip ids={{ trigger: id }} content="Segun Adebayo is online">
<Avatar
ids={{ root: id }}
name="Segun Adebayo"
src="https://bit.ly/sage-adebayo"
/>
</Tooltip>
)
}
```
### [With Checkbox]()
Here's an example of how to use the `Tooltip` component with a `Checkbox` component.
PreviewCode
Welcome
This is the tooltip content
```
import { Checkbox } from "@/components/ui/checkbox"
import { Tooltip } from "@/components/ui/tooltip"
import { useId } from "react"
const Demo = () => {
const id = useId()
return (
<Tooltip ids={{ trigger: id }} content="This is the tooltip content">
<Checkbox ids={{ root: id }}>Welcome</Checkbox>
</Tooltip>
)
}
```
### [With MenuItem]()
Here's an example of how to use the `Tooltip` with a `MenuItem` component.
PreviewCode
Open
Open tooltip
This is the tooltip content
New File...
New Window
Export
```
import type { MenuItemProps } from "@chakra-ui/react"
import { Button } from "@/components/ui/button"
import {
MenuContent,
MenuItem,
MenuRoot,
MenuTrigger,
} from "@/components/ui/menu"
import { Tooltip } from "@/components/ui/tooltip"
const Demo = () => {
return (
<MenuRoot>
<MenuTrigger asChild>
<Button variant="outline" size="sm">
Open
</Button>
</MenuTrigger>
<MenuContent>
<TooltipMenuItem value="new-txt" tooltip="This is the tooltip content">
Open tooltip
</TooltipMenuItem>
<MenuItem value="new-file">New File...</MenuItem>
<MenuItem value="new-win">New Window</MenuItem>
<MenuItem value="export">Export</MenuItem>
</MenuContent>
</MenuRoot>
)
}
const TooltipMenuItem = (props: MenuItemProps & { tooltip: string }) => {
const { value, tooltip, ...rest } = props
return (
<Tooltip
ids={{ trigger: value }}
openDelay={200}
closeDelay={0}
positioning={{ placement: "right" }}
content={tooltip}
>
<MenuItem value={value} {...rest} />
</Tooltip>
)
}
```
### [With Switch]()
Here's an example of how to wrap `Tooltip` around a `Switch` component.
PreviewCode
This is the tooltip content
```
import { Switch } from "@/components/ui/switch"
import { Tooltip } from "@/components/ui/tooltip"
import { useId } from "react"
const Demo = () => {
const id = useId()
return (
<Tooltip ids={{ trigger: id }} content="This is the tooltip content">
<Switch ids={{ root: id }} />
</Tooltip>
)
}
```
### [With Tabs]()
Here's an example of how to wrap `Tooltip` around a `Tabs` component.
PreviewCode
Members
This is the tooltip content
ProjectsSettings
Manage your team members
Manage your projects
Manage your tasks for freelancers
```
import { Tabs } from "@chakra-ui/react"
import { Tooltip } from "@/components/ui/tooltip"
import { LuCheckSquare, LuFolder, LuUser } from "react-icons/lu"
const Demo = () => {
return (
<Tabs.Root defaultValue="members">
<Tabs.List>
<Tooltip
positioning={{ placement: "top" }}
ids={{ trigger: "members" }}
content="This is the tooltip content"
>
{/* TODO: Remove this once Zag.js is fixed */}
<span>
<Tabs.Trigger value="members">
<LuUser />
Members
</Tabs.Trigger>
</span>
</Tooltip>
<Tabs.Trigger value="projects">
<LuFolder />
Projects
</Tabs.Trigger>
<Tabs.Trigger value="tasks">
<LuCheckSquare />
Settings
</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="members">Manage your team members</Tabs.Content>
<Tabs.Content value="projects">Manage your projects</Tabs.Content>
<Tabs.Content value="tasks">
Manage your tasks for freelancers
</Tabs.Content>
</Tabs.Root>
)
}
```
### [Without Snippet]()
If you don't want to use the snippet, you can use the `Tooltip` component from the `@chakra-ui/react` package.
PreviewCode
Hover me
This is the tooltip content
```
import { Button, Portal, Tooltip } from "@chakra-ui/react"
const Demo = () => {
return (
<Tooltip.Root>
<Tooltip.Trigger asChild>
<Button variant="outline" size="sm">
Hover me
</Button>
</Tooltip.Trigger>
<Portal>
<Tooltip.Positioner>
<Tooltip.Content>This is the tooltip content</Tooltip.Content>
</Tooltip.Positioner>
</Portal>
</Tooltip.Root>
)
}
```
## [Props]()
### [Root]()
[Previous
\
Toggle Tip](https://www.chakra-ui.com/docs/components/toggle-tip)
[Next
\
ClientOnly](https://www.chakra-ui.com/docs/components/client-only) |
https://www.chakra-ui.com/docs/components/client-only | 1. Utilities
2. ClientOnly
# Client Only
Used to render content only on the client side.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/client-only)
## [Usage]()
```
import { ClientOnly, Skeleton } from "@chakra-ui/react"
```
```
<ClientOnly fallback={<Skeleton />}>
<ColorModeButton />
</ClientOnly>
```
## [Props]()
These props can be passed to the `ClientOnly` component.
PropDefaultType`fallback`
`React.ReactNode`
[Previous
\
Tooltip](https://www.chakra-ui.com/docs/components/tooltip)
[Next
\
EnvironmentProvider](https://www.chakra-ui.com/docs/components/environment-provider) |
https://www.chakra-ui.com/docs/components/locale-provider | 1. Utilities
2. LocaleProvider
# Locale Provider
Used for globally setting the locale
## [Usage]()
The `LocaleProvider` component sets the locale for your app, formatting dates, numbers, and other locale-specific data.
Most Chakra UI components that read the locale set by the `LocaleProvider`.
```
import { LocaleProvider, useLocaleContext } from "@chakra-ui/react"
```
```
<LocaleProvider locale="...">{/* Your App */}</LocaleProvider>
```
## [Examples]()
### [Setting Locale]()
Set the `locale` prop to the locale you want to use.
```
<LocaleProvider locale="ar-BH">
<Component />
</LocaleProvider>
```
### [Reading Locale]()
```
export const Usage = () => {
const { locale, dir } = useLocaleContext()
return <pre>{JSON.stringify({ locale, dir }, null, 2)}</pre>
}
```
## [Props]()
PropDefaultType`locale`\*`''en-US''`
`string`
The locale to use for the application.
[Previous
\
FormatByte](https://www.chakra-ui.com/docs/components/format-byte)
[Next
\
Portal](https://www.chakra-ui.com/docs/components/portal) |
https://www.chakra-ui.com/docs/components/environment-provider | 1. Utilities
2. EnvironmentProvider
# Environment Provider
Used to render components in iframes, Shadow DOM, or Electron.
[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-environment-provider--basic)[Recipe](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/theme/recipes/environment-provider.ts)[Ark](https://ark-ui.com/react/docs/utilities/environment-provider)
We use [Zag.js](https://zagjs.com/overview/composition) internally, which relies on DOM query methods like `document.querySelectorAll` and `document.getElementById`. In custom environments like iframes, Shadow DOM, or Electron, these methods might not work as expected.
To handle this, Ark UI includes the `EnvironmentProvider`, allowing you to set the appropriate root node or document, ensuring correct DOM queries.
## [Usage]()
```
import { EnvironmentProvider } from "@chakra-ui/react"
```
```
<EnvironmentProvider>{/* Your App */}</EnvironmentProvider>
```
## [Examples]()
### [iframe]()
Here's an example that uses `react-frame-component` to set the `EnvironmentProvider`'s value with the iframe environment.
```
import { EnvironmentProvider } from "@chakra-ui/react"
import Frame, { FrameContextConsumer } from "react-frame-component"
export const Demo = () => (
<Frame>
<FrameContextConsumer>
{({ document }) => (
<EnvironmentProvider value={() => document}>
{/* Your App */}
</EnvironmentProvider>
)}
</FrameContextConsumer>
</Frame>
)
```
### [Shadow DOM]()
Here's an example that uses `react-shadow` to set the `EnvironmentProvider`'s value with Shadow DOM environment.
```
import { EnvironmentProvider } from "@chakra-ui/react"
import { useRef } from "react"
import root from "react-shadow"
export const Demo = () => {
const portalRef = useRef()
return (
<root.div ref={portalRef}>
<EnvironmentProvider
value={() => portalRef?.current?.shadowRoot ?? document}
>
{/* Your App */}
</EnvironmentProvider>
</root.div>
)
}
```
### [Accessing Context]()
Use the `useEnvironmentContext` hook to access the `RootNode`, `Document`, and `Window` context.
```
import { useEnvironmentContext } from "@chakra-ui/react"
export const Demo = () => {
const { getRootNode } = useEnvironmentContext()
return <pre>{JSON.stringify(getRootNode(), null, 2)}</pre>
}
```
## [Props]()
PropDefaultType`value`
`RootNode | (() => RootNode)`
[Previous
\
ClientOnly](https://www.chakra-ui.com/docs/components/client-only)
[Next
\
For](https://www.chakra-ui.com/docs/components/for) |
https://www.chakra-ui.com/docs/components/for | 1. Utilities
2. For
# For
Used to loop over an array and render a component for each item.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/for)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-for--basic)
PreviewCode
One
Two
Three
```
import { For } from "@chakra-ui/react"
const Demo = () => {
return (
<For each={["One", "Two", "Three"]}>
{(item, index) => <div key={index}>{item}</div>}
</For>
)
}
```
## [Usage]()
The `For` component is used to render a list of items in a strongly typed manner. It is similar to the `.map()`.
```
import { For } from "@chakra-ui/react"
```
```
<For each={[]} fallback={...} />
```
## [Examples]()
### [Object]()
Here's an example of using the `For` component to loop over an object.
PreviewCode
Naruto
Powers: Shadow Clone, Rasengan
Sasuke
Powers: Chidori, Sharingan
Sakura
Powers: Healing, Super Strength
```
import { Box, For, Stack, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack>
<For
each={[
{ name: "Naruto", powers: ["Shadow Clone", "Rasengan"] },
{ name: "Sasuke", powers: ["Chidori", "Sharingan"] },
{ name: "Sakura", powers: ["Healing", "Super Strength"] },
]}
>
{(item, index) => (
<Box borderWidth="1px" key={index} p="4">
<Text fontWeight="bold">{item.name}</Text>
<Text color="fg.muted">Powers: {item.powers.join(", ")}</Text>
</Box>
)}
</For>
</Stack>
)
}
```
### [Fallback]()
Use the `fallback` prop to render a fallback component when the array is empty or undefined.
PreviewCode
No items to show
```
import { For, Stack, VStack } from "@chakra-ui/react"
import { DecorativeBox } from "compositions/lib/decorative-box"
import { LuBox } from "react-icons/lu"
const Demo = () => {
return (
<Stack gap="4">
<For
each={[]}
fallback={
<VStack textAlign="center" fontWeight="medium">
<LuBox />
No items to show
</VStack>
}
>
{(item, index) => (
<DecorativeBox h="10" key={index}>
{item}
</DecorativeBox>
)}
</For>
</Stack>
)
}
```
## [Props]()
PropDefaultType`each`
`T[] | readonly T[] | undefined`
The array to iterate over
`fallback`
`React.ReactNode`
The fallback content to render when the array is empty
[Previous
\
EnvironmentProvider](https://www.chakra-ui.com/docs/components/environment-provider)
[Next
\
FormatNumber](https://www.chakra-ui.com/docs/components/format-number) |
https://www.chakra-ui.com/docs/components/portal | 1. Utilities
2. Portal
# Portal
Used to render an element outside the DOM hierarchy.
## [Usage]()
The `Portal` uses the `ReactDOM.createPortal` API to render an element at the end of `document.body` or specific container.
```
import { Portal } from "@chakra-ui/react"
```
```
<Portal>
<div>Portal content</div>
</Portal>
```
## [Examples]()
### [Custom Container]()
Use the `container` prop to render the portal in a custom container.
```
import { Portal } from "@chakra-ui/react"
const Demo = () => {
const containerRef = React.useRef()
return (
<>
<Portal container={containerRef}>
<div>Portal content</div>
</Portal>
<div ref={containerRef} />
</>
)
}
```
### [Disabled]()
Use the `disabled` prop to disable the portal. This will render the children in the same DOM hierarchy.
```
import { Portal } from "@chakra-ui/react"
const Demo = () => {
return (
<Portal disabled>
<div>Will render the content in place</div>
</Portal>
)
}
```
## [Server Rendering]()
During SSR, the `Portal` component directly renders its content. If you run into any mismatch warnings, we recommended conditionally rendering the `Portal` component only on the client-side.
## [Props]()
PropDefaultType`container`
`RefObject<HTMLElement>`
`disabled`
`boolean`
[Previous
\
LocaleProvider](https://www.chakra-ui.com/docs/components/locale-provider)
[Next
\
Show](https://www.chakra-ui.com/docs/components/show) |
https://www.chakra-ui.com/docs/components/format-byte | 1. Utilities
2. FormatByte
# Format Byte
Used to format bytes to a human-readable format
[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-format-byte--basic)[Ark](https://ark-ui.com/react/docs/utilities/format-byte)
PreviewCode
File size: 1.45 kB
```
import { FormatByte, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Text textStyle="lg">
File size: <FormatByte value={1450.45} />
</Text>
)
}
```
## [Usage]()
```
import { FormatByte } from "@chakra-ui/react"
```
```
<FormatByte value={1000} />
```
## [Examples]()
### [Sizes]()
The format functions works for any size of bytes.
PreviewCode
50 byte
5 kB
5 MB
5 GB
```
import { FormatByte, Stack, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack>
<Text textStyle="lg">
<FormatByte value={50} />
</Text>
<Text textStyle="lg">
<FormatByte value={5000} />
</Text>
<Text textStyle="lg">
<FormatByte value={5000000} />
</Text>
<Text textStyle="lg">
<FormatByte value={5000000000} />
</Text>
</Stack>
)
}
```
### [Format Bits]()
Use the `unit` prop to change the byte format to bits.
PreviewCode
File size: 1.45 kb
```
import { FormatByte, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Text textStyle="lg">
File size: <FormatByte value={1450.45} unit="bit" />
</Text>
)
}
```
### [Locale]()
Wrap the `FormatByte` component within the `LocaleProvider` to change the locale.
PreviewCode
de-DE
1,45 kB
zh-CN
1.45 kB
```
import { FormatByte, HStack, LocaleProvider, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Text textStyle="lg">
<HStack>
<Text fontWeight="medium">de-DE</Text>
<LocaleProvider locale="de-DE">
<FormatByte value={1450.45} />
</LocaleProvider>
</HStack>
<HStack>
<Text fontWeight="medium">zh-CN</Text>
<LocaleProvider locale="zh-CN">
<FormatByte value={1450.45} />
</LocaleProvider>
</HStack>
</Text>
)
}
```
### [Unit Display]()
Use the `unitDisplay` prop to change the byte format to compact notation.
PreviewCode
50.3kB
50.3 kB
50.3 kilobytes
```
import { FormatByte, Stack, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack>
<Text textStyle="lg">
<FormatByte value={50345.53} unitDisplay="narrow" />
</Text>
<Text textStyle="lg">
<FormatByte value={50345.53} unitDisplay="short" />
</Text>
<Text textStyle="lg">
<FormatByte value={50345.53} unitDisplay="long" />
</Text>
</Stack>
)
}
```
## [Props]()
PropDefaultType`value`*
`number`
The byte size to format
`unit`
`'bit' | 'byte'`
The unit granularity to display
`unitDisplay`
`'long' | 'short' | 'narrow'`
The unit display
[Previous
\
FormatNumber](https://www.chakra-ui.com/docs/components/format-number)
[Next
\
LocaleProvider](https://www.chakra-ui.com/docs/components/locale-provider) |
https://www.chakra-ui.com/docs/components/show | 1. Utilities
2. Show
# Show
Used to conditional render part of the view based on a condition.
PreviewCode
Value: 0
```
"use client"
import { Button, Show, Stack } from "@chakra-ui/react"
import { useState } from "react"
const Demo = () => {
const [count, setCount] = useState(0)
return (
<Stack align="flex-start">
<Button variant="outline" onClick={() => setCount(count + 1)}>
Value: {count}
</Button>
<Show when={count > 3}>
<div>My Content</div>
</Show>
</Stack>
)
}
```
## [Usage]()
The `Show` component renders its children when the `when` value is truthy, otherwise it renders the `fallback` prop.
```
import { Show } from "@chakra-ui/react"
```
```
<Show when={...} fallback={...}>
<div>Content</div>
</Show>
```
## [Examples]()
### [Fallback]()
Use the `fallback` prop to render a fallback component when the array is empty or undefined.
PreviewCode
Value: 0
Not there yet. Keep clicking...
```
"use client"
import { Button, Show, Stack, Text } from "@chakra-ui/react"
import { useState } from "react"
const Demo = () => {
const [count, setCount] = useState(0)
return (
<Stack align="flex-start">
<Button variant="outline" onClick={() => setCount(count + 1)}>
Value: {count}
</Button>
<Show
when={count > 3}
fallback={<Text>Not there yet. Keep clicking...</Text>}
>
<div>Congrats! I am here</div>
</Show>
</Stack>
)
}
```
### [Render Prop]()
Use the `children` render prop to narrow the type of the `when` value and remove `undefined` | `null`
PreviewCode
Value: 10
```
import { Show } from "@chakra-ui/react"
const Demo = () => {
const value: number | undefined = 10
return <Show when={value}>{(value) => <div>Value: {value}</div>}</Show>
}
```
## [Props]()
PropDefaultType`when`
`T | null | undefined`
If \`true\`, it'll render the \`children\` prop
`fallback`
`React.ReactNode`
The fallback content to render if \`when\` is \`false\`
[Previous
\
Portal](https://www.chakra-ui.com/docs/components/portal)
[Next
\
Visually Hidden](https://www.chakra-ui.com/docs/components/visually-hidden) |
https://www.chakra-ui.com/docs/components/format-number | 1. Utilities
2. FormatNumber
# Format Number
Used to format numbers to a specific locale and options
[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-format-number--basic)[Ark](https://ark-ui.com/react/docs/utilities/format-number)
PreviewCode
1,450.45
```
import { FormatNumber, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Text textStyle="lg">
<FormatNumber value={1450.45} />
</Text>
)
}
```
## [Usage]()
The number formatting logic is handled by the native `Intl.NumberFormat` API and smartly cached to avoid performance issues when using the same locale and options.
```
import { FormatNumber } from "@chakra-ui/react"
```
```
<FormatNumber value={1000} />
```
## [Examples]()
### [Percentage]()
Use the `style=percentage` prop to change the number format to percentage.
PreviewCode
14.50%
```
import { FormatNumber, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Text textStyle="lg">
<FormatNumber
value={0.145}
style="percent"
maximumFractionDigits={2}
minimumFractionDigits={2}
/>
</Text>
)
}
```
### [Currency]()
Use the `style=currency` prop to change the number format to currency.
PreviewCode
$1,234.45
```
import { FormatNumber, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Text textStyle="lg">
<FormatNumber value={1234.45} style="currency" currency="USD" />
</Text>
)
}
```
### [Locale]()
Wrap the `FormatNumber` component within the `LocaleProvider` to change the locale.
PreviewCode
de-DE
1.450,45
zh-CN
1,450.45
```
import { FormatNumber, HStack, LocaleProvider, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Text textStyle="lg">
<HStack>
<Text fontWeight="medium">de-DE</Text>
<LocaleProvider locale="de-DE">
<FormatNumber value={1450.45} />
</LocaleProvider>
</HStack>
<HStack>
<Text fontWeight="medium">zh-CN</Text>
<LocaleProvider locale="zh-CN">
<FormatNumber value={1450.45} />
</LocaleProvider>
</HStack>
</Text>
)
}
```
### [Unit]()
Use the `style=unit` prop to change the number format to unit.
PreviewCode
384.4 km
```
import { FormatNumber, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Text textStyle="lg">
<FormatNumber value={384.4} style="unit" unit="kilometer" />
</Text>
)
}
```
### [Compact Notation]()
Use the `notation=compact` prop to change the number format to compact notation.
PreviewCode
1.5M
```
import { FormatNumber, Text } from "@chakra-ui/react"
const Demo = () => {
return (
<Text textStyle="lg">
<FormatNumber value={1500000} notation="compact" compactDisplay="short" />
</Text>
)
}
```
## [Props]()
The `FormatNumber` component supports all `Intl.NumberFormat` options in addition to the following props:
PropDefaultType`value`*
`number`
The number to format
[Previous
\
For](https://www.chakra-ui.com/docs/components/for)
[Next
\
FormatByte](https://www.chakra-ui.com/docs/components/format-byte) |
https://www.chakra-ui.com/docs/components/pagination?page=3 | 1. Components
2. Pagination
# Pagination
Used to navigate through a series of pages.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/pagination)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-pagination--basic)[Ark](https://ark-ui.com/react/docs/components/pagination)
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `pagination` snippet
```
npx @chakra-ui/cli snippet add pagination
```
The snippet includes a closed component composition for the `Pagination` component.
## [Usage]()
```
import {
PaginationItems,
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
```
```
<PaginationRoot>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationPageText />
<PaginationNextTrigger />
</PaginationRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the pagination.
info
The pagination sizes are mapped to the `Button` component sizes.
PreviewCode
1235
1235
1235
1235
```
import { For, HStack, Stack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<Stack gap="8">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<PaginationRoot
key={size}
count={10}
pageSize={2}
defaultPage={1}
size={size}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)}
</For>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to control the variant of the pagination items and ellipsis.
The variant matches the `Button` component variant.
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1} variant="solid">
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Controlled]()
Use the `page` and `onPageChange` props to control the current page.
PreviewCode
1234510
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const Demo = () => {
const [page, setPage] = useState(1)
return (
<PaginationRoot
count={20}
pageSize={2}
page={page}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Sibling Count]()
Use `siblingCount` to control the number of sibling pages to show before and after the current page.
PreviewCode
18910111220
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={200} pageSize={10} defaultPage={10} siblingCount={2}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Compact]()
Use the `PaginationPageText` to create a compact pagination. This can be useful for mobile views.
PreviewCode
1 of 10
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack gap="4">
<PaginationPrevTrigger />
<PaginationPageText />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [As Link]()
Use the `getHref` prop to create a pagination that navigates via links. This will use the `LinkButton` component to create the links.
info
Edit the `LinkButton` component to point to the correct framework link component if needed.
PreviewCode
[]()[1](https://www.chakra-ui.com/docs/components/pagination?page=1)[2](https://www.chakra-ui.com/docs/components/pagination?page=2)[3](https://www.chakra-ui.com/docs/components/pagination?page=3)[4](https://www.chakra-ui.com/docs/components/pagination?page=4)[5](https://www.chakra-ui.com/docs/components/pagination?page=5)[10](https://www.chakra-ui.com/docs/components/pagination?page=10)[](https://www.chakra-ui.com/docs/components/pagination?page=2)
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot
count={20}
pageSize={2}
defaultPage={1}
getHref={(page) => `?page=${page}`}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Attached]()
Here's an example of composing the pagination with the `Group` component to attach the pagination items and triggers.
PreviewCode
1235
```
import { Group } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={10} pageSize={2} defaultPage={1} variant="solid">
<Group attached>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</Group>
</PaginationRoot>
)
}
```
### [Count Text]()
Pass `format=long` to the `PaginationPageText` component to show the count text
PreviewCode
1 - 5 of 50
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={50} pageSize={5} defaultPage={1} maxW="240px">
<HStack gap="4">
<PaginationPageText format="long" flex="1" />
<PaginationPrevTrigger />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Data Driven]()
Here's an example of controlling the pagination state and using the state to chunk the data.
PreviewCode
Lorem ipsum dolor sit amet 1
Lorem ipsum dolor sit amet 2
Lorem ipsum dolor sit amet 3
Lorem ipsum dolor sit amet 4
Lorem ipsum dolor sit amet 5
1234510
```
"use client"
import { HStack, Stack, Text } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const pageSize = 5
const count = 50
const items = new Array(count)
.fill(0)
.map((_, index) => `Lorem ipsum dolor sit amet ${index + 1}`)
const Demo = () => {
const [page, setPage] = useState(1)
const startRange = (page - 1) * pageSize
const endRange = startRange + pageSize
const visibleItems = items.slice(startRange, endRange)
return (
<Stack gap="4">
<Stack>
{visibleItems.map((item) => (
<Text key={item}>{item}</Text>
))}
</Stack>
<PaginationRoot
page={page}
count={count}
pageSize={pageSize}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
</Stack>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`count`*
`number`
Total number of data items
`page``'1'`
`number`
The active page
`pageSize``'10'`
`number`
Number of data items per page
`siblingCount``'1'`
`number`
Number of pages to show beside active page
`type``'\'button\''`
`'button' | 'link'`
The type of the trigger element
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultPage`
`number`
The initial page of the pagination when it is first rendered. Use when you do not need to control the state of the pagination.
`ids`
`Partial<{ root: string ellipsis(index: number): string prevTrigger: string nextTrigger: string item(page: number): string }>`
The ids of the elements in the accordion. Useful for composition.
`onPageChange`
`(details: PageChangeDetails) => void`
Called when the page number is changed
`onPageSizeChange`
`(details: PageSizeChangeDetails) => void`
Called when the page size is changed
`translations`
`IntlTranslations`
Specifies the localized strings that identifies the accessibility elements and their states
[Previous
\
Number Input](https://www.chakra-ui.com/docs/components/number-input)
[Next
\
Password Input](https://www.chakra-ui.com/docs/components/password-input) |
https://www.chakra-ui.com/docs/components/pagination?page=1 | 1. Components
2. Pagination
# Pagination
Used to navigate through a series of pages.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/pagination)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-pagination--basic)[Ark](https://ark-ui.com/react/docs/components/pagination)
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `pagination` snippet
```
npx @chakra-ui/cli snippet add pagination
```
The snippet includes a closed component composition for the `Pagination` component.
## [Usage]()
```
import {
PaginationItems,
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
```
```
<PaginationRoot>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationPageText />
<PaginationNextTrigger />
</PaginationRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the pagination.
info
The pagination sizes are mapped to the `Button` component sizes.
PreviewCode
1235
1235
1235
1235
```
import { For, HStack, Stack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<Stack gap="8">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<PaginationRoot
key={size}
count={10}
pageSize={2}
defaultPage={1}
size={size}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)}
</For>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to control the variant of the pagination items and ellipsis.
The variant matches the `Button` component variant.
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1} variant="solid">
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Controlled]()
Use the `page` and `onPageChange` props to control the current page.
PreviewCode
1234510
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const Demo = () => {
const [page, setPage] = useState(1)
return (
<PaginationRoot
count={20}
pageSize={2}
page={page}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Sibling Count]()
Use `siblingCount` to control the number of sibling pages to show before and after the current page.
PreviewCode
18910111220
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={200} pageSize={10} defaultPage={10} siblingCount={2}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Compact]()
Use the `PaginationPageText` to create a compact pagination. This can be useful for mobile views.
PreviewCode
1 of 10
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack gap="4">
<PaginationPrevTrigger />
<PaginationPageText />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [As Link]()
Use the `getHref` prop to create a pagination that navigates via links. This will use the `LinkButton` component to create the links.
info
Edit the `LinkButton` component to point to the correct framework link component if needed.
PreviewCode
[]()[1](https://www.chakra-ui.com/docs/components/pagination?page=1)[2](https://www.chakra-ui.com/docs/components/pagination?page=2)[3](https://www.chakra-ui.com/docs/components/pagination?page=3)[4](https://www.chakra-ui.com/docs/components/pagination?page=4)[5](https://www.chakra-ui.com/docs/components/pagination?page=5)[10](https://www.chakra-ui.com/docs/components/pagination?page=10)[](https://www.chakra-ui.com/docs/components/pagination?page=2)
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot
count={20}
pageSize={2}
defaultPage={1}
getHref={(page) => `?page=${page}`}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Attached]()
Here's an example of composing the pagination with the `Group` component to attach the pagination items and triggers.
PreviewCode
1235
```
import { Group } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={10} pageSize={2} defaultPage={1} variant="solid">
<Group attached>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</Group>
</PaginationRoot>
)
}
```
### [Count Text]()
Pass `format=long` to the `PaginationPageText` component to show the count text
PreviewCode
1 - 5 of 50
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={50} pageSize={5} defaultPage={1} maxW="240px">
<HStack gap="4">
<PaginationPageText format="long" flex="1" />
<PaginationPrevTrigger />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Data Driven]()
Here's an example of controlling the pagination state and using the state to chunk the data.
PreviewCode
Lorem ipsum dolor sit amet 1
Lorem ipsum dolor sit amet 2
Lorem ipsum dolor sit amet 3
Lorem ipsum dolor sit amet 4
Lorem ipsum dolor sit amet 5
1234510
```
"use client"
import { HStack, Stack, Text } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const pageSize = 5
const count = 50
const items = new Array(count)
.fill(0)
.map((_, index) => `Lorem ipsum dolor sit amet ${index + 1}`)
const Demo = () => {
const [page, setPage] = useState(1)
const startRange = (page - 1) * pageSize
const endRange = startRange + pageSize
const visibleItems = items.slice(startRange, endRange)
return (
<Stack gap="4">
<Stack>
{visibleItems.map((item) => (
<Text key={item}>{item}</Text>
))}
</Stack>
<PaginationRoot
page={page}
count={count}
pageSize={pageSize}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
</Stack>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`count`*
`number`
Total number of data items
`page``'1'`
`number`
The active page
`pageSize``'10'`
`number`
Number of data items per page
`siblingCount``'1'`
`number`
Number of pages to show beside active page
`type``'\'button\''`
`'button' | 'link'`
The type of the trigger element
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultPage`
`number`
The initial page of the pagination when it is first rendered. Use when you do not need to control the state of the pagination.
`ids`
`Partial<{ root: string ellipsis(index: number): string prevTrigger: string nextTrigger: string item(page: number): string }>`
The ids of the elements in the accordion. Useful for composition.
`onPageChange`
`(details: PageChangeDetails) => void`
Called when the page number is changed
`onPageSizeChange`
`(details: PageSizeChangeDetails) => void`
Called when the page size is changed
`translations`
`IntlTranslations`
Specifies the localized strings that identifies the accessibility elements and their states
[Previous
\
Number Input](https://www.chakra-ui.com/docs/components/number-input)
[Next
\
Password Input](https://www.chakra-ui.com/docs/components/password-input) |
https://www.chakra-ui.com/docs/components/pagination?page=2 | 1. Components
2. Pagination
# Pagination
Used to navigate through a series of pages.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/pagination)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-pagination--basic)[Ark](https://ark-ui.com/react/docs/components/pagination)
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `pagination` snippet
```
npx @chakra-ui/cli snippet add pagination
```
The snippet includes a closed component composition for the `Pagination` component.
## [Usage]()
```
import {
PaginationItems,
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
```
```
<PaginationRoot>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationPageText />
<PaginationNextTrigger />
</PaginationRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the pagination.
info
The pagination sizes are mapped to the `Button` component sizes.
PreviewCode
1235
1235
1235
1235
```
import { For, HStack, Stack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<Stack gap="8">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<PaginationRoot
key={size}
count={10}
pageSize={2}
defaultPage={1}
size={size}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)}
</For>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to control the variant of the pagination items and ellipsis.
The variant matches the `Button` component variant.
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1} variant="solid">
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Controlled]()
Use the `page` and `onPageChange` props to control the current page.
PreviewCode
1234510
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const Demo = () => {
const [page, setPage] = useState(1)
return (
<PaginationRoot
count={20}
pageSize={2}
page={page}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Sibling Count]()
Use `siblingCount` to control the number of sibling pages to show before and after the current page.
PreviewCode
18910111220
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={200} pageSize={10} defaultPage={10} siblingCount={2}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Compact]()
Use the `PaginationPageText` to create a compact pagination. This can be useful for mobile views.
PreviewCode
1 of 10
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack gap="4">
<PaginationPrevTrigger />
<PaginationPageText />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [As Link]()
Use the `getHref` prop to create a pagination that navigates via links. This will use the `LinkButton` component to create the links.
info
Edit the `LinkButton` component to point to the correct framework link component if needed.
PreviewCode
[]()[1](https://www.chakra-ui.com/docs/components/pagination?page=1)[2](https://www.chakra-ui.com/docs/components/pagination?page=2)[3](https://www.chakra-ui.com/docs/components/pagination?page=3)[4](https://www.chakra-ui.com/docs/components/pagination?page=4)[5](https://www.chakra-ui.com/docs/components/pagination?page=5)[10](https://www.chakra-ui.com/docs/components/pagination?page=10)[](https://www.chakra-ui.com/docs/components/pagination?page=2)
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot
count={20}
pageSize={2}
defaultPage={1}
getHref={(page) => `?page=${page}`}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Attached]()
Here's an example of composing the pagination with the `Group` component to attach the pagination items and triggers.
PreviewCode
1235
```
import { Group } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={10} pageSize={2} defaultPage={1} variant="solid">
<Group attached>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</Group>
</PaginationRoot>
)
}
```
### [Count Text]()
Pass `format=long` to the `PaginationPageText` component to show the count text
PreviewCode
1 - 5 of 50
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={50} pageSize={5} defaultPage={1} maxW="240px">
<HStack gap="4">
<PaginationPageText format="long" flex="1" />
<PaginationPrevTrigger />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Data Driven]()
Here's an example of controlling the pagination state and using the state to chunk the data.
PreviewCode
Lorem ipsum dolor sit amet 1
Lorem ipsum dolor sit amet 2
Lorem ipsum dolor sit amet 3
Lorem ipsum dolor sit amet 4
Lorem ipsum dolor sit amet 5
1234510
```
"use client"
import { HStack, Stack, Text } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const pageSize = 5
const count = 50
const items = new Array(count)
.fill(0)
.map((_, index) => `Lorem ipsum dolor sit amet ${index + 1}`)
const Demo = () => {
const [page, setPage] = useState(1)
const startRange = (page - 1) * pageSize
const endRange = startRange + pageSize
const visibleItems = items.slice(startRange, endRange)
return (
<Stack gap="4">
<Stack>
{visibleItems.map((item) => (
<Text key={item}>{item}</Text>
))}
</Stack>
<PaginationRoot
page={page}
count={count}
pageSize={pageSize}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
</Stack>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`count`*
`number`
Total number of data items
`page``'1'`
`number`
The active page
`pageSize``'10'`
`number`
Number of data items per page
`siblingCount``'1'`
`number`
Number of pages to show beside active page
`type``'\'button\''`
`'button' | 'link'`
The type of the trigger element
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultPage`
`number`
The initial page of the pagination when it is first rendered. Use when you do not need to control the state of the pagination.
`ids`
`Partial<{ root: string ellipsis(index: number): string prevTrigger: string nextTrigger: string item(page: number): string }>`
The ids of the elements in the accordion. Useful for composition.
`onPageChange`
`(details: PageChangeDetails) => void`
Called when the page number is changed
`onPageSizeChange`
`(details: PageSizeChangeDetails) => void`
Called when the page size is changed
`translations`
`IntlTranslations`
Specifies the localized strings that identifies the accessibility elements and their states
[Previous
\
Number Input](https://www.chakra-ui.com/docs/components/number-input)
[Next
\
Password Input](https://www.chakra-ui.com/docs/components/password-input) |
https://www.chakra-ui.com/docs/components/pagination?page=4 | 1. Components
2. Pagination
# Pagination
Used to navigate through a series of pages.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/pagination)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-pagination--basic)[Ark](https://ark-ui.com/react/docs/components/pagination)
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `pagination` snippet
```
npx @chakra-ui/cli snippet add pagination
```
The snippet includes a closed component composition for the `Pagination` component.
## [Usage]()
```
import {
PaginationItems,
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
```
```
<PaginationRoot>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationPageText />
<PaginationNextTrigger />
</PaginationRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the pagination.
info
The pagination sizes are mapped to the `Button` component sizes.
PreviewCode
1235
1235
1235
1235
```
import { For, HStack, Stack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<Stack gap="8">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<PaginationRoot
key={size}
count={10}
pageSize={2}
defaultPage={1}
size={size}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)}
</For>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to control the variant of the pagination items and ellipsis.
The variant matches the `Button` component variant.
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1} variant="solid">
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Controlled]()
Use the `page` and `onPageChange` props to control the current page.
PreviewCode
1234510
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const Demo = () => {
const [page, setPage] = useState(1)
return (
<PaginationRoot
count={20}
pageSize={2}
page={page}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Sibling Count]()
Use `siblingCount` to control the number of sibling pages to show before and after the current page.
PreviewCode
18910111220
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={200} pageSize={10} defaultPage={10} siblingCount={2}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Compact]()
Use the `PaginationPageText` to create a compact pagination. This can be useful for mobile views.
PreviewCode
1 of 10
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack gap="4">
<PaginationPrevTrigger />
<PaginationPageText />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [As Link]()
Use the `getHref` prop to create a pagination that navigates via links. This will use the `LinkButton` component to create the links.
info
Edit the `LinkButton` component to point to the correct framework link component if needed.
PreviewCode
[]()[1](https://www.chakra-ui.com/docs/components/pagination?page=1)[2](https://www.chakra-ui.com/docs/components/pagination?page=2)[3](https://www.chakra-ui.com/docs/components/pagination?page=3)[4](https://www.chakra-ui.com/docs/components/pagination?page=4)[5](https://www.chakra-ui.com/docs/components/pagination?page=5)[10](https://www.chakra-ui.com/docs/components/pagination?page=10)[](https://www.chakra-ui.com/docs/components/pagination?page=2)
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot
count={20}
pageSize={2}
defaultPage={1}
getHref={(page) => `?page=${page}`}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Attached]()
Here's an example of composing the pagination with the `Group` component to attach the pagination items and triggers.
PreviewCode
1235
```
import { Group } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={10} pageSize={2} defaultPage={1} variant="solid">
<Group attached>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</Group>
</PaginationRoot>
)
}
```
### [Count Text]()
Pass `format=long` to the `PaginationPageText` component to show the count text
PreviewCode
1 - 5 of 50
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={50} pageSize={5} defaultPage={1} maxW="240px">
<HStack gap="4">
<PaginationPageText format="long" flex="1" />
<PaginationPrevTrigger />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Data Driven]()
Here's an example of controlling the pagination state and using the state to chunk the data.
PreviewCode
Lorem ipsum dolor sit amet 1
Lorem ipsum dolor sit amet 2
Lorem ipsum dolor sit amet 3
Lorem ipsum dolor sit amet 4
Lorem ipsum dolor sit amet 5
1234510
```
"use client"
import { HStack, Stack, Text } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const pageSize = 5
const count = 50
const items = new Array(count)
.fill(0)
.map((_, index) => `Lorem ipsum dolor sit amet ${index + 1}`)
const Demo = () => {
const [page, setPage] = useState(1)
const startRange = (page - 1) * pageSize
const endRange = startRange + pageSize
const visibleItems = items.slice(startRange, endRange)
return (
<Stack gap="4">
<Stack>
{visibleItems.map((item) => (
<Text key={item}>{item}</Text>
))}
</Stack>
<PaginationRoot
page={page}
count={count}
pageSize={pageSize}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
</Stack>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`count`*
`number`
Total number of data items
`page``'1'`
`number`
The active page
`pageSize``'10'`
`number`
Number of data items per page
`siblingCount``'1'`
`number`
Number of pages to show beside active page
`type``'\'button\''`
`'button' | 'link'`
The type of the trigger element
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultPage`
`number`
The initial page of the pagination when it is first rendered. Use when you do not need to control the state of the pagination.
`ids`
`Partial<{ root: string ellipsis(index: number): string prevTrigger: string nextTrigger: string item(page: number): string }>`
The ids of the elements in the accordion. Useful for composition.
`onPageChange`
`(details: PageChangeDetails) => void`
Called when the page number is changed
`onPageSizeChange`
`(details: PageSizeChangeDetails) => void`
Called when the page size is changed
`translations`
`IntlTranslations`
Specifies the localized strings that identifies the accessibility elements and their states
[Previous
\
Number Input](https://www.chakra-ui.com/docs/components/number-input)
[Next
\
Password Input](https://www.chakra-ui.com/docs/components/password-input) |
https://www.chakra-ui.com/docs/components/pagination?page=5 | 1. Components
2. Pagination
# Pagination
Used to navigate through a series of pages.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/pagination)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-pagination--basic)[Ark](https://ark-ui.com/react/docs/components/pagination)
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `pagination` snippet
```
npx @chakra-ui/cli snippet add pagination
```
The snippet includes a closed component composition for the `Pagination` component.
## [Usage]()
```
import {
PaginationItems,
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
```
```
<PaginationRoot>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationPageText />
<PaginationNextTrigger />
</PaginationRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the pagination.
info
The pagination sizes are mapped to the `Button` component sizes.
PreviewCode
1235
1235
1235
1235
```
import { For, HStack, Stack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<Stack gap="8">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<PaginationRoot
key={size}
count={10}
pageSize={2}
defaultPage={1}
size={size}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)}
</For>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to control the variant of the pagination items and ellipsis.
The variant matches the `Button` component variant.
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1} variant="solid">
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Controlled]()
Use the `page` and `onPageChange` props to control the current page.
PreviewCode
1234510
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const Demo = () => {
const [page, setPage] = useState(1)
return (
<PaginationRoot
count={20}
pageSize={2}
page={page}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Sibling Count]()
Use `siblingCount` to control the number of sibling pages to show before and after the current page.
PreviewCode
18910111220
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={200} pageSize={10} defaultPage={10} siblingCount={2}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Compact]()
Use the `PaginationPageText` to create a compact pagination. This can be useful for mobile views.
PreviewCode
1 of 10
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack gap="4">
<PaginationPrevTrigger />
<PaginationPageText />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [As Link]()
Use the `getHref` prop to create a pagination that navigates via links. This will use the `LinkButton` component to create the links.
info
Edit the `LinkButton` component to point to the correct framework link component if needed.
PreviewCode
[]()[1](https://www.chakra-ui.com/docs/components/pagination?page=1)[2](https://www.chakra-ui.com/docs/components/pagination?page=2)[3](https://www.chakra-ui.com/docs/components/pagination?page=3)[4](https://www.chakra-ui.com/docs/components/pagination?page=4)[5](https://www.chakra-ui.com/docs/components/pagination?page=5)[10](https://www.chakra-ui.com/docs/components/pagination?page=10)[](https://www.chakra-ui.com/docs/components/pagination?page=2)
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot
count={20}
pageSize={2}
defaultPage={1}
getHref={(page) => `?page=${page}`}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Attached]()
Here's an example of composing the pagination with the `Group` component to attach the pagination items and triggers.
PreviewCode
1235
```
import { Group } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={10} pageSize={2} defaultPage={1} variant="solid">
<Group attached>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</Group>
</PaginationRoot>
)
}
```
### [Count Text]()
Pass `format=long` to the `PaginationPageText` component to show the count text
PreviewCode
1 - 5 of 50
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={50} pageSize={5} defaultPage={1} maxW="240px">
<HStack gap="4">
<PaginationPageText format="long" flex="1" />
<PaginationPrevTrigger />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Data Driven]()
Here's an example of controlling the pagination state and using the state to chunk the data.
PreviewCode
Lorem ipsum dolor sit amet 1
Lorem ipsum dolor sit amet 2
Lorem ipsum dolor sit amet 3
Lorem ipsum dolor sit amet 4
Lorem ipsum dolor sit amet 5
1234510
```
"use client"
import { HStack, Stack, Text } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const pageSize = 5
const count = 50
const items = new Array(count)
.fill(0)
.map((_, index) => `Lorem ipsum dolor sit amet ${index + 1}`)
const Demo = () => {
const [page, setPage] = useState(1)
const startRange = (page - 1) * pageSize
const endRange = startRange + pageSize
const visibleItems = items.slice(startRange, endRange)
return (
<Stack gap="4">
<Stack>
{visibleItems.map((item) => (
<Text key={item}>{item}</Text>
))}
</Stack>
<PaginationRoot
page={page}
count={count}
pageSize={pageSize}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
</Stack>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`count`*
`number`
Total number of data items
`page``'1'`
`number`
The active page
`pageSize``'10'`
`number`
Number of data items per page
`siblingCount``'1'`
`number`
Number of pages to show beside active page
`type``'\'button\''`
`'button' | 'link'`
The type of the trigger element
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultPage`
`number`
The initial page of the pagination when it is first rendered. Use when you do not need to control the state of the pagination.
`ids`
`Partial<{ root: string ellipsis(index: number): string prevTrigger: string nextTrigger: string item(page: number): string }>`
The ids of the elements in the accordion. Useful for composition.
`onPageChange`
`(details: PageChangeDetails) => void`
Called when the page number is changed
`onPageSizeChange`
`(details: PageSizeChangeDetails) => void`
Called when the page size is changed
`translations`
`IntlTranslations`
Specifies the localized strings that identifies the accessibility elements and their states
[Previous
\
Number Input](https://www.chakra-ui.com/docs/components/number-input)
[Next
\
Password Input](https://www.chakra-ui.com/docs/components/password-input) |
https://www.chakra-ui.com/docs/components/pagination?page=10 | 1. Components
2. Pagination
# Pagination
Used to navigate through a series of pages.
[Source](https://github.com/chakra-ui/chakra-ui/tree/main/packages/react/src/components/pagination)[Storybook](https://storybook.chakra-ui.com/?path=%2Fstory%2Fcomponents-pagination--basic)[Ark](https://ark-ui.com/react/docs/components/pagination)
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
## [Setup]()
If you don't already have the snippet, run the following command to add the `pagination` snippet
```
npx @chakra-ui/cli snippet add pagination
```
The snippet includes a closed component composition for the `Pagination` component.
## [Usage]()
```
import {
PaginationItems,
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
```
```
<PaginationRoot>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationPageText />
<PaginationNextTrigger />
</PaginationRoot>
```
## [Examples]()
### [Sizes]()
Use the `size` prop to change the size of the pagination.
info
The pagination sizes are mapped to the `Button` component sizes.
PreviewCode
1235
1235
1235
1235
```
import { For, HStack, Stack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<Stack gap="8">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<PaginationRoot
key={size}
count={10}
pageSize={2}
defaultPage={1}
size={size}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)}
</For>
</Stack>
)
}
```
### [Variants]()
Use the `variant` prop to control the variant of the pagination items and ellipsis.
The variant matches the `Button` component variant.
PreviewCode
1234510
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1} variant="solid">
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Controlled]()
Use the `page` and `onPageChange` props to control the current page.
PreviewCode
1234510
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const Demo = () => {
const [page, setPage] = useState(1)
return (
<PaginationRoot
count={20}
pageSize={2}
page={page}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Sibling Count]()
Use `siblingCount` to control the number of sibling pages to show before and after the current page.
PreviewCode
18910111220
```
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={200} pageSize={10} defaultPage={10} siblingCount={2}>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Compact]()
Use the `PaginationPageText` to create a compact pagination. This can be useful for mobile views.
PreviewCode
1 of 10
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={20} pageSize={2} defaultPage={1}>
<HStack gap="4">
<PaginationPrevTrigger />
<PaginationPageText />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [As Link]()
Use the `getHref` prop to create a pagination that navigates via links. This will use the `LinkButton` component to create the links.
info
Edit the `LinkButton` component to point to the correct framework link component if needed.
PreviewCode
[]()[1](https://www.chakra-ui.com/docs/components/pagination?page=1)[2](https://www.chakra-ui.com/docs/components/pagination?page=2)[3](https://www.chakra-ui.com/docs/components/pagination?page=3)[4](https://www.chakra-ui.com/docs/components/pagination?page=4)[5](https://www.chakra-ui.com/docs/components/pagination?page=5)[10](https://www.chakra-ui.com/docs/components/pagination?page=10)[](https://www.chakra-ui.com/docs/components/pagination?page=2)
```
"use client"
import { HStack } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot
count={20}
pageSize={2}
defaultPage={1}
getHref={(page) => `?page=${page}`}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Attached]()
Here's an example of composing the pagination with the `Group` component to attach the pagination items and triggers.
PreviewCode
1235
```
import { Group } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={10} pageSize={2} defaultPage={1} variant="solid">
<Group attached>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</Group>
</PaginationRoot>
)
}
```
### [Count Text]()
Pass `format=long` to the `PaginationPageText` component to show the count text
PreviewCode
1 - 5 of 50
```
import { HStack } from "@chakra-ui/react"
import {
PaginationNextTrigger,
PaginationPageText,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
const Demo = () => {
return (
<PaginationRoot count={50} pageSize={5} defaultPage={1} maxW="240px">
<HStack gap="4">
<PaginationPageText format="long" flex="1" />
<PaginationPrevTrigger />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
)
}
```
### [Data Driven]()
Here's an example of controlling the pagination state and using the state to chunk the data.
PreviewCode
Lorem ipsum dolor sit amet 1
Lorem ipsum dolor sit amet 2
Lorem ipsum dolor sit amet 3
Lorem ipsum dolor sit amet 4
Lorem ipsum dolor sit amet 5
1234510
```
"use client"
import { HStack, Stack, Text } from "@chakra-ui/react"
import {
PaginationItems,
PaginationNextTrigger,
PaginationPrevTrigger,
PaginationRoot,
} from "@/components/ui/pagination"
import { useState } from "react"
const pageSize = 5
const count = 50
const items = new Array(count)
.fill(0)
.map((_, index) => `Lorem ipsum dolor sit amet ${index + 1}`)
const Demo = () => {
const [page, setPage] = useState(1)
const startRange = (page - 1) * pageSize
const endRange = startRange + pageSize
const visibleItems = items.slice(startRange, endRange)
return (
<Stack gap="4">
<Stack>
{visibleItems.map((item) => (
<Text key={item}>{item}</Text>
))}
</Stack>
<PaginationRoot
page={page}
count={count}
pageSize={pageSize}
onPageChange={(e) => setPage(e.page)}
>
<HStack>
<PaginationPrevTrigger />
<PaginationItems />
<PaginationNextTrigger />
</HStack>
</PaginationRoot>
</Stack>
)
}
```
## [Props]()
### [Root]()
PropDefaultType`count`*
`number`
Total number of data items
`page``'1'`
`number`
The active page
`pageSize``'10'`
`number`
Number of data items per page
`siblingCount``'1'`
`number`
Number of pages to show beside active page
`type``'\'button\''`
`'button' | 'link'`
The type of the trigger element
`asChild`
`boolean`
Use the provided child element as the default rendered element, combining their props and behavior.
For more details, read our [Composition](https://www.chakra-ui.com/docs/guides/composition) guide.
`defaultPage`
`number`
The initial page of the pagination when it is first rendered. Use when you do not need to control the state of the pagination.
`ids`
`Partial<{ root: string ellipsis(index: number): string prevTrigger: string nextTrigger: string item(page: number): string }>`
The ids of the elements in the accordion. Useful for composition.
`onPageChange`
`(details: PageChangeDetails) => void`
Called when the page number is changed
`onPageSizeChange`
`(details: PageSizeChangeDetails) => void`
Called when the page size is changed
`translations`
`IntlTranslations`
Specifies the localized strings that identifies the accessibility elements and their states
[Previous
\
Number Input](https://www.chakra-ui.com/docs/components/number-input)
[Next
\
Password Input](https://www.chakra-ui.com/docs/components/password-input) |