Skip to content
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

fix: chinese input method should not trigger input event #297

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions src/components/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
},

onInput(evt) {
if (this.isOnComposition) return
const { value } = evt.target

this.value = value
Expand All @@ -112,6 +113,16 @@
}
},

handleComposition(event) {
if (event.type === 'compositionstart') {
this.isOnComposition = true
}
if (event.type === 'compositionend') {
this.isOnComposition = false
this.onInput(event)
}
},

// 用 keyUp 事件存在一个问题,删除输入框最后一个字符也会导致取消选中最后一项
onKeyDown(evt) {
const { instance } = this
Expand Down Expand Up @@ -262,6 +273,8 @@
onFocus={this.onFocus}
onInput={this.onInput}
onBlur={this.onBlur}
onCompositionstart={this.handleComposition}
onCompositionend={this.handleComposition}
onKeydown={this.onKeyDown}
onMousedown={this.onMouseDown}
/>
Expand Down
1 change: 1 addition & 0 deletions src/mixins/treeselectMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ export default {
isFocused: false,
// User entered search query - value of the input.
searchQuery: '',
isOnComposition: false,
},

menu: {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/specs/SearchInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,15 @@ describe('Search Input', () => {
prevWidth = width
}
})

it('when input letter, compositionstart should not be triggered', async () => {
const wrapper = mount(Treeselect, {
propsData: {
options: [],
},
})
const text = 'hello world'
await typeSearchText(wrapper, text)
expect(wrapper.vm.trigger.isOnComposition).toBe(false)
})
})