Skip to content

Commit 722f9db

Browse files
authored
feat(b-form-file, b-form-checkbox, b-form-radio): make input element inherit non-prop attributes (addresses #3752) (#3754)
1 parent f261987 commit 722f9db

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

src/components/form-checkbox/form-checkbox.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,20 @@ describe('form-checkbox', () => {
279279
wrapper.destroy()
280280
})
281281

282+
it('has custom attributes transferred to input element', async () => {
283+
const wrapper = mount(BFormCheckbox, {
284+
propsData: {
285+
id: 'foo',
286+
foo: 'bar'
287+
}
288+
})
289+
const input = wrapper.find('input')
290+
expect(input.attributes('foo')).toBeDefined()
291+
expect(input.attributes('foo')).toEqual('bar')
292+
293+
wrapper.destroy()
294+
})
295+
282296
it('default has class custom-control-inline when prop inline=true', async () => {
283297
const wrapper = mount(BFormCheckbox, {
284298
propsData: {

src/components/form-file/form-file.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const NAME = 'BFormFile'
1414
export const BFormFile = /*#__PURE__*/ Vue.extend({
1515
name: NAME,
1616
mixins: [idMixin, formMixin, formStateMixin, formCustomMixin, normalizeSlotMixin],
17+
inheritAttrs: false,
1718
model: {
1819
prop: 'value',
1920
event: 'input'
@@ -261,6 +262,7 @@ export const BFormFile = /*#__PURE__*/ Vue.extend({
261262
this.stateClass
262263
],
263264
attrs: {
265+
...this.$attrs,
264266
type: 'file',
265267
id: this.safeId(),
266268
name: this.name,

src/components/form-file/form-file.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ describe('form-file', () => {
135135
wrapper.destroy()
136136
})
137137

138+
it('default has custom attributes transferred input element', async () => {
139+
const wrapper = mount(BFormFile, {
140+
propsData: {
141+
id: 'foo',
142+
foo: 'bar'
143+
}
144+
})
145+
const input = wrapper.find('input')
146+
expect(input.attributes('foo')).toBeDefined()
147+
expect(input.attributes('foo')).toEqual('bar')
148+
149+
wrapper.destroy()
150+
})
151+
138152
it('default has class focus when input focused', async () => {
139153
const wrapper = mount(BFormFile, {
140154
propsData: {

src/components/form-radio/form-radio.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,20 @@ describe('form-radio', () => {
261261
wrapper.destroy()
262262
})
263263

264+
it('has custom attributes transferred to input element', async () => {
265+
const wrapper = mount(BFormRadio, {
266+
propsData: {
267+
id: 'foo',
268+
foo: 'bar'
269+
}
270+
})
271+
const input = wrapper.find('input')
272+
expect(input.attributes('foo')).toBeDefined()
273+
expect(input.attributes('foo')).toEqual('bar')
274+
275+
wrapper.destroy()
276+
})
277+
264278
it('default has class custom-control-inline when prop inline=true', async () => {
265279
const wrapper = mount(BFormRadio, {
266280
propsData: {

src/mixins/form-radio-check.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import normalizeSlotMixin from './normalize-slot'
33
// @vue/component
44
export default {
55
mixins: [normalizeSlotMixin],
6+
inheritAttrs: false,
67
model: {
78
prop: 'checked',
89
event: 'input'
@@ -198,6 +199,7 @@ export default {
198199
}
199200
],
200201
attrs: {
202+
...this.$attrs,
201203
id: this.safeId(),
202204
type: this.isRadio ? 'radio' : 'checkbox',
203205
name: this.getName,

0 commit comments

Comments
 (0)