Skip to content

Commit d681e76

Browse files
authored
Merge pull request #1362 from hiendv/fix-disabled-attr
fix: whitelist tags to be ignored with `disabled` attribute
2 parents 0a72913 + 7f35e66 commit d681e76

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

packages/test-utils/src/wrapper.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,25 @@ export default class Wrapper implements BaseWrapper {
574574
)
575575
}
576576

577-
// Don't fire event on a disabled element
578-
if (this.attributes().disabled) {
577+
/**
578+
* Avoids firing events on specific disabled elements
579+
* See more: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled
580+
*/
581+
582+
const supportedTags = [
583+
'BUTTON',
584+
'COMMAND',
585+
'FIELDSET',
586+
'KEYGEN',
587+
'OPTGROUP',
588+
'OPTION',
589+
'SELECT',
590+
'TEXTAREA',
591+
'INPUT'
592+
]
593+
const tagName = this.element.tagName
594+
595+
if (this.attributes().disabled && supportedTags.indexOf(tagName) > -1) {
579596
return
580597
}
581598

test/specs/wrapper/trigger.spec.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,47 @@ describeWithShallowAndMount('trigger', mountingMethod => {
120120
expect(stub).calledWith(123)
121121
})
122122

123-
it('does not fire on disabled elements', () => {
123+
it('does not fire on valid disabled elements', () => {
124124
const clickHandler = sandbox.stub()
125-
const TestComponent = {
126-
template: '<button disabled @click="clickHandler"/>',
125+
const ButtonComponent = {
126+
template: '<button disabled @click="clickHandler">Button</button>',
127127
props: ['clickHandler']
128128
}
129-
const wrapper = mountingMethod(TestComponent, {
129+
const buttonWrapper = mountingMethod(ButtonComponent, {
130130
propsData: {
131131
clickHandler
132132
}
133133
})
134-
wrapper.trigger('click')
134+
buttonWrapper.trigger('click')
135135
expect(clickHandler.called).to.equal(false)
136+
137+
const changeHandler = sandbox.stub()
138+
const InputComponent = {
139+
template: '<input disabled @change="changeHandler"/>',
140+
props: ['changeHandler']
141+
}
142+
const inputWrapper = mountingMethod(InputComponent, {
143+
propsData: {
144+
changeHandler
145+
}
146+
})
147+
inputWrapper.trigger('change')
148+
expect(changeHandler.called).to.equal(false)
149+
})
150+
151+
it('fires on invalid disabled elements', () => {
152+
const clickHandler = sandbox.stub()
153+
const LinkComponent = {
154+
template: '<a disabled href="#" @click="clickHandler">Link</a>',
155+
props: ['clickHandler']
156+
}
157+
const linkWrapper = mountingMethod(LinkComponent, {
158+
propsData: {
159+
clickHandler
160+
}
161+
})
162+
linkWrapper.trigger('click')
163+
expect(clickHandler.called).to.equal(true)
136164
})
137165

138166
it('handles .prevent', () => {

0 commit comments

Comments
 (0)