-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(Slider): forward aria attributes to the thumb #6848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
394df91
f05615d
542afc4
0a8050f
b56f385
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ import { reactivePick } from '@vueuse/core' | |
| import { useAppConfig } from '#imports' | ||
| import { useComponentProps } from '../composables/useComponentProps' | ||
| import { useFormField } from '../composables/useFormField' | ||
| import { pick, omit } from '../utils' | ||
| import { tv } from '../utils/tv' | ||
| import UTooltip from './Tooltip.vue' | ||
|
|
||
|
|
@@ -62,6 +63,8 @@ const _props = withDefaults(defineProps<SliderProps>(), { | |
| }) | ||
| const emits = defineEmits<SliderEmits>() | ||
|
|
||
| defineOptions({ inheritAttrs: false }) | ||
|
|
||
| const props = useComponentProps<SliderProps>('slider', _props) | ||
|
|
||
| const modelValue = defineModel<T>() | ||
|
|
@@ -100,6 +103,10 @@ const sliderValue = computed({ | |
|
|
||
| const thumbs = computed(() => sliderValue.value?.length ?? 1) | ||
|
|
||
| // The thumb is the element with `role="slider"`, so these describe it rather than the root. | ||
| // Multiple thumbs keep Reka UI's positional names and the caller's label groups them on the root. | ||
| const thumbAttrs = ['aria-label', 'aria-labelledby', 'aria-describedby', 'aria-valuetext', 'aria-invalid', 'aria-errormessage'] | ||
|
|
||
| // eslint-disable-next-line vue/no-dupe-keys | ||
| const ui = computed(() => tv({ extend: theme, ...(appConfig.ui?.slider || {}) })({ | ||
| disabled: disabled.value, | ||
|
|
@@ -118,12 +125,13 @@ function onChange(value: any) { | |
|
|
||
| <template> | ||
| <SliderRoot | ||
| v-bind="rootProps" | ||
| :id="id" | ||
| v-model="sliderValue" | ||
| data-slot="root" | ||
| :role="thumbs > 1 && ($attrs['aria-label'] || $attrs['aria-labelledby']) ? 'group' : undefined" | ||
| v-bind="{ ...rootProps, ...(thumbs > 1 ? $attrs : omit($attrs, thumbAttrs)) }" | ||
| :name="name" | ||
| :disabled="disabled" | ||
| data-slot="root" | ||
| :class="ui.root({ class: [props.ui?.root, props.class] })" | ||
| :default-value="defaultSliderValue" | ||
| @update:model-value="emitFormInput()" | ||
|
|
@@ -140,9 +148,9 @@ function onChange(value: any) { | |
| disable-closing-trigger | ||
| v-bind="(typeof props.tooltip === 'object' ? props.tooltip : {})" | ||
| > | ||
| <SliderThumb data-slot="thumb" :class="ui.thumb({ class: props.ui?.thumb })" :aria-label="thumbs === 1 ? 'Thumb' : `Thumb ${thumb} of ${thumbs}`" v-bind="ariaAttrs" /> | ||
| <SliderThumb data-slot="thumb" :class="ui.thumb({ class: props.ui?.thumb })" v-bind="{ ...(thumbs === 1 ? pick($attrs, thumbAttrs) : {}), ...ariaAttrs }" :aria-label="thumbs > 1 || $attrs['aria-labelledby'] ? undefined : ($attrs['aria-label'] ?? 'Thumb')" /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π― Functional Correctness | π‘ Minor | β‘ Quick win Merge
Concatenate and de-duplicate both ID lists. Keep FormField control of π€ Prompt for AI Agents |
||
| </UTooltip> | ||
| <SliderThumb v-else data-slot="thumb" :class="ui.thumb({ class: props.ui?.thumb })" :aria-label="thumbs === 1 ? 'Thumb' : `Thumb ${thumb} of ${thumbs}`" v-bind="ariaAttrs" /> | ||
| <SliderThumb v-else data-slot="thumb" :class="ui.thumb({ class: props.ui?.thumb })" v-bind="{ ...(thumbs === 1 ? pick($attrs, thumbAttrs) : {}), ...ariaAttrs }" :aria-label="thumbs > 1 || $attrs['aria-labelledby'] ? undefined : ($attrs['aria-label'] ?? 'Thumb')" /> | ||
| </template> | ||
| </SliderRoot> | ||
| </template> | ||
Uh oh!
There was an error while loading. Please reload this page.