Skip to content

Commit abaf0f2

Browse files
committed
feat: allow range picker switch with doubleClick
1 parent 723bb47 commit abaf0f2

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

components/vc-picker/PanelContext.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export type PanelContextProps = {
2323

2424
/** Only used for TimePicker and this is a deprecated prop */
2525
defaultOpenValue?: Ref<any>;
26+
27+
/** Double click state for RangePicker */
28+
isDoubleClickRef?: Ref<boolean>;
2629
};
2730

2831
const PanelContextKey: InjectionKey<PanelContextProps> = Symbol('PanelContextProps');

components/vc-picker/RangePicker.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ function RangerPicker<DateType>() {
263263
const needConfirmButton = computed(
264264
() => (props.picker === 'date' && !!props.showTime) || props.picker === 'time',
265265
);
266+
267+
const isDoubleClickRef = ref(false);
266268
const presets = computed(() => props.presets);
267269
const ranges = computed(() => props.ranges);
268270
const presetList = usePresets(presets, ranges);
@@ -970,10 +972,30 @@ function RangerPicker<DateType>() {
970972

971973
const onContextSelect = (date: DateType, type: 'key' | 'mouse' | 'submit') => {
972974
const values = updateValues(selectedValue.value, date, mergedActivePickerIndex.value);
975+
const currentIndex = mergedActivePickerIndex.value;
976+
const isDoubleClick = isDoubleClickRef.value;
977+
const shouldSwitch = type === 'mouse' && needConfirmButton.value && isDoubleClick;
978+
979+
// Reset double click state
980+
isDoubleClickRef.value = false;
973981

974-
if (type === 'submit' || (type !== 'key' && !needConfirmButton.value)) {
982+
if (type === 'submit' || (type !== 'key' && !needConfirmButton.value) || shouldSwitch) {
975983
// triggerChange will also update selected values
976984
triggerChange(values, mergedActivePickerIndex.value);
985+
986+
// If double click, switch to next input
987+
// But check if both inputs are complete, if so don't switch to avoid animation before popup closes
988+
if (shouldSwitch) {
989+
const startValue = getValue(values, 0);
990+
const endValue = getValue(values, 1);
991+
const bothValuesComplete = startValue && endValue;
992+
993+
if (!bothValuesComplete) {
994+
const nextIndex = ((currentIndex + 1) % 2) as 0 | 1;
995+
setMergedActivePickerIndex(nextIndex);
996+
}
997+
}
998+
977999
// clear hover value style
9781000
if (mergedActivePickerIndex.value === 0) {
9791001
onStartLeave();
@@ -993,6 +1015,7 @@ function RangerPicker<DateType>() {
9931015
hideRanges: computed(() => true),
9941016
onSelect: onContextSelect,
9951017
open: mergedOpen,
1018+
isDoubleClickRef,
9961019
});
9971020

9981021
return () => {

components/vc-picker/panels/PanelBody.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function PanelBody<DateType>(_props: PanelBodyProps<DateType>) {
4949
titleCell,
5050
headerCells,
5151
} = useMergeProps(_props);
52-
const { onDateMouseenter, onDateMouseleave, mode } = useInjectPanel();
52+
const { onDateMouseenter, onDateMouseleave, mode, isDoubleClickRef } = useInjectPanel();
5353

5454
const cellPrefixCls = `${prefixCls}-cell`;
5555

@@ -99,6 +99,14 @@ function PanelBody<DateType>(_props: PanelBodyProps<DateType>) {
9999
onSelect(currentDate);
100100
}
101101
}}
102+
onDblclick={e => {
103+
e.stopPropagation();
104+
if (!disabled && isDoubleClickRef) {
105+
// 设置双击状态
106+
isDoubleClickRef.value = true;
107+
onSelect(currentDate);
108+
}
109+
}}
102110
onMouseenter={() => {
103111
if (!disabled && onDateMouseenter) {
104112
onDateMouseenter(currentDate);

0 commit comments

Comments
 (0)