Skip to content

Commit 9b516e5

Browse files
committed
fix: whitelist tags to be ignored with disabled attribute
1 parent 3115396 commit 9b516e5

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,21 @@ describeWithShallowAndMount('trigger', mountingMethod => {
123123
it('does not fire on disabled elements', () => {
124124
const clickHandler = sandbox.stub()
125125
const TestComponent = {
126-
template: '<button disabled @click="clickHandler"/>',
126+
template:
127+
'<div><button disabled @click="clickHandler"/><a href="#" disabled @click="clickHandler"/></div>',
127128
props: ['clickHandler']
128129
}
129130
const wrapper = mountingMethod(TestComponent, {
130131
propsData: {
131132
clickHandler
132133
}
133134
})
134-
wrapper.trigger('click')
135+
136+
wrapper.find('button').trigger('click')
135137
expect(clickHandler.called).to.equal(false)
138+
139+
wrapper.find('a').trigger('click')
140+
expect(clickHandler.called).to.equal(true)
136141
})
137142

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

0 commit comments

Comments
 (0)