Skip to content

Commit 8e9787d

Browse files
committed
💄 Improve accessibility and visual coherence of RangeSlider
1 parent 3679d14 commit 8e9787d

File tree

4 files changed

+52
-14
lines changed

4 files changed

+52
-14
lines changed

src/components/RangeSlider/RangeSlider.astro

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,8 @@ const labelStyle = updateLabels ? `min-width:${minLabelWidth};` : null
138138
}
139139

140140
const updateRange = ({ range, minValue, maxValue, min, max }: RangeParams) => {
141-
const minAdjust = minValue > (max / 2) ? -1 : 1
142-
const maxAdjust = maxValue < (max / 2) ? 1 : -1
143-
144-
range.style.left = `${interpolate(minValue + minAdjust, [min, max], [0, 100])}%`
145-
range.style.right = `${interpolate(maxValue + maxAdjust, [min, max], [100, 0])}%`
141+
range.style.left = `${interpolate(minValue, [min, max], [0, 100])}%`
142+
range.style.right = `${interpolate(maxValue, [min, max], [100, 0])}%`
146143
}
147144

148145
const updateLabels = (wrapper: HTMLDivElement, minValue: number, maxValue: number) => {

src/components/RangeSlider/RangeSlider.svelte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@
4545
let dynamicMinLabel = $state(minLabel)
4646
let dynamicMaxLabel = $state(maxLabel)
4747
48-
const minAdjust = $derived(minValue > (max / 2) ? -1 : 1)
49-
const maxAdjust = $derived(maxValue < (max / 2) ? 1 : -1)
50-
const rangeLeftPercent = $derived(interpolate((minValue || min) + minAdjust, [min, max], [0, 100]))
51-
const rangeRightPercent = $derived(interpolate((maxValue || max) + maxAdjust, [min, max], [100, 0]))
48+
const rangeLeftPercent = $derived(interpolate((minValue || min), [min, max], [0, 100]))
49+
const rangeRightPercent = $derived(interpolate((maxValue || max), [min, max], [100, 0]))
5250
5351
const updateDynamicLabels = (minValue: number, maxValue: number) => {
5452
if (dynamicMinLabel && dynamicMaxLabel) {

src/components/RangeSlider/RangeSlider.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,8 @@ const RangeSlider = ({
116116
}
117117

118118
useEffect(() => {
119-
const minAdjust = minValue > (max / 2) ? -1 : 1
120-
const maxAdjust = maxValue < (max / 2) ? 1 : -1
121-
122-
rangeLeftPercent.current = interpolate((minValue || min) + minAdjust, [min, max], [0, 100])
123-
rangeRightPercent.current = interpolate((maxValue || max) + maxAdjust, [min, max], [100, 0])
119+
rangeLeftPercent.current = interpolate((minValue || min), [min, max], [0, 100])
120+
rangeRightPercent.current = interpolate((maxValue || max), [min, max], [100, 0])
124121
}, [minValue, maxValue])
125122

126123
return (

src/components/RangeSlider/rangeslider.module.scss

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ body {
4343
@include position(absolute);
4444
@include background(var(--w-range-slider-color));
4545
@include size('h100%');
46+
@include border-radius();
4647

4748
&[data-disabled] {
4849
@include background(primary-30);
@@ -60,6 +61,18 @@ body {
6061
appearance: none;
6162
pointer-events: none;
6263

64+
&:focus-visible {
65+
outline: none;
66+
67+
&::-webkit-slider-thumb {
68+
@include border(info);
69+
}
70+
71+
&::-moz-range-thumb {
72+
@include border(info);
73+
}
74+
}
75+
6376
&[disabled]::-webkit-slider-thumb {
6477
@include background(primary-50);
6578
@include border(primary-30);
@@ -71,6 +84,39 @@ body {
7184
@include border(primary-30);
7285
cursor: no-drop;
7386
}
87+
88+
&[data-min]::-webkit-slider-thumb {
89+
box-shadow: 3px 0 0 3px var(--w-range-slider-color);
90+
}
91+
92+
&[data-max]::-webkit-slider-thumb {
93+
box-shadow: -3px 0 0 3px var(--w-range-slider-color);
94+
}
95+
96+
&[data-min]::-moz-range-thumb {
97+
box-shadow: 3px 0 0 3px var(--w-range-slider-color);
98+
}
99+
100+
&[data-max]::-moz-range-thumb {
101+
box-shadow: -3px 0 0 3px var(--w-range-slider-color);
102+
}
103+
104+
105+
&[disabled][data-min]::-webkit-slider-thumb {
106+
box-shadow: 3px 0 0 3px var(--w-color-primary-30);
107+
}
108+
109+
&[disabled][data-max]::-webkit-slider-thumb {
110+
box-shadow: -3px 0 0 3px var(--w-color-primary-30);
111+
}
112+
113+
&[disabled][data-min]::-moz-range-thumb {
114+
box-shadow: 3px 0 0 3px var(--w-color-primary-30);
115+
}
116+
117+
&[disabled][data-max]::-moz-range-thumb {
118+
box-shadow: -3px 0 0 3px var(--w-color-primary-30);
119+
}
74120
}
75121

76122
.input::-webkit-slider-thumb {

0 commit comments

Comments
 (0)