Skip to content

Commit

Permalink
fix: avoid blocking first input event in IE when it shouldn't (vuejs#…
Browse files Browse the repository at this point in the history
…9297)

- the original bug in vuejs#7138 only happens for `<textarea>`
- the bug doesn't happen if placeholder has empty value

fix vuejs#9042, fix vuejs#9383
  • Loading branch information
nciont authored and Lostlover committed Dec 10, 2019
1 parent 53c4e19 commit 133d792
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/platforms/web/runtime/modules/attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ function baseSetAttr (el, key, value) {
/* istanbul ignore if */
if (
isIE && !isIE9 &&
(el.tagName === 'TEXTAREA' || el.tagName === 'INPUT') &&
key === 'placeholder' && !el.__ieph
el.tagName === 'TEXTAREA' &&
key === 'placeholder' && value !== '' && !el.__ieph
) {
const blocker = e => {
e.stopImmediatePropagation()
Expand Down
18 changes: 17 additions & 1 deletion test/unit/features/directives/model-text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ describe('Directive v-model text', () => {
})
}

// #7138
if (isIE && !isIE9) {
// #7138
it('should not fire input on initial render of textarea with placeholder in IE10/11', done => {
const el = document.createElement('div')
document.body.appendChild(el)
Expand All @@ -452,5 +452,21 @@ describe('Directive v-model text', () => {
done()
}, 17)
})

// #9042
it('should not block the first input event when placeholder is empty', done => {
const el = document.createElement('div')
document.body.appendChild(el)
const vm = new Vue({
el,
data: { evtCount: 0 },
template: `<textarea placeholder="" @input="evtCount++"></textarea>`,
})
triggerEvent(vm.$el, 'input')
setTimeout(() => {
expect(vm.evtCount).toBe(1)
done()
}, 17)
})
}
})

0 comments on commit 133d792

Please sign in to comment.