Skip to content

Commit

Permalink
fix: Increase the priority of executing events in dateTime mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dujiaqi committed Sep 18, 2023
1 parent 8f802d2 commit 213d2c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {

const [inputProps, { focused, typing }] = usePickerInput({
blurToCancel: needConfirmButton,
changeOnBlur,
open: mergedOpen,
value: text,
triggerOpen,
Expand Down
15 changes: 8 additions & 7 deletions src/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {

const onInternalBlur: React.FocusEventHandler<HTMLInputElement> = (e) => {
if (delayOpen) {
if (changeOnBlur) {
const selectedIndexValue = getValue(selectedValue, mergedActivePickerIndex);

if (selectedIndexValue) {
triggerChange(selectedValue, mergedActivePickerIndex);
}
} else if (needConfirmButton) {
if (needConfirmButton) {
// when in dateTime mode, switching between two date input fields will trigger onCalendarChange.
// when onBlur is triggered, the input field has already switched,
// so it's necessary to obtain the value of the previous input field here.
Expand All @@ -589,6 +583,12 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
if (selectedIndexValue) {
triggerChange(selectedValue, needTriggerIndex, true);
}
} else if (changeOnBlur) {
const selectedIndexValue = getValue(selectedValue, mergedActivePickerIndex);

if (selectedIndexValue) {
triggerChange(selectedValue, mergedActivePickerIndex);
}
}
}

Expand All @@ -597,6 +597,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {

const getSharedInputHookProps = (index: 0 | 1, resetText: () => void) => ({
blurToCancel: !changeOnBlur && needConfirmButton,
changeOnBlur,
forwardKeyDown,
onBlur: onInternalBlur,
isClickOutside: (target: EventTarget | null) => {
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/usePickerInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function usePickerInput({
forwardKeyDown,
onKeyDown,
blurToCancel,
changeOnBlur,
onSubmit,
onCancel,
onFocus,
Expand All @@ -24,6 +25,7 @@ export default function usePickerInput({
forwardKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => boolean;
onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>, preventDefault: () => void) => void;
blurToCancel?: boolean;
changeOnBlur?: boolean
onSubmit: () => void | boolean;
onCancel: () => void;
onFocus?: React.FocusEventHandler<HTMLInputElement>;
Expand Down Expand Up @@ -158,7 +160,7 @@ export default function usePickerInput({
raf(() => {
preventBlurRef.current = false;
});
} else if (!blurToCancel && (!focused || clickedOutside)) {
} else if (!changeOnBlur && !blurToCancel && (!focused || clickedOutside)) {
triggerOpen(false);
}
}
Expand Down

0 comments on commit 213d2c5

Please sign in to comment.