Slider
Choose a value or range by dragging a handle or using the keyboard.
Demos
Size
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Installation
Complete the shared installation. Copy Slider.vue and index.ts into app/components/ui/slider/.
app/components/ui/slider/Slider.vue
<script setup lang="ts">
import { AlertDialog as Primitive } from 'akaza-ui'
import { computed, useAttrs, useTemplateRef } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
alertDialogVariants,
resolveAlertDialogVariants,
type AlertDialogProps,
type AlertDialogSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AlertDialogProps>(), {
as: undefined,
teleport: undefined,
transition: undefined,
duration: undefined,
title: undefined,
ariaLabel: undefined,
description: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AlertDialogSlots>()
const attrs = useAttrs()
const styles = computed(() => alertDialogVariants(resolveAlertDialogVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'content' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, width: _width, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
defineExpose({
get open() {
return primitive.value!.open
},
get close() {
return primitive.value!.close
},
get toggle() {
return primitive.value!.toggle
},
get titleId() {
return primitive.value!.titleId
},
get descriptionId() {
return primitive.value!.descriptionId
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AlertDialogSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | field id | Thumb id. |
name | string | field name | Form field name. Renders hidden range input. |
min | number | 0 | Minimum value. |
max | number | 100 | Maximum value. |
step | number | 1 | Keyboard and pointer snapping step. |
orientation | "horizontal" | "vertical" | "horizontal" | Slider orientation. |
minStepsBetweenThumbs | number | 0 | Minimum distance between adjacent thumbs, in step units. |
inverted | boolean | false | Reverses value direction. |
thumbAlignment | "center" | "contain" | "center" | Thumb alignment metadata exposed as a data attr. |
required | boolean | false | Required state for hidden input. |
disabled | boolean | false | Disabled state. |
invalid | boolean | false | Sets invalid attrs. |
ariaLabel | string | — | Accessible label when no visible label exists. |
ariaLabels | string[] | — | Per-thumb accessible labels for range sliders. |
ariaLabelledby | string | — | Accessible label id. |
ariaDescribedby | string | field description/error | Accessible description ids. |
getValueLabel | (value, max) => string | undefined | — | Human-readable aria-valuetext. |
ui | SliderUi | — | Classes for structural parts. |
Slots
| Slot | Props | Description |
|---|---|---|
range | value, values, percentage, percentages | Custom range content. |
thumb | value, values, index, percentage, percentages | Custom thumb content. |
Events
| Event | Payload | Description |
|---|---|---|
value-change | (value: number | number[], details) | Fired before model updates. details.cancel() prevents the update. |
value-commit | (value: number | number[], details) | Fired at the end of pointer or keyboard interaction. |
Keyboard
| Key | Behavior |
|---|---|
ArrowRight / ArrowUp | Increment by step. |
ArrowLeft / ArrowDown | Decrement by step. |
PageUp / PageDown | Increment/decrement by step * 10. |
Home / End | Set to min/max. |