Skip to content

Commit 7fdd89c

Browse files
committed
add check for ariaLabels array, remove uneeded defaults
resolves #93
1 parent 6530136 commit 7fdd89c

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ prop | type | default | description
114114
**hoverable** | `Boolean` | `true` | Whether hover styles are enabled for both handles and pips/values
115115
**disabled** | `Boolean` | `false` | Determine if the slider is disabled, or enabled _(only disables interactions, and events)_
116116
**id** | `String` | `""` | Give the slider a unique ID for use in styling
117+
**ariaLabels** | `Array` | `[]` | Array of strings to use for the `aria-label` attribute on the handles.
117118
**formatter** | `Function` | `(v,i,p) => v` | A function to re-format values before they are displayed (`v = value, i = pip index, p = percent`)
118119
**handleFormatter** | `Function` | `formatter` | A function to re-format values on the handle/float before they are displayed. Defaults to the same function given to the `formatter` property (`v = value, i = handle index, p = percent`)
119120
**springValues** | `Object` | `{ stiffness: 0.15, damping: 0.4 }` | Svelte spring physics object to change the behaviour of the handle when moving

src/RangeSlider.svelte

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,11 @@
8888
// set the valueLength for the next check
8989
valueLength = values.length;
9090
91-
};
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-
}
91+
if ( values.length > 1 && !Array.isArray(ariaLabels) ) {
92+
console.warn( `'ariaLabels' prop should be an Array (https://github.com/simeydotme/svelte-range-slider-pips#slider-props)` );
93+
}
10894
109-
}
95+
};
11096
11197
/**
11298
* take in a value, and then calculate that value's percentage

test/src/App.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
<br><button on:click={()=>{ zeromin = 10; zeromax = 30; zero = [3,70]; }}>increase min/max</button> - {zero}
232232

233233
<h2>push & pop values</h2>
234-
<RangeSlider bind:values float pips all="label" {reversed} {hoverable} {disabled} />
234+
<RangeSlider bind:values float pips all="label" {reversed} {hoverable} {disabled} ariaLabels="x" />
235235
<button on:click={pushValues}>push</button>
236236
<button on:click={popValues}>pop</button>
237237
<br>({values})
@@ -255,7 +255,9 @@
255255
{decimals2}<br>
256256

257257
<h2>Aria Labels</h2>
258-
<RangeSlider ariaLabels={["a"]} {reversed} {hoverable} {disabled} />
258+
<RangeSlider ariaLabels="ab" values={[5,20]} {reversed} {hoverable} {disabled} />
259+
<RangeSlider ariaLabels="{6}" {reversed} {hoverable} {disabled} />
260+
<RangeSlider ariaLabels="{{}}" {reversed} {hoverable} {disabled} />
259261
<RangeSlider ariaLabels={["a", "b"]} values={[5,20]} {reversed} {hoverable} {disabled} />
260262
<RangeSlider ariaLabels={["a", "b"]} values={[5,20,40]} {reversed} {hoverable} {disabled} />
261263
<RangeSlider ariaLabels={["", "b"]} values={[5,20]} range {reversed} {hoverable} {disabled} />

0 commit comments

Comments
 (0)