Skip to content

Commit 582a913

Browse files
committed
feat(RelativeRangeDatePicker): allow apply presets immediately
1 parent c4fb393 commit 582a913

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/components/RelativeRangeDatePicker/RelativeRangeDatePicker.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export function RelativeRangeDatePicker(props: RelativeRangeDatePickerProps) {
150150
isDateUnavailable={props.isDateUnavailable}
151151
placeholderValue={props.placeholderValue}
152152
withPresets={props.withPresets}
153+
applyPresetsImmediately={props.applyPresetsImmediately}
153154
presetTabs={props.presetTabs}
154155
docs={props.docs}
155156
withApplyButton={props.withApplyButton}

src/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export interface PickerFormProps extends RelativeRangeDatePickerStateOptions, Do
4040
withZonesList?: boolean;
4141
/** Show relative range presets */
4242
withPresets?: boolean;
43+
/** Apply presets immediately */
44+
applyPresetsImmediately?: boolean;
4345
/** Show header with docs tooltip */
4446
withHeader?: boolean;
4547
/** Custom preset tabs */
@@ -139,8 +141,9 @@ export function PickerForm(
139141
state.setRange(
140142
{type: 'relative', value: start},
141143
{type: 'relative', value: end},
144+
props.applyPresetsImmediately,
142145
);
143-
if (!props.withApplyButton) {
146+
if (!props.withApplyButton || props.applyPresetsImmediately) {
144147
props.onApply();
145148
}
146149
}}

src/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ export function useRelativeRangeDatePickerDialogState(props: PickerFormProps) {
6767
return;
6868
}
6969
setTimeZone(newTimeZone);
70-
const newStart = start ? {...start} : start;
70+
const newStart = start ? {...start} : null;
7171
if (newStart?.type === 'absolute') {
7272
newStart.value = newStart.value.timeZone(newTimeZone, true);
7373
setStart(newStart);
7474
}
75-
const newEnd = end ? {...end} : end;
75+
const newEnd = end ? {...end} : null;
7676
if (newEnd?.type === 'absolute') {
7777
newEnd.value = newEnd.value.timeZone(newTimeZone, true);
7878
setEnd(newEnd);
@@ -89,13 +89,13 @@ export function useRelativeRangeDatePickerDialogState(props: PickerFormProps) {
8989
}
9090
}
9191

92-
function setRange(newStart: Value, newEnd: Value) {
92+
function setRange(newStart: Value, newEnd: Value, force?: boolean) {
9393
if (props.readOnly) {
9494
return;
9595
}
9696
setStart(newStart);
9797
setEnd(newEnd);
98-
if (!withApplyButton) {
98+
if (!withApplyButton || force) {
9999
setValue(
100100
getRangeValue(newStart, newEnd, {...props, timeZone, allowNullableValues}),
101101
timeZone,

src/components/RelativeRangeDatePicker/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export interface RelativeRangeDatePickerProps
7070
withZonesList?: boolean;
7171
/** Show relative range presets */
7272
withPresets?: boolean;
73+
/** Apply presets immediately */
74+
applyPresetsImmediately?: boolean;
7375
/** Show header with docs tooltip */
7476
withHeader?: boolean;
7577
/** Custom preset tabs */

0 commit comments

Comments
 (0)