Skip to content

Commit a6fa2d7

Browse files
committed
!444 feat(datePicker): 开启simple/range后点击快捷选项无需确认
* feat(datePicker): 开启simple/range后点击快捷选项无需确认
1 parent 85db1b6 commit a6fa2d7

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

packages/component/component/datePicker/__tests__/datePicker-range.test.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { mount } from "@vue/test-utils";
22
import { afterEach, describe, expect, test } from "vitest";
33
import { sleep } from "../../../test-utils";
44

5+
import LayDropdown from "../../dropdown/index.vue";
56
import LayDatePicker from "../index.vue";
67
import DateRangeComponent from "../component/DateRange.vue";
7-
import DateComponent from "../component/common/Date.vue";
8-
import Year from "../component/common/Year.vue";
9-
import Footer from "../component/common/Footer.vue";
8+
import Shortcuts from "../component/common/Shortcuts.vue";
9+
// import DateComponent from "../component/common/Date.vue";
10+
// import Year from "../component/common/Year.vue";
11+
// import Footer from "../component/common/Footer.vue";
1012
// import Month from "../component/common/Month.vue";
1113
import { nextTick } from "vue";
1214
import { dayjsToString } from "../util";
@@ -52,4 +54,36 @@ describe("LayDatePicker date type", () => {
5254
expect(parseInt(rightYear.text())).toBe(2024);
5355
expect(parseInt(rightMonth.text())).toBe(11);
5456
});
57+
58+
test("simple模式 点击快捷选项下拉关闭", async () => {
59+
const shortcuts = [
60+
{
61+
text: "两年",
62+
value: ["2024", "2025"],
63+
},
64+
];
65+
66+
const wrapper = mount(LayDatePicker, {
67+
props: {
68+
range: true,
69+
simple: true,
70+
modelValue: [],
71+
shortcuts,
72+
},
73+
});
74+
75+
await mockInputClick(wrapper);
76+
77+
const dropdownInstance1 = wrapper.findComponent(LayDropdown);
78+
expect((dropdownInstance1.vm as any).open).toBeTruthy();
79+
80+
const shortcut = wrapper.findComponent(Shortcuts);
81+
const lis = shortcut.findAll("li");
82+
expect(lis.length).toBe(1);
83+
84+
await (lis[0] as any).trigger("click");
85+
await sleep();
86+
const dropdownInstance2 = wrapper.findComponent(LayDropdown);
87+
expect((dropdownInstance2.vm as any).open).toBeFalsy();
88+
});
5589
});

packages/component/component/datePicker/component/DateRange.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ const handleChangeShortcut = (shortcuts: ShortcutsType) => {
258258
rightDate.value = shortcutsValues[1];
259259
startDate.value = shortcutsValues[0];
260260
endDate.value = shortcutsValues[1];
261+
262+
if (props.simple) handleConfirm();
261263
};
262264
263265
const handleConfirm = () => {

packages/component/component/datePicker/component/MonthRange.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ const handleChangeShortcut = (shortcuts: ShortcutsType) => {
129129
130130
startDate.value = shortcutsValues[0];
131131
endDate.value = shortcutsValues[1];
132+
133+
if (props.simple) handleConfirm();
132134
};
133135
134136
const handleConfirm = () => {

packages/component/component/datePicker/component/TimeRange.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const handleChangeShortcut = (shortcuts: ShortcutsType) => {
6464
6565
startDate.value = shortcutsValues[0];
6666
endDate.value = shortcutsValues[1];
67+
68+
if (props.simple) handleConfirm();
6769
};
6870
6971
const handleConfirm = () => {

packages/component/component/datePicker/component/YearRange.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ const handleChangeShortcut = (shortcuts: ShortcutsType) => {
103103
104104
startDate.value = shortcutsValues[0];
105105
endDate.value = shortcutsValues[1];
106+
107+
if (props.simple) handleConfirm();
106108
};
107109
108110
const handleConfirm = () => {

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