Skip to content
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

Allow passing array to aria and ariaLabelledby for labeling multiple handles #89

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/Slider.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { defineComponent } from 'vue';

interface typePropFormat {
prefix?: string,
suffix?: string,
decimals?: string,
thousand?: string,
}
interface SliderProps {
modelValue?: any;
value?: any;
modelValue?: number | number[];
value?: number | number[];
id?: string;
disabled?: boolean;
min?: number;
Expand All @@ -11,15 +17,15 @@ interface SliderProps {
orientation?: 'horizontal' | 'vertical';
direction?: 'ltr' | 'rtl';
tooltips?: boolean;
options?: object;
options?: Record<string, any>;
merge?: number;
format?: any;
classes?: object;
format?: typePropFormat | ((v:number) => string | number);
classes?: Record<string, string>;
showTooltip?: 'always' | 'focus' | 'drag';
tooltipPosition?: null | 'top' | 'bottom' | 'left' | 'right';
lazy?: boolean;
ariaLabelledby?: string;
aria?: object;
ariaLabelledby?: string | string[];
aria?: Record<string, string> | Record<string, string>[];
}

declare class Slider implements ReturnType<typeof defineComponent> {
Expand Down
4 changes: 2 additions & 2 deletions src/Slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@
default: true,
},
ariaLabelledby: {
type: String,
type: [String, Array],
required: false,
default: undefined,
},
aria: {
required: false,
type: Object,
type: [Object, Array],
default: () => ({}),
},
},
Expand Down
36 changes: 31 additions & 5 deletions src/composables/useSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,38 @@ export default function useSlider (props, context, dependencies)
defaultOptions.connect = true
}

if ((ariaLabelledby && ariaLabelledby.value) || (aria && Object.keys(aria.value).length)) {
let handles = Array.isArray(value.value) ? value.value : [value.value]
// Check if aria / ariaLabelledby is provided
if ((ariaLabelledby && ariaLabelledby.value) || (aria && aria.value)) {
const handles = Array.isArray(value.value) ? value.value : [value.value];

// For each handle
defaultOptions.handleAttributes = handles.map((h, i) => {
const output = {};

// if aria provided
if (aria.value) {
if (Array.isArray(aria.value)) {
// If array is provided, assign the value respectively
Object.assign(output, aria.value[i]);
} else {
// Else assign the object
Object.assign(output, aria.value);
}
}

// if ariaLabelledby provided
if (ariaLabelledby.value) {
if (typeof ariaLabelledby.value === 'string') {
// if string is provided, assign the value in object format
Object.assign(output, { 'aria-labelledby': ariaLabelledby.value });
} else {
// Else if string array is provided, assign the value respectively
Object.assign(output, { 'aria-labelledby': ariaLabelledby.value[i] });
}
}

defaultOptions.handleAttributes = handles.map(h => (Object.assign({}, aria.value, ariaLabelledby && ariaLabelledby.value ? {
'aria-labelledby': ariaLabelledby.value,
}: {})))
return output;
});
}

if (format.value) {
Expand Down