HueSlider
HueSlider is a component used to allow the user to select a color hue.
<HueSlider.Root defaultValue={180} />
Usage
import { HueSlider } from "@yamada-ui/react"
import { HueSlider } from "@/components/ui"
import { HueSlider } from "@workspaces/ui"
<HueSlider.Root />
Change Size
<VStack>
<For each={["sm", "md", "lg"]}>
{(size, index) => (
<HueSlider.Root key={index} size={size} defaultValue={180} />
)}
</For>
</VStack>
Set Default Value
To set a default value, set a value to defaultValue.
<HueSlider.Root defaultValue={270} />
Set Min and Max Values
To set minimum and maximum values, set numbers to min or max.
<HueSlider.Root defaultValue={300} min={270} max={360} />
Change Orientation
To change the orientation, set orientation to "vertical" or "horizontal". By default, "horizontal" is set.
<HueSlider.Root defaultValue={180} orientation="vertical" h="xs" />
Change Shape
<VStack>
<For each={["circle", "rounded", "square"]}>
{(shape, index) => (
<HueSlider.Root key={index} defaultValue={180} shape={shape} />
)}
</For>
</VStack>
Set Step Value
To set a step value, set a value to step.
<HueSlider.Root defaultValue={180} step={10} />
Disable
To disable, set disabled to true.
<HueSlider.Root defaultValue={180} disabled />
Read-Only
To make read-only, set readOnly to true.
<HueSlider.Root defaultValue={180} readOnly />
Display Tooltip
const [value, setValue] = useState(50)
return (
<HueSlider.Root value={value} onChange={setValue}>
<HueSlider.Track>
<Tooltip content={value}>
<HueSlider.Thumb />
</Tooltip>
<HueSlider.Overlay />
</HueSlider.Track>
</HueSlider.Root>
)
"use client" to the top of the file.Handle Start and End Events
To handle start and end events, use onChangeStart or onChangeEnd.
Value: 180, Start Value: 180, End Value: 180
const [value, onChange] = useState(180)
const [startValue, onChangeStart] = useState(180)
const [endValue, onChangeEnd] = useState(180)
return (
<VStack>
<Text>
Value: {value}, Start Value: {startValue}, End Value: {endValue}
</Text>
<HueSlider.Root
value={value}
onChange={onChange}
onChangeStart={onChangeStart}
onChangeEnd={onChangeEnd}
/>
</VStack>
)
"use client" to the top of the file.Control
const [value, setValue] = useState(180)
return <HueSlider.Root value={value} onChange={setValue} />
"use client" to the top of the file.Props
Accessibility
The HueSlider follows the WAI-ARIA - Slider Pattern for accessibility.
Keyboard Navigation
| Key | Description | State |
|---|---|---|
ArrowRight | Increases the value based on the step value. | - |
ArrowLeft | Decreases the value based on the step value. | - |
ArrowUp | Increases the value based on the step value. | - |
ArrowDown | Decreases the value based on the step value. | - |
Home | Sets the value to min. | - |
End | Sets the value to max. | - |
PageUp | Increases the value based on the min and max values. | - |
PageDown | Decreases the value based on the min and max values. | - |
ARIA Roles and Attributes
| Component | Role and Attributes | Usage |
|---|---|---|
HueSlider.Thumb | role="slider" | Indicates that this is a slider. |
aria-label | Sets "Slider thumb". | |
aria-labelledby | Sets the id of the associated HueSlider.Root. | |
aria-orientation | Sets "horizontal" or "vertical" based on the orientation value. Default is "horizontal". | |
aria-valuemin | Sets the min value. Default is 0. | |
aria-valuemax | Sets the max value. Default is 360. | |
aria-valuenow | Sets the current value. | |
aria-valuetext | Sets the current value, such as "18°, Red". | |
aria-describedby | If HueSlider.Thumb is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id. | |
aria-readonly | Set to "true" if readOnly is set. | |
aria-disabled | Set to "true" if disabled is set. | |
aria-invalid | Set to "true" if invalid is set. | |
aria-required | Set to "true" if required is set. | |
SliderInput | type="hidden" | Excludes the element from the accessibility tree. |
aria-describedby | If HueSlider.Root is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id. | |
aria-readonly | Set to "true" if readOnly is set. | |
aria-disabled | Set to "true" if disabled is set. | |
aria-invalid | Set to "true" if invalid is set. | |
aria-required | Set to "true" if required is set. |