Skip to content

Commit a19d921

Browse files
committed
FOUR-23681:S2: Improve Behavior Aria Label RADIO / CHECKS
1 parent b9b5e6c commit a19d921

File tree

1 file changed

+61
-50
lines changed

1 file changed

+61
-50
lines changed
Lines changed: 61 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,102 @@
11
<template>
22
<form>
3-
<div :class="divClass" :key="getOptionValue(option)" v-for="(option, index) in options">
3+
<div v-for="(option, index) in options" :key="getOptionValue(option)" :class="divClass">
44
<input
5-
:class="inputClass"
6-
type="radio"
7-
v-uni-id="getOptionId(option, index)"
8-
:name="`${name}`"
9-
:value="emitObjects ? option : getOptionValue(option)"
10-
v-model="selected"
11-
v-bind="$attrs"
12-
:disabled="isReadOnly"
13-
:aria-label="getOptionAriaLabel(option)"
14-
>
15-
<label :class="labelClass" v-uni-for="getOptionId(option, index)">
16-
{{getOptionContent(option)}}
5+
v-model="selected"
6+
v-uni-id="getOptionId(option, index)"
7+
:class="inputClass"
8+
type="radio"
9+
:name="`${name}`"
10+
:value="emitObjects ? option : getOptionValue(option)"
11+
v-bind="$attrs"
12+
:disabled="isReadOnly"
13+
:aria-label="getOptionAriaLabel(option)"
14+
/>
15+
<label v-uni-for="getOptionId(option, index)" :class="labelClass">
16+
{{ getOptionContent(option) }}
1717
</label>
1818
</div>
1919
</form>
2020
</template>
2121

2222
<script>
23-
import {createUniqIdsMixin} from 'vue-uniq-ids'
24-
import ValidationMixin from '../mixins/validation'
23+
import { createUniqIdsMixin } from "vue-uniq-ids";
24+
import ValidationMixin from "../mixins/validation";
2525
2626
const uniqIdsMixin = createUniqIdsMixin();
2727
2828
export default {
29-
inheritAttrs: false,
3029
mixins: [uniqIdsMixin, ValidationMixin],
30+
inheritAttrs: false,
3131
props: [
32-
'value',
33-
'optionValue',
34-
'optionContent',
35-
'options',
36-
'error',
37-
'helper',
38-
'name',
39-
'controlClass',
40-
'emitObjects',
41-
'emitArray',
42-
'optionAriaLabel'
32+
"value",
33+
"optionValue",
34+
"optionContent",
35+
"options",
36+
"optionsExtra",
37+
"error",
38+
"helper",
39+
"name",
40+
"controlClass",
41+
"emitObjects",
42+
"emitArray",
43+
"optionAriaLabel"
4344
],
4445
data() {
4546
return {
46-
selected:[]
47-
}
48-
},
49-
mounted() {
50-
this.selected = this.value;
51-
},
52-
watch: {
53-
value(val) {
54-
this.selected = val;
55-
},
56-
selected() {
57-
this.$emit('input', this.selected);
58-
}
47+
selected: []
48+
};
5949
},
6050
computed: {
6151
divClass() {
62-
return this.toggle ? 'custom-control custom-radio' : 'form-check';
52+
return this.toggle ? "custom-control custom-radio" : "form-check";
6353
},
6454
labelClass() {
65-
return this.toggle ? 'custom-control-label' : 'form-check-label';
55+
return this.toggle ? "custom-control-label" : "form-check-label";
6656
},
6757
inputClass() {
6858
return [
69-
{[this.controlClass]: !!this.controlClass},
70-
{'is-invalid': (this.validator && this.validator.errorCount) || this.error},
71-
this.toggle ? 'custom-control-input' : 'form-check-input'
59+
{ [this.controlClass]: !!this.controlClass },
60+
{ "is-invalid": (this.validator && this.validator.errorCount) || this.error },
61+
this.toggle ? "custom-control-input" : "form-check-input"
7262
];
63+
}
64+
},
65+
watch: {
66+
value(val) {
67+
this.selected = val;
7368
},
69+
selected() {
70+
this.$emit("input", this.selected);
71+
}
72+
},
73+
mounted() {
74+
this.selected = this.value;
7475
},
7576
methods: {
7677
getOptionValue(option) {
77-
return option[this.optionValue || 'value'];
78+
return option[this.optionValue || "value"];
7879
},
7980
getOptionContent(option) {
80-
return option[this.optionContent || 'content'];
81+
return option[this.optionContent || "content"];
8182
},
8283
getOptionAriaLabel(option) {
83-
const ariaLabel = option[this.optionAriaLabel || "ariaLabel"];
84-
return (!ariaLabel || ariaLabel === "") ? this.getOptionContent(option) : ariaLabel;
84+
let ariaLabel = "";
85+
if (this.optionsExtra?.length) {
86+
const optionExtra = this.optionsExtra.find(
87+
(extra) => extra.hasOwnProperty(this.optionValue) && extra[this.optionValue] === option[this.optionValue]
88+
);
89+
if (optionExtra) {
90+
ariaLabel = optionExtra[this.optionAriaLabel || "ariaLabel"] ?? "";
91+
}
92+
} else {
93+
ariaLabel = option[this.optionAriaLabel || "ariaLabel"] ?? "";
94+
}
95+
return !ariaLabel || ariaLabel === "" ? this.getOptionContent(option) : ariaLabel;
8596
},
8697
getOptionId(option, index) {
8798
return `${this.name}-${this.getOptionValue(option)}-${index}`;
8899
}
89100
}
90-
}
101+
};
91102
</script>

0 commit comments

Comments
 (0)