Skip to content

Commit e623edc

Browse files
jevin98sleeprite
authored andcommitted
!470 fix(select): 当下拉弹窗隐藏,用户输入自动显示下拉弹窗
* fix(select): 当下拉弹窗隐藏,用户输入自动显示下拉弹窗
1 parent 4b35290 commit e623edc

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

packages/component/component/select/__tests__/select.test.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,56 @@ describe("LaySelect", () => {
243243
expect(tags1.length).toBe(0);
244244
expect(value1.value.length).toBe(0);
245245
});
246+
247+
test("输入内容,自动弹出下拉框", async () => {
248+
const teleportProps = { to: "body", disabled: true };
249+
250+
const value1 = ref([1]);
251+
252+
const wrapper = mount(
253+
{
254+
setup() {
255+
const options = [
256+
{ label: "学习", value: 1 },
257+
{ label: "复习", value: 2 },
258+
];
259+
260+
return () => (
261+
<LaySelect
262+
v-model={value1.value}
263+
options={options}
264+
multiple
265+
show-search
266+
teleportProps={teleportProps}
267+
></LaySelect>
268+
);
269+
},
270+
},
271+
{ attachTo: document.body }
272+
);
273+
274+
const inputComponent = wrapper.findComponent(".layui-tag-input");
275+
276+
await inputComponent.trigger("click");
277+
await nextTick();
278+
await sleep();
279+
280+
const tooltip1 = wrapper.find(".layui-popper");
281+
expect(tooltip1.exists()).toBeTruthy();
282+
expect(tooltip1.isVisible()).toBeTruthy();
283+
284+
await inputComponent.trigger("click");
285+
await nextTick();
286+
await sleep();
287+
expect(tooltip1.isVisible()).toBeFalsy();
288+
289+
const inputInstance = wrapper.find(
290+
".layui-tag-input .layui-tag-input-inner input"
291+
);
292+
await inputInstance.setValue("hello");
293+
294+
await nextTick();
295+
await sleep();
296+
expect(tooltip1.isVisible()).toBeTruthy();
297+
});
246298
});

packages/component/component/select/index.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const props = withDefaults(defineProps<SelectProps>(), {
7373
const { size } = useProps(props);
7474
7575
const slots = useSlots();
76-
const selectRef = ref();
76+
const selectRef = ref<typeof LayDropdown | null>(null);
7777
const searchValue = ref("");
7878
const singleValue = ref("");
7979
const multipleValue: Ref<any[]> = ref([]);
@@ -203,6 +203,11 @@ const handleSearch = (value: string) => {
203203
if (composing.value) return;
204204
emits("search", value);
205205
searchValue.value = value;
206+
207+
// 当拉下关闭 | 用户输入,弹出弹窗
208+
if (value && !openState.value) {
209+
selectRef.value && selectRef.value.show();
210+
}
206211
};
207212
208213
const handleClear = () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy