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

[datetime2] fix(DateInput2): clearing input calls onChange(null) #5409

Merged
merged 7 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion packages/datetime2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blueprintjs/datetime2",
"version": "0.2.0",
"version": "0.3.0",
adidahiya marked this conversation as resolved.
Show resolved Hide resolved
"description": "Components for interacting with dates and times with timezones",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/datetime2/src/components/date-input2/dateInput2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export interface DateInput2Props extends Omit<DateInputProps, "onChange" | "valu
/** The default timezone selected. Defaults to the user local timezone */
defaultTimezone?: string;

/** Callback invoked whenever the date or timezone has changed. ISO string */
onChange: (newDate: string, isUserChange?: boolean) => void;
/** Callback invoked whenever the date or timezone has changed. ISO string. Null if's not currently a valid date */
adidahiya marked this conversation as resolved.
Show resolved Hide resolved
onChange: (newDate: string | null, isUserChange?: boolean) => void;

/** An ISO string mapping to the selected time. */
value: string | null;
Expand Down Expand Up @@ -88,7 +88,7 @@ export const DateInput2: React.FC<DateInput2Props> = React.memo(function _DateIn
const handleDateChange = React.useCallback(
(newDate: Date | null, isUserChange: boolean) => {
if (newDate == null) {
return;
return onChange?.(newDate, isUserChange);
adidahiya marked this conversation as resolved.
Show resolved Hide resolved
}
const newDateString = getIsoEquivalentWithUpdatedTimezone(newDate, timezoneValue, timePrecision);
onChange?.(newDateString, isUserChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class DateInput2Example extends React.PureComponent<IExampleProps, DateIn
);
}

private handleDateChange = (date: string) => this.setState({ date });
private handleDateChange = (date: string | null) => this.setState({ date });

private handleFormatChange = (format: DateFormatProps) => this.setState({ format });
}