8000 Update form-radio-check-group.js · bootstrap-vue/bootstrap-vue@1ff43ec · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ff43ec

Browse files
committed
Update form-radio-check-group.js
1 parent cabb899 commit 1ff43ec

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/mixins/form-radio-check-group.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SLOT_NAME_FIRST } from '../constants/slots'
44
import { htmlOrText } from '../utils/html'
55
import { looseEqual } from '../utils/loose-equal'
66
import { makeModelMixin } from '../utils/model'
7-
import { sortKeys } from '../utils/object'
7+
import { omit, pick, sortKeys } from '../utils/object'
88
import { makeProp, makePropsConfigurable } from '../utils/props'
99
import { BFormCheckbox } from '../components/form-checkbox/form-checkbox'
1010
import { BFormRadio } from '../components/form-radio/form-radio'
@@ -18,6 +18,9 @@ import { normalizeSlotMixin } from './normalize-slot'
1818

1919
// --- Constants ---
2020

21+
// Attributes to pass down to checks/radios instead of applying them to the group
22+
const PASS_DOWN_ATTRS = ['aria-describedby', 'aria-labelledby']
23+
2124
const {
2225
mixin: modelMixin,
2326
props: modelProps,
@@ -63,6 +66,7 @@ export const formRadioCheckGroupMixin = Vue.extend({
6366
formStateMixin,
6467
formCustomMixin
6568
],
69+
inheritAttrs: false,
6670
props,
6771
data() {
6872
return {
@@ -75,7 +79,7 @@ export const formRadioCheckGroupMixin = Vue.extend({
7579
},
7680 8000
groupName() {
7781
// Checks/Radios tied to the same model must have the same name,
78-
// especially for ARIA accessibility.
82+
// especially for ARIA accessibility
7983
return this.name || this.safeId()
8084
},
8185
groupClasses() {
@@ -111,6 +115,7 @@ export const formRadioCheckGroupMixin = Vue.extend({
111115
},
112116
render(h) {
113117
const { isRadioGroup } = this
118+
const attrs = pick(this.$attrs, PASS_DOWN_ATTRS)
114119
const optionComponent = isRadioGroup ? BFormRadio : BFormCheckbox
115120

116121
const $inputs = this.formOptions.map((option, index) => {
@@ -120,15 +125,16 @@ export const formRadioCheckGroupMixin = Vue.extend({
120125
optionComponent,
121126
{
122127
props: {
123-
id: this.safeId(key),
124-
value: option.value,
125128
// Individual radios or checks can be disabled in a group
126-
disabled: option.disabled || false
129+
disabled: option.disabled || false,
130+
id: this.safeId(key),
131+
value: option.value
127132
// We don't need to include these, since the input's will know they are inside here
128-
// name: this.groupName,
129133
// form: this.form || null,
134+
// name: this.groupName,
130135
// required: Boolean(this.name && this.required)
131136
},
137+
attrs,
132138
key
133139
},
134140
[h('span', { domProps: htmlOrText(option.html, option.text) })]
@@ -140,12 +146,13 @@ export const formRadioCheckGroupMixin = Vue.extend({
140146
{
141147
class: [this.groupClasses, 'bv-no-focus-ring'],
142148
attrs: {
149+
...omit(this.$attrs, PASS_DOWN_ATTRS),
150+
'aria-invalid': this.computedAriaInvalid,
151+
'aria-required': this.required ? 'true' : null,
143152
id: this.safeId(),
144153
role: isRadioGroup ? 'radiogroup' : 'group',
145154
// Add `tabindex="-1"` to allow group to be focused if needed by screen readers
146-
tabindex: '-1',
147-
'aria-required': this.required ? 'true' : null,
148-
'aria-invalid': this.computedAriaInvalid
155+
tabindex: '-1'
149156
}
150157
},
151158
[this.normalizeSlot(SLOT_NAME_FIRST), $inputs, this.normalizeSlot()]

0 commit comments

Comments
 (0)
0