Skip to content

Commit

Permalink
fix: avoid blocking first input event in IE when it shouldn't (#9297)
Browse files Browse the repository at this point in the history
- the original bug in #7138 only happens for `<textarea>`
- the bug doesn't happen if placeholder has empty value

fix #9042, fix #9383
  • Loading branch information
nciont authored and yyx990803 committed Feb 4, 2019
1 parent 55bfb94 commit 0fb03b7
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 0fb03b7

Please sign in to comment.