Skip to content
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

Update Datepicker onSelectedDateChanged signature to include isClearAction parameter #1367

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
10 changes: 5 additions & 5 deletions packages/ui/src/components/Datepicker/Datepicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface DatepickerProps extends Omit<TextInputProps, "theme"> {
language?: string;
weekStart?: WeekStart;
theme?: DeepPartial<FlowbiteDatepickerTheme>;
onSelectedDateChanged?: (date: Date) => void;
onSelectedDateChanged?: (date: Date, isClearAction: boolean) => void;
}

const DatepickerRender: ForwardRefRenderFunction<DatepickerRef, DatepickerProps> = (
Expand Down Expand Up @@ -137,11 +137,11 @@ const DatepickerRender: ForwardRefRenderFunction<DatepickerRef, DatepickerProps>
const datepickerRef = useRef<HTMLDivElement>(null);

// Triggers when user select the date
const changeSelectedDate = (date: Date, useAutohide: boolean) => {
const changeSelectedDate = (date: Date, useAutohide: boolean, isClearAction?: boolean) => {
setSelectedDate(date);

if (onSelectedDateChanged) {
onSelectedDateChanged(date);
onSelectedDateChanged(date, isClearAction ?? false);
}

if (autoHide && view === Views.Days && useAutohide == true && !inline) {
Expand All @@ -150,7 +150,7 @@ const DatepickerRender: ForwardRefRenderFunction<DatepickerRef, DatepickerProps>
};

const clearDate = () => {
changeSelectedDate(defaultDate, true);
changeSelectedDate(defaultDate, true, true);
if (defaultDate) {
setViewDate(defaultDate);
}
Expand Down Expand Up @@ -336,7 +336,7 @@ const DatepickerRender: ForwardRefRenderFunction<DatepickerRef, DatepickerProps>
type="button"
className={twMerge(theme.popup.footer.button.base, theme.popup.footer.button.clear)}
onClick={() => {
changeSelectedDate(defaultDate, true);
changeSelectedDate(defaultDate, true, true);
if (defaultDate) {
setViewDate(defaultDate);
}
Expand Down
Loading