@aleph-alpha/ui-library 7.0.2 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,15 @@
1
1
  <script setup lang="ts">
2
2
  import type { SliderRootEmits } from 'reka-ui';
3
+ import { useDirection } from 'reka-ui';
4
+ import { computed, toRef } from 'vue';
3
5
  import { Slider as ShadcnSlider } from '@/components/core/slider';
6
+ import { cn } from '@/lib/utils';
7
+ import {
8
+ stepMarkPercents,
9
+ stepsIntervalOrDefault,
10
+ trackStartEdge,
11
+ type TrackStartEdge,
12
+ } from './step-marks';
4
13
  import type { UiSliderProps, UiSliderEmits } from './types';
5
14
 
6
15
  defineOptions({
@@ -21,6 +30,81 @@ function handleModelValueUpdate(
21
30
  // reka-ui can emit undefined in some cases; keep our public API stable.
22
31
  emit('update:modelValue', []);
23
32
  }
33
+
34
+ const isVertical = computed(() => props.orientation === 'vertical');
35
+
36
+ // Room above the track for the shown value. The handle overhangs the thin
37
+ // track, so this is taller than the value's own line.
38
+ const rootClass = computed(() =>
39
+ cn(props.showValue && !isVertical.value && 'pt-6'),
40
+ );
41
+
42
+ function valueText(value: number): string {
43
+ return props.formatValue ? props.formatValue(value) : String(value);
44
+ }
45
+
46
+ // The same direction the vendor slider uses: the prop, else the app's
47
+ // ConfigProvider, else left to right.
48
+ const direction = useDirection(toRef(props, 'dir'));
49
+
50
+ const startEdge = computed(() =>
51
+ trackStartEdge(
52
+ props.orientation ?? 'horizontal',
53
+ direction.value,
54
+ props.inverted,
55
+ ),
56
+ );
57
+
58
+ // Defaults match the vendor slider's, so the marks line up with what it draws.
59
+ const markPercents = computed(() => {
60
+ const min = props.min ?? 0;
61
+ const max = props.max ?? 100;
62
+ const interval = stepsIntervalOrDefault(
63
+ min,
64
+ max,
65
+ props.step ?? 1,
66
+ props.stepsInterval,
67
+ );
68
+ return stepMarkPercents(min, max, interval);
69
+ });
70
+
71
+ // Lies over the track, centred on it the way the vendor centres the handle.
72
+ // In 'contain' mode the handle's centre stops half a handle short of each end,
73
+ // so the marks are inset by the same amount.
74
+ const marksLayerClass = computed(() =>
75
+ cn(
76
+ 'pointer-events-none absolute',
77
+ isVertical.value ? 'inset-y-0 w-1.5' : 'inset-x-0 h-1.5',
78
+ props.thumbAlignment !== 'overflow' &&
79
+ (isVertical.value
80
+ ? 'my-[calc(var(--slider-thumb-size)/2)]'
81
+ : 'mx-[calc(var(--slider-thumb-size)/2)]'),
82
+ ),
83
+ );
84
+
85
+ // Centres each mark on its position, the way the vendor centres the handle.
86
+ const markCentring: Record<TrackStartEdge, string> = {
87
+ left: 'top-1/2 -translate-x-1/2 -translate-y-1/2',
88
+ right: 'top-1/2 translate-x-1/2 -translate-y-1/2',
89
+ bottom: 'left-1/2 -translate-x-1/2 translate-y-1/2',
90
+ top: 'left-1/2 -translate-x-1/2 -translate-y-1/2',
91
+ };
92
+
93
+ const markClass = computed(() =>
94
+ cn(
95
+ 'bg-background-accent-soft absolute size-1 rounded-full',
96
+ markCentring[startEdge.value],
97
+ ),
98
+ );
99
+
100
+ const valueLabelClass = computed(() =>
101
+ cn(
102
+ 'label-xs-regular text-content-on-surface-primary pointer-events-none absolute whitespace-nowrap',
103
+ isVertical.value
104
+ ? 'top-1/2 left-full ml-2 -translate-y-1/2'
105
+ : 'bottom-full left-1/2 mb-1 -translate-x-1/2',
106
+ ),
107
+ );
24
108
  </script>
25
109
 
26
110
  <template>
@@ -38,7 +122,31 @@ function handleModelValueUpdate(
38
122
  :thumb-alignment="props.thumbAlignment"
39
123
  :name="props.name"
40
124
  :required="props.required"
125
+ :class="rootClass"
126
+ :thumb-value-text="props.formatValue"
41
127
  @update:model-value="handleModelValueUpdate"
42
128
  @value-commit="emit('valueCommit', $event)"
43
- />
129
+ >
130
+ <template v-if="props.showSteps" #track-overlay>
131
+ <div aria-hidden="true" :class="marksLayerClass">
132
+ <span
133
+ v-for="percent in markPercents"
134
+ :key="percent"
135
+ data-slot="slider-step-mark"
136
+ :class="markClass"
137
+ :style="{ [startEdge]: `${percent}%` }"
138
+ />
139
+ </div>
140
+ </template>
141
+
142
+ <template v-if="props.showValue" #thumb="{ value }">
143
+ <span
144
+ aria-hidden="true"
145
+ data-slot="slider-value"
146
+ :class="valueLabelClass"
147
+ >
148
+ {{ valueText(value) }}
149
+ </span>
150
+ </template>
151
+ </ShadcnSlider>
44
152
  </template>
@@ -0,0 +1,210 @@
1
+ import { render } from '@testing-library/vue';
2
+ import { ConfigProvider } from 'reka-ui';
3
+ import { describe, expect, test } from 'vitest';
4
+ import { h } from 'vue';
5
+ import { Slider as ShadcnSlider } from '@/components/core/slider';
6
+ import { UiSlider } from '../index';
7
+
8
+ // Mounted against the real vendor slider, unlike `UiSlider.test.ts`, which
9
+ // stubs it to exercise the payload guard.
10
+
11
+ const valueLabels = (container: Element) =>
12
+ [...container.querySelectorAll('[data-slot="slider-value"]')].map(
13
+ (label) => label.textContent,
14
+ );
15
+
16
+ const stepMarks = (container: Element) => [
17
+ ...container.querySelectorAll<HTMLElement>('[data-slot="slider-step-mark"]'),
18
+ ];
19
+
20
+ describe('UiSlider value and step marks', () => {
21
+ test('renders exactly what the base slider renders unless asked for more', () => {
22
+ const props = { modelValue: [25, 75], min: 0, max: 100, step: 10 };
23
+
24
+ const wrapped = render(UiSlider, { props }).container.innerHTML;
25
+ const base = render(ShadcnSlider, { props }).container.innerHTML;
26
+
27
+ expect(wrapped).toBe(base);
28
+ });
29
+
30
+ test('draws neither a value nor step marks unless asked to', () => {
31
+ const { container } = render(UiSlider, { props: { modelValue: [50] } });
32
+
33
+ expect(valueLabels(container)).toEqual([]);
34
+ expect(stepMarks(container)).toHaveLength(0);
35
+ });
36
+
37
+ test('shows the value above each handle', () => {
38
+ const { container } = render(UiSlider, {
39
+ props: { modelValue: [25, 75], showValue: true },
40
+ });
41
+
42
+ expect(valueLabels(container)).toEqual(['25', '75']);
43
+ });
44
+
45
+ test('writes the value the way formatValue says', () => {
46
+ const { container } = render(UiSlider, {
47
+ props: {
48
+ modelValue: [70],
49
+ showValue: true,
50
+ formatValue: (value: number) => `${value}%`,
51
+ },
52
+ });
53
+
54
+ expect(valueLabels(container)).toEqual(['70%']);
55
+ });
56
+
57
+ // That the handle still announces the value is checked by the stories: under
58
+ // jsdom the vendor renders the handle without its slider role and values.
59
+ test('keeps the shown value hidden from screen readers', () => {
60
+ const { container } = render(UiSlider, {
61
+ props: { modelValue: [70], showValue: true },
62
+ });
63
+
64
+ const label = container.querySelector('[data-slot="slider-value"]');
65
+ expect(label).toHaveAttribute('aria-hidden', 'true');
66
+ });
67
+
68
+ test('updates the shown value when the model changes', async () => {
69
+ const { container, rerender } = render(UiSlider, {
70
+ props: { modelValue: [10], showValue: true },
71
+ });
72
+
73
+ await rerender({ modelValue: [40], showValue: true });
74
+
75
+ expect(valueLabels(container)).toEqual(['40']);
76
+ });
77
+
78
+ test('draws one mark per reachable step, hidden from screen readers', () => {
79
+ const { container } = render(UiSlider, {
80
+ props: { modelValue: [50], min: 0, max: 100, step: 10, showSteps: true },
81
+ });
82
+
83
+ const marks = stepMarks(container);
84
+ expect(marks).toHaveLength(11);
85
+ expect(marks[0].closest('[aria-hidden="true"]')).not.toBeNull();
86
+ });
87
+
88
+ test('places the marks from the edge the track starts at', () => {
89
+ const { container } = render(UiSlider, {
90
+ props: {
91
+ modelValue: [50],
92
+ step: 50,
93
+ dir: 'rtl',
94
+ showSteps: true,
95
+ },
96
+ });
97
+
98
+ const marks = stepMarks(container);
99
+ expect(marks.map((mark) => mark.style.right)).toEqual([
100
+ '0%',
101
+ '50%',
102
+ '100%',
103
+ ]);
104
+ expect(marks.every((mark) => mark.style.left === '')).toBe(true);
105
+ });
106
+
107
+ test('mirrors the marks for an inverted slider when no direction is given', () => {
108
+ const { container } = render(UiSlider, {
109
+ props: { modelValue: [50], step: 50, inverted: true, showSteps: true },
110
+ });
111
+
112
+ const marks = stepMarks(container);
113
+ expect(marks.map((mark) => mark.style.right)).toEqual([
114
+ '0%',
115
+ '50%',
116
+ '100%',
117
+ ]);
118
+ expect(marks.every((mark) => mark.style.left === '')).toBe(true);
119
+ });
120
+
121
+ test('places the marks from the right when the app reads right to left', () => {
122
+ const { container } = render({
123
+ render: () =>
124
+ h(ConfigProvider, { dir: 'rtl' }, () =>
125
+ h(UiSlider, { modelValue: [50], step: 50, showSteps: true }),
126
+ ),
127
+ });
128
+
129
+ expect(stepMarks(container).map((mark) => mark.style.right)).toEqual([
130
+ '0%',
131
+ '50%',
132
+ '100%',
133
+ ]);
134
+ });
135
+
136
+ test('places the marks from the bottom of a vertical slider', () => {
137
+ const { container } = render(UiSlider, {
138
+ props: {
139
+ modelValue: [50],
140
+ step: 50,
141
+ orientation: 'vertical',
142
+ showSteps: true,
143
+ },
144
+ });
145
+
146
+ expect(stepMarks(container).map((mark) => mark.style.bottom)).toEqual([
147
+ '0%',
148
+ '50%',
149
+ '100%',
150
+ ]);
151
+ });
152
+
153
+ // The track clips what it holds, which would cut the end marks in half
154
+ // where the handle runs to the very ends.
155
+ test('draws the marks outside the track, so the end marks are not cut off', () => {
156
+ const { container } = render(UiSlider, {
157
+ props: { modelValue: [50], showSteps: true },
158
+ });
159
+
160
+ const track = container.querySelector('[data-slot="slider-track"]');
161
+ expect(stepMarks(container).length).toBeGreaterThan(0);
162
+ expect(stepMarks(container).some((mark) => track?.contains(mark))).toBe(
163
+ false,
164
+ );
165
+ });
166
+
167
+ test('draws the marks at their own interval when it differs from the step', () => {
168
+ const { container } = render(UiSlider, {
169
+ props: {
170
+ modelValue: [50],
171
+ step: 1,
172
+ stepsInterval: 10,
173
+ showSteps: true,
174
+ },
175
+ });
176
+
177
+ expect(stepMarks(container).map((mark) => mark.style.left)).toEqual(
178
+ Array.from({ length: 11 }, (_, index) => `${index * 10}%`),
179
+ );
180
+ });
181
+
182
+ test('spaces the marks of a fine slider out to a tenth of its range by default', () => {
183
+ const { container } = render(UiSlider, {
184
+ props: { modelValue: [50], step: 1, showSteps: true },
185
+ });
186
+
187
+ expect(stepMarks(container)).toHaveLength(11);
188
+ });
189
+
190
+ test('keeps an interval as fine as a hundredth of the range', () => {
191
+ const { container } = render(UiSlider, {
192
+ props: { modelValue: [50], step: 1, stepsInterval: 1, showSteps: true },
193
+ });
194
+
195
+ expect(stepMarks(container)).toHaveLength(101);
196
+ });
197
+
198
+ test('falls back to the default spacing for an interval finer than a hundredth of the range', () => {
199
+ const { container } = render(UiSlider, {
200
+ props: {
201
+ modelValue: [50],
202
+ step: 0.5,
203
+ stepsInterval: 0.5,
204
+ showSteps: true,
205
+ },
206
+ });
207
+
208
+ expect(stepMarks(container)).toHaveLength(11);
209
+ });
210
+ });
@@ -0,0 +1,94 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import {
3
+ defaultStepsInterval,
4
+ stepMarkPercents,
5
+ stepsIntervalOrDefault,
6
+ trackStartEdge,
7
+ } from '../step-marks';
8
+
9
+ describe('stepMarkPercents', () => {
10
+ test('places one mark per step, from the start to the end of the track', () => {
11
+ expect(stepMarkPercents(0, 100, 10)).toEqual([
12
+ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
13
+ ]);
14
+ });
15
+
16
+ test('ends with a mark at the maximum when the interval does not divide the range', () => {
17
+ // The handle reaches the maximum too: a step past 90 is clamped to it.
18
+ expect(stepMarkPercents(0, 100, 30)).toEqual([0, 30, 60, 90, 100]);
19
+ });
20
+
21
+ test('keeps the last mark at the end of the track for fractional steps', () => {
22
+ const percents = stepMarkPercents(0, 1, 0.1);
23
+
24
+ expect(percents).toHaveLength(11);
25
+ expect(percents.at(-1)).toBe(100);
26
+ });
27
+
28
+ test('measures from min when the range does not start at zero', () => {
29
+ expect(stepMarkPercents(20, 60, 10)).toEqual([0, 25, 50, 75, 100]);
30
+ });
31
+
32
+ test('returns no marks for an interval or range that cannot be drawn', () => {
33
+ expect(stepMarkPercents(0, 100, 0)).toEqual([]);
34
+ expect(stepMarkPercents(0, 100, -5)).toEqual([]);
35
+ expect(stepMarkPercents(50, 50, 1)).toEqual([]);
36
+ expect(stepMarkPercents(100, 0, 1)).toEqual([]);
37
+ });
38
+ });
39
+
40
+ describe('defaultStepsInterval', () => {
41
+ test('keeps the step when it already gives at most a dot every tenth of the range', () => {
42
+ expect(defaultStepsInterval(0, 100, 10)).toBe(10);
43
+ expect(defaultStepsInterval(0, 100, 30)).toBe(30);
44
+ });
45
+
46
+ test('spaces a fine slider out to a tenth of its range', () => {
47
+ expect(defaultStepsInterval(0, 100, 1)).toBe(10);
48
+ expect(defaultStepsInterval(0, 1, 0.01)).toBe(0.1);
49
+ });
50
+
51
+ test('stays on values the handle can reach when a tenth is not a whole number of steps', () => {
52
+ expect(defaultStepsInterval(0, 100, 3)).toBe(12);
53
+ });
54
+ });
55
+
56
+ describe('stepsIntervalOrDefault', () => {
57
+ test('uses the requested gap down to a hundredth of the range', () => {
58
+ expect(stepsIntervalOrDefault(0, 100, 1, 5)).toBe(5);
59
+ expect(stepsIntervalOrDefault(0, 100, 1, 1)).toBe(1);
60
+ expect(stepsIntervalOrDefault(0, 1, 0.01, 0.01)).toBe(0.01);
61
+ });
62
+
63
+ test('uses the default gap when none is requested or it is finer than a hundredth', () => {
64
+ expect(stepsIntervalOrDefault(0, 100, 1)).toBe(10);
65
+ expect(stepsIntervalOrDefault(0, 100, 1, 0.001)).toBe(10);
66
+ expect(stepsIntervalOrDefault(0, 100, 1, 0)).toBe(10);
67
+ });
68
+
69
+ test('keeps a gap of exactly a hundredth when floating-point rounding makes the range a hair larger', () => {
70
+ // 0.4 - 0.1 is 0.30000000000000004 in floating point.
71
+ expect(stepsIntervalOrDefault(0.1, 0.4, 0.003, 0.003)).toBe(0.003);
72
+ });
73
+
74
+ test('holds the hundredth limit on a very small range too', () => {
75
+ expect(stepsIntervalOrDefault(0, 1e-8, 1e-9, 1e-15)).toBe(1e-9);
76
+ });
77
+ });
78
+
79
+ describe('trackStartEdge', () => {
80
+ test('a horizontal track starts on the left, or the right when it reads right to left', () => {
81
+ expect(trackStartEdge('horizontal', 'ltr', false)).toBe('left');
82
+ expect(trackStartEdge('horizontal', 'rtl', false)).toBe('right');
83
+ });
84
+
85
+ test('inverting a horizontal track swaps its start edge', () => {
86
+ expect(trackStartEdge('horizontal', 'ltr', true)).toBe('right');
87
+ expect(trackStartEdge('horizontal', 'rtl', true)).toBe('left');
88
+ });
89
+
90
+ test('a vertical track starts at the bottom, or the top when inverted', () => {
91
+ expect(trackStartEdge('vertical', 'ltr', false)).toBe('bottom');
92
+ expect(trackStartEdge('vertical', 'ltr', true)).toBe('top');
93
+ });
94
+ });
@@ -0,0 +1,96 @@
1
+ import type { UiSliderProps } from './types';
2
+
3
+ /** The track edge the lowest value sits at. */
4
+ export type TrackStartEdge = 'left' | 'right' | 'top' | 'bottom';
5
+
6
+ /**
7
+ * Where each mark sits along the track, as a percentage from the start edge:
8
+ * one every `interval` from `min`, and one at `max`.
9
+ * @param min Lowest value of the range.
10
+ * @param max Highest value of the range.
11
+ * @param interval Gap between two marks, in the slider's own units.
12
+ * @returns One percentage per mark, or none when the range or interval cannot
13
+ * be drawn.
14
+ */
15
+ export function stepMarkPercents(
16
+ min: number,
17
+ max: number,
18
+ interval: number,
19
+ ): number[] {
20
+ const range = max - min;
21
+ if (interval <= 0 || range <= 0) return [];
22
+ // The small tolerance keeps a fractional interval such as 0.1 from losing a
23
+ // mark to floating-point rounding.
24
+ const intervalCount = Math.floor(range / interval + 1e-9);
25
+ const percents = Array.from({ length: intervalCount + 1 }, (_, index) =>
26
+ // Rounding drops floating-point noise such as 30.000000000000004.
27
+ Number(((index * interval * 100) / range).toFixed(6)),
28
+ );
29
+ // The handle can always reach max, even when the interval does not divide
30
+ // the range: a step past the last mark is clamped to it.
31
+ return percents.at(-1) === 100 ? percents : [...percents, 100];
32
+ }
33
+
34
+ /**
35
+ * The gap between dots: the one the caller asked for, unless it would put the
36
+ * dots closer than a hundredth of the range, where they would run together and
37
+ * could number in the millions. Then the default gap is used instead.
38
+ * @param min Lowest value of the range.
39
+ * @param max Highest value of the range.
40
+ * @param step The slider's stepping interval.
41
+ * @param requested The gap the caller set, if any.
42
+ * @returns The gap between two dots, in the slider's own units.
43
+ */
44
+ export function stepsIntervalOrDefault(
45
+ min: number,
46
+ max: number,
47
+ step: number,
48
+ requested?: number,
49
+ ): number {
50
+ const finestInterval = (max - min) / 100;
51
+ // Relative, so the tolerance never outweighs the limit on a tiny range.
52
+ return requested !== undefined && requested >= finestInterval * (1 - 1e-9)
53
+ ? requested
54
+ : defaultStepsInterval(min, max, step);
55
+ }
56
+
57
+ /**
58
+ * The gap between dots when the caller sets none: every step, but no closer
59
+ * together than a tenth of the range, so a fine slider gets about 11 dots.
60
+ * The gap stays a whole number of steps, so every dot is a reachable value.
61
+ * @param min Lowest value of the range.
62
+ * @param max Highest value of the range.
63
+ * @param step The slider's stepping interval.
64
+ * @returns The gap between two dots, in the slider's own units.
65
+ */
66
+ export function defaultStepsInterval(
67
+ min: number,
68
+ max: number,
69
+ step: number,
70
+ ): number {
71
+ const tenth = (max - min) / 10;
72
+ if (step <= 0 || step >= tenth) return step;
73
+ // The tolerance keeps 0.1 / 0.01 from rounding up to 11 steps.
74
+ const stepsPerDot = Math.ceil(tenth / step - 1e-9);
75
+ return Number((stepsPerDot * step).toFixed(10));
76
+ }
77
+
78
+ /**
79
+ * The edge the track starts from. reka-ui works this out for the handle but
80
+ * does not export it, so this follows the same rule as its `SliderHorizontal`
81
+ * and `SliderVertical`.
82
+ * @param orientation Slider orientation.
83
+ * @param dir Reading direction, already resolved as reka-ui's `useDirection`
84
+ * resolves it.
85
+ * @param inverted Whether the slider is visually inverted.
86
+ * @returns The edge the lowest value sits at.
87
+ */
88
+ export function trackStartEdge(
89
+ orientation: NonNullable<UiSliderProps['orientation']>,
90
+ dir: NonNullable<UiSliderProps['dir']>,
91
+ inverted: boolean,
92
+ ): TrackStartEdge {
93
+ if (orientation === 'vertical') return inverted ? 'top' : 'bottom';
94
+ const startsLeft = (dir === 'ltr') !== inverted;
95
+ return startsLeft ? 'left' : 'right';
96
+ }
@@ -85,6 +85,38 @@ export interface UiSliderProps {
85
85
  * @default false
86
86
  */
87
87
  required?: boolean;
88
+
89
+ /**
90
+ * Shows each handle's current value in text, above the handle (beside it
91
+ * when vertical), moving with it while dragging. The text is hidden from
92
+ * screen readers, which read the value from the handle itself. A vertical
93
+ * slider reserves no room beside itself, so leave space for the text there.
94
+ * @default false
95
+ */
96
+ showValue?: boolean;
97
+
98
+ /**
99
+ * Turns a value into text, e.g. `(value) => \`${value}%\``. Used for the text
100
+ * `showValue` shows, and announced by screen readers as the handle's value
101
+ * (`aria-valuetext`). Without it the plain number is used.
102
+ */
103
+ formatValue?: (value: number) => string;
104
+
105
+ /**
106
+ * Shows a dot on the track for every value the handle can reach, but no
107
+ * closer together than a tenth of the range, plus one at `max`. Set
108
+ * `stepsInterval` to choose the gap yourself.
109
+ * @default false
110
+ */
111
+ showSteps?: boolean;
112
+
113
+ /**
114
+ * The gap between two dots drawn by `showSteps`, in the slider's own units.
115
+ * A gap smaller than a hundredth of the range falls back to the default.
116
+ * @default every `step`, but no closer than a tenth of the range: a 0 to 100
117
+ * slider in steps of 1 gets a dot every 10
118
+ */
119
+ stepsInterval?: number;
88
120
  }
89
121
 
90
122
  export interface UiSliderEmits {
@@ -12,11 +12,15 @@ import {
12
12
  import { cn } from '@/lib/utils';
13
13
 
14
14
  const props = defineProps<
15
- SliderRootProps & { class?: HTMLAttributes['class'] }
15
+ SliderRootProps & {
16
+ class?: HTMLAttributes['class'];
17
+ /** Text a screen reader announces for a handle's value, as `aria-valuetext`. */
18
+ thumbValueText?: (value: number) => string;
19
+ }
16
20
  >();
17
21
  const emits = defineEmits<SliderRootEmits>();
18
22
 
19
- const delegatedProps = reactiveOmit(props, 'class');
23
+ const delegatedProps = reactiveOmit(props, 'class', 'thumbValueText');
20
24
 
21
25
  const forwarded = useForwardPropsEmits(delegatedProps, emits);
22
26
  </script>
@@ -27,7 +31,7 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
27
31
  data-slot="slider"
28
32
  :class="
29
33
  cn(
30
- 'relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col',
34
+ 'relative flex w-full touch-none items-center select-none [--slider-thumb-size:1rem] data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col',
31
35
  props.class,
32
36
  )
33
37
  "
@@ -43,12 +47,18 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
43
47
  />
44
48
  </SliderTrack>
45
49
 
50
+ <!-- Outside the track, which clips what it holds. -->
51
+ <slot name="track-overlay" />
52
+
46
53
  <SliderThumb
47
- v-for="(_, key) in modelValue"
54
+ v-for="(thumbValue, key) in modelValue"
48
55
  :key="key"
49
56
  data-slot="slider-thumb"
50
57
  :aria-label="(modelValue?.length ?? 0) > 1 ? `Value ${key + 1}` : 'Value'"
51
- class="bg-white border-accent-default ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
52
- />
58
+ :aria-valuetext="props.thumbValueText?.(thumbValue)"
59
+ class="bg-white border-accent-default ring-ring/50 block size-[var(--slider-thumb-size)] shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
60
+ >
61
+ <slot name="thumb" :value="thumbValue" />
62
+ </SliderThumb>
53
63
  </SliderRoot>
54
64
  </template>
@@ -174,18 +174,18 @@ export const Default: Story = {
174
174
  await step(
175
175
  'screen-reader: every link is a named menu item (WCAG 4.1.2)',
176
176
  async () => {
177
- await expect(
178
- body.getByRole('menuitem', { name: 'Account settings' }),
179
- ).toBeVisible();
180
- await expect(
181
- body.getByRole('menuitem', { name: 'Privacy policy' }),
182
- ).toBeVisible();
183
- await expect(
184
- body.getByRole('menuitem', { name: 'Terms and conditions' }),
185
- ).toBeVisible();
186
- await expect(
187
- body.getByRole('menuitem', { name: 'Sign out' }),
188
- ).toBeVisible();
177
+ // Items can still be hidden for a frame after the menu itself is
178
+ // visible while the card opens.
179
+ for (const name of [
180
+ 'Account settings',
181
+ 'Privacy policy',
182
+ 'Terms and conditions',
183
+ 'Sign out',
184
+ ]) {
185
+ await waitFor(async () => {
186
+ await expect(body.getByRole('menuitem', { name })).toBeVisible();
187
+ });
188
+ }
189
189
  },
190
190
  );
191
191