From c2025a5eac5e61d6113b2194e64029ad096e9c10 Mon Sep 17 00:00:00 2001 From: Jiwen Bai <56228105@qq.com> Date: Tue, 3 Aug 2021 11:19:41 +0800 Subject: [PATCH 1/4] fix(select): filter break --- src/_internal/selection/src/Selection.tsx | 2 ++ src/select/src/Select.tsx | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/_internal/selection/src/Selection.tsx b/src/_internal/selection/src/Selection.tsx index 547e404de7d..759ae9dad22 100644 --- a/src/_internal/selection/src/Selection.tsx +++ b/src/_internal/selection/src/Selection.tsx @@ -82,6 +82,7 @@ export default defineComponent({ onKeyup: Function as PropType<(e: KeyboardEvent) => void>, onKeydown: Function as PropType<(e: KeyboardEvent) => void>, onClick: Function as PropType<(e: MouseEvent) => void>, + onMousedown: Function as PropType<(e: MouseEvent) => void>, onBlur: Function as PropType<(e: FocusEvent) => void>, onFocus: Function as PropType<(e: FocusEvent) => void>, onDeleteOption: Function, @@ -209,6 +210,7 @@ export default defineComponent({ hoverRef.value = false } function handleMouseDown (e: MouseEvent): void { + props.onMousedown?.(e) if (!props.active || !props.filterable) return if (e.target === patternInputRef.value) return e.preventDefault() diff --git a/src/select/src/Select.tsx b/src/select/src/Select.tsx index 53033cfb8ae..96965e20980 100644 --- a/src/select/src/Select.tsx +++ b/src/select/src/Select.tsx @@ -713,7 +713,7 @@ export default defineComponent({ } loading={this.loading} focused={this.focused} - onClick={this.handleTriggerClick} + onMousedown={this.handleTriggerClick} onDeleteOption={this.handleToggleOption} onPatternInput={this.handlePatternInput} onClear={this.handleClear} From 4904e1f3759f9301a359e2b288da455d4da37ad0 Mon Sep 17 00:00:00 2001 From: Jiwen Bai <56228105@qq.com> Date: Tue, 3 Aug 2021 11:40:43 +0800 Subject: [PATCH 2/4] changelog update --- CHANGELOG.en-US.md | 6 ++++++ CHANGELOG.zh-CN.md | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 98431af7bcb..f3e8d48e50b 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -1,5 +1,11 @@ # CHANGELOG +## Pending + +### Fixes + +- Fix `n-select` filterable select breaks, closes [#510](https://github.com/TuSimple/naive-ui/issues/510). + ## 2.16.0 (2021-08-02) ### Breaking Changes diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 8ed4c55680d..069f4d31189 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -1,5 +1,11 @@ # CHANGELOG +## Pending + +### Fixes + +- 修复 `n-select` 可过滤的选择器失效,关闭 [#510](https://github.com/TuSimple/naive-ui/issues/510) + ## 2.16.0 (2021-08-02) ### Breaking Changes From 0f708394b93447912abe765f37edc4f16a5f7bd7 Mon Sep 17 00:00:00 2001 From: Jiwen Bai <56228105@qq.com> Date: Thu, 5 Aug 2021 19:15:36 +0800 Subject: [PATCH 3/4] fix(select): use another way to solve this problem --- src/_internal/selection/src/Selection.tsx | 2 -- src/select/src/Select.tsx | 10 +++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/_internal/selection/src/Selection.tsx b/src/_internal/selection/src/Selection.tsx index 759ae9dad22..547e404de7d 100644 --- a/src/_internal/selection/src/Selection.tsx +++ b/src/_internal/selection/src/Selection.tsx @@ -82,7 +82,6 @@ export default defineComponent({ onKeyup: Function as PropType<(e: KeyboardEvent) => void>, onKeydown: Function as PropType<(e: KeyboardEvent) => void>, onClick: Function as PropType<(e: MouseEvent) => void>, - onMousedown: Function as PropType<(e: MouseEvent) => void>, onBlur: Function as PropType<(e: FocusEvent) => void>, onFocus: Function as PropType<(e: FocusEvent) => void>, onDeleteOption: Function, @@ -210,7 +209,6 @@ export default defineComponent({ hoverRef.value = false } function handleMouseDown (e: MouseEvent): void { - props.onMousedown?.(e) if (!props.active || !props.filterable) return if (e.target === patternInputRef.value) return e.preventDefault() diff --git a/src/select/src/Select.tsx b/src/select/src/Select.tsx index 96965e20980..56cd170f1d9 100644 --- a/src/select/src/Select.tsx +++ b/src/select/src/Select.tsx @@ -509,6 +509,14 @@ export default defineComponent({ ) } function handlePatternInput (e: InputEvent): void { + if (!mergedShowRef.value) { + openMenu() + } else { + if (!props.filterable) { + // already focused, don't need to return focus + closeMenu() + } + } const { value } = e.target as unknown as HTMLInputElement patternRef.value = value const { tag, remote } = props @@ -713,7 +721,7 @@ export default defineComponent({ } loading={this.loading} focused={this.focused} - onMousedown={this.handleTriggerClick} + onClick={this.handleTriggerClick} onDeleteOption={this.handleToggleOption} onPatternInput={this.handlePatternInput} onClear={this.handleClear} From ff08aad21d479cd49752c601f3953f6240272179 Mon Sep 17 00:00:00 2001 From: Jiwen Bai <56228105@qq.com> Date: Fri, 6 Aug 2021 10:48:21 +0800 Subject: [PATCH 4/4] fix(select): optimization --- src/select/src/Select.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/select/src/Select.tsx b/src/select/src/Select.tsx index 56cd170f1d9..8483a3c1efd 100644 --- a/src/select/src/Select.tsx +++ b/src/select/src/Select.tsx @@ -511,11 +511,6 @@ export default defineComponent({ function handlePatternInput (e: InputEvent): void { if (!mergedShowRef.value) { openMenu() - } else { - if (!props.filterable) { - // already focused, don't need to return focus - closeMenu() - } } const { value } = e.target as unknown as HTMLInputElement patternRef.value = value