Skip to content

fix: whitelist tags to be ignored with disabled attribute #1362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions packages/test-utils/src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,25 @@ export default class Wrapper implements BaseWrapper {
)
}

// Don't fire event on a disabled element
if (this.attributes().disabled) {
/**
* Avoids firing events on specific disabled elements
* See more: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled
*/

const supportedTags = [
'BUTTON',
'COMMAND',
'FIELDSET',
'KEYGEN',
'OPTGROUP',
'OPTION',
'SELECT',
'TEXTAREA',
'INPUT'
]
const tagName = this.element.tagName

if (this.attributes().disabled && supportedTags.indexOf(tagName) > -1) {
return
}

Expand Down
38 changes: 33 additions & 5 deletions test/specs/wrapper/trigger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,47 @@ describeWithShallowAndMount('trigger', mountingMethod => {
expect(stub).calledWith(123)
})

it('does not fire on disabled elements', () => {
it('does not fire on valid disabled elements', () => {
const clickHandler = sandbox.stub()
const TestComponent = {
template: '<button disabled @click="clickHandler"/>',
const ButtonComponent = {
template: '<button disabled @click="clickHandler">Button</button>',
props: ['clickHandler']
}
const wrapper = mountingMethod(TestComponent, {
const buttonWrapper = mountingMethod(ButtonComponent, {
propsData: {
clickHandler
}
})
wrapper.trigger('click')
buttonWrapper.trigger('click')
expect(clickHandler.called).to.equal(false)

const changeHandler = sandbox.stub()
const InputComponent = {
template: '<input disabled @change="changeHandler"/>',
props: ['changeHandler']
}
const inputWrapper = mountingMethod(InputComponent, {
propsData: {
changeHandler
}
})
inputWrapper.trigger('change')
expect(changeHandler.called).to.equal(false)
})

it('fires on invalid disabled elements', () => {
const clickHandler = sandbox.stub()
const LinkComponent = {
template: '<a disabled href="#" @click="clickHandler">Link</a>',
props: ['clickHandler']
}
const linkWrapper = mountingMethod(LinkComponent, {
propsData: {
clickHandler
}
})
linkWrapper.trigger('click')
expect(clickHandler.called).to.equal(true)
})

it('handles .prevent', () => {
Expand Down