|
35 | 35 | export let suffix = ""; |
36 | 36 | export let formatter = (v,i,p) => v; |
37 | 37 | export let handleFormatter = formatter; |
| 38 | + export let ariaLabels = []; |
38 | 39 |
|
39 | 40 | // stylistic props |
40 | 41 | export let precision = 2; |
|
86 | 87 | } |
87 | 88 | // set the valueLength for the next check |
88 | 89 | valueLength = values.length; |
| 90 | +
|
89 | 91 | }; |
90 | 92 |
|
| 93 | + $: { |
| 94 | + // set default aria labels if none provided, |
| 95 | + // and also update the aria labels if the values change |
| 96 | + if ( !ariaLabels.length ) { |
| 97 | + if ( range === true && values.length === 2 ) { |
| 98 | + ariaLabels[0] = `Minimum value in range from ${min} to ${max}`; |
| 99 | + ariaLabels[1] = `Maximum value in range from ${min} to ${max}`; |
| 100 | + } else { |
| 101 | + ariaLabels = values.map((v, i) => `Value ${i + 1} in range from ${min} to ${max}`); |
| 102 | + } |
| 103 | + } else if ( ariaLabels.length !== values.length ) { |
| 104 | + for ( let i = ariaLabels.length; i < values.length; i++ ) { |
| 105 | + ariaLabels[i] = `Value ${i + 1} in range from ${min} to ${max}`; |
| 106 | + } |
| 107 | + } |
| 108 | +
|
| 109 | + } |
| 110 | +
|
91 | 111 | /** |
92 | 112 | * take in a value, and then calculate that value's percentage |
93 | 113 | * of the overall range (min-max); |
|
810 | 830 | on:focus={sliderFocusHandle} |
811 | 831 | on:keydown={sliderKeydown} |
812 | 832 | style="{orientationStart}: {$springPositions[index]}%; z-index: {activeHandle === index ? 3 : 2};" |
| 833 | + aria-label={ariaLabels[index]} |
813 | 834 | aria-valuemin={range === true && index === 1 ? values[0] : min} |
814 | 835 | aria-valuemax={range === true && index === 0 ? values[1] : max} |
815 | 836 | aria-valuenow={value} |
|
0 commit comments