Skip to content

feat(RelativeRangeDatePicker): allow apply presets immediately #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export function RelativeRangeDatePicker(props: RelativeRangeDatePickerProps) {
isDateUnavailable={props.isDateUnavailable}
placeholderValue={props.placeholderValue}
withPresets={props.withPresets}
applyPresetsImmediately={props.applyPresetsImmediately}
presetTabs={props.presetTabs}
docs={props.docs}
withApplyButton={props.withApplyButton}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface PickerFormProps extends RelativeRangeDatePickerStateOptions, Do
withZonesList?: boolean;
/** Show relative range presets */
withPresets?: boolean;
/** Apply presets immediately */
applyPresetsImmediately?: boolean;
/** Show header with docs tooltip */
withHeader?: boolean;
/** Custom preset tabs */
Expand Down Expand Up @@ -139,8 +141,9 @@ export function PickerForm(
state.setRange(
{type: 'relative', value: start},
{type: 'relative', value: end},
props.applyPresetsImmediately,
);
if (!props.withApplyButton) {
if (!props.withApplyButton || props.applyPresetsImmediately) {
props.onApply();
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ export function useRelativeRangeDatePickerDialogState(props: PickerFormProps) {
return;
}
setTimeZone(newTimeZone);
const newStart = start ? {...start} : start;
const newStart = start ? {...start} : null;
if (newStart?.type === 'absolute') {
newStart.value = newStart.value.timeZone(newTimeZone, true);
setStart(newStart);
}
const newEnd = end ? {...end} : end;
const newEnd = end ? {...end} : null;
if (newEnd?.type === 'absolute') {
newEnd.value = newEnd.value.timeZone(newTimeZone, true);
setEnd(newEnd);
Expand All @@ -89,13 +89,13 @@ export function useRelativeRangeDatePickerDialogState(props: PickerFormProps) {
}
}

function setRange(newStart: Value, newEnd: Value) {
function setRange(newStart: Value, newEnd: Value, force?: boolean) {
if (props.readOnly) {
return;
}
setStart(newStart);
setEnd(newEnd);
if (!withApplyButton) {
if (!withApplyButton || force) {
setValue(
getRangeValue(newStart, newEnd, {...props, timeZone, allowNullableValues}),
timeZone,
Expand Down
2 changes: 2 additions & 0 deletions src/components/RelativeRangeDatePicker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export interface RelativeRangeDatePickerProps
withZonesList?: boolean;
/** Show relative range presets */
withPresets?: boolean;
/** Apply presets immediately */
applyPresetsImmediately?: boolean;
/** Show header with docs tooltip */
withHeader?: boolean;
/** Custom preset tabs */
Expand Down
Loading