) => {
+ this.setState({ textInputValue: event.target.value });
+
+ // Add a debouncer that gives the user some time to finish typing
+ // before attempting to parse the text as a timestamp. Otherwise,
+ // typing a single digit gets parsed as a unix timestamp 😬
+ clearTimeout(this.debouncedTypeTimeout);
+ this.debouncedTypeTimeout = setTimeout(this.parseUserDateInput, 1000); // 1 second debounce
+ };
+
+ parseUserDateInput = () => {
+ const { onChange, dateFormat } = this.props;
+ const { textInputValue } = this.state;
+
+ const invalidDateState = {
+ isTextInvalid: true,
+ valueAsMoment: null,
+ };
+ if (!textInputValue) {
+ return this.setState(invalidDateState);
+ }
+
+ // Attempt to parse with passed `dateFormat`
+ let valueAsMoment = moment(textInputValue, dateFormat, true);
+ let dateIsValid = valueAsMoment.isValid();
+
+ // If not valid, try a few other other standardized formats
+ if (!dateIsValid) {
+ valueAsMoment = moment(textInputValue, ALLOWED_USER_DATE_FORMATS, true);
+ dateIsValid = valueAsMoment.isValid();
+ }
+
if (dateIsValid) {
- onChange(valueAsMoment.toISOString(), event);
+ onChange(valueAsMoment.toISOString());
+ this.setState({
+ textInputValue: valueAsMoment.format(this.props.dateFormat),
+ isTextInvalid: false,
+ valueAsMoment: valueAsMoment,
+ });
+ } else {
+ this.setState(invalidDateState);
}
- this.setState({
- textInputValue: event.target.value,
- isTextInvalid: !dateIsValid,
- valueAsMoment: dateIsValid ? valueAsMoment : null,
- });
};
render() {
@@ -98,7 +136,7 @@ export class EuiAbsoluteTab extends Component<
const { valueAsMoment, isTextInvalid, textInputValue } = this.state;
return (
-
+ <>
{dateFormat} }}
>
{(dateFormatError: string) => (
{labelPrefix}}
/>
)}
-
+ >
);
}
}
diff --git a/src/components/date_picker/super_date_picker/date_popover/date_popover_button.tsx b/src/components/date_picker/super_date_picker/date_popover/date_popover_button.tsx
index 5122482e826..536e1e178fb 100644
--- a/src/components/date_picker/super_date_picker/date_popover/date_popover_button.tsx
+++ b/src/components/date_picker/super_date_picker/date_popover/date_popover_button.tsx
@@ -34,7 +34,7 @@ export interface EuiDatePopoverButtonProps {
isOpen: boolean;
needsUpdating?: boolean;
locale?: LocaleSpecifier;
- onChange: NonNullable;
+ onChange: EuiDatePopoverContentProps['onChange'];
onPopoverClose: EuiPopoverProps['closePopover'];
onPopoverToggle: MouseEventHandler;
position: 'start' | 'end';
diff --git a/src/components/date_picker/super_date_picker/date_popover/date_popover_content.tsx b/src/components/date_picker/super_date_picker/date_popover/date_popover_content.tsx
index 98dfb45f5de..6a1a2a60f91 100644
--- a/src/components/date_picker/super_date_picker/date_popover/date_popover_content.tsx
+++ b/src/components/date_picker/super_date_picker/date_popover/date_popover_content.tsx
@@ -27,7 +27,7 @@ import { LocaleSpecifier } from 'moment'; // eslint-disable-line import/named
export interface EuiDatePopoverContentProps {
value: string;
- onChange(date: string | null, event?: React.SyntheticEvent): void;
+ onChange: (date: string) => void;
roundUp?: boolean;
dateFormat: string;
timeFormat: string;
diff --git a/src/components/date_picker/super_date_picker/super_date_picker.tsx b/src/components/date_picker/super_date_picker/super_date_picker.tsx
index cf5ce985b0a..6e75c2e6396 100644
--- a/src/components/date_picker/super_date_picker/super_date_picker.tsx
+++ b/src/components/date_picker/super_date_picker/super_date_picker.tsx
@@ -75,6 +75,7 @@ export type EuiSuperDatePickerProps = CommonProps & {
/**
* Specifies the formatted used when displaying dates and/or datetimes
+ * @default 'MMM D, YYYY @ HH:mm:ss.SSS'
*/
dateFormat?: string;
@@ -92,6 +93,9 @@ export type EuiSuperDatePickerProps = CommonProps & {
isDisabled?: boolean | { display: ReactNode };
isLoading?: boolean;
+ /**
+ * @default true
+ */
isPaused?: boolean;
/**
@@ -99,6 +103,7 @@ export type EuiSuperDatePickerProps = CommonProps & {
* - `auto`: fits width to internal content / time string.
* - `restricted`: static width that fits the longest possible time string.
* - `full`: expands to 100% of the container.
+ * @default 'restricted'
*/
width?: 'restricted' | 'full' | 'auto';
@@ -139,20 +144,29 @@ export type EuiSuperDatePickerProps = CommonProps & {
/**
* Refresh interval in milliseconds
+ * @default 1000
*/
refreshInterval?: Milliseconds;
+ /**
+ * @default 'now-15m'
+ */
start?: ShortDate;
+ /**
+ * @default 'now'
+ */
end?: ShortDate;
/**
* Specifies the formatted used when displaying times
+ * @default 'HH:mm'
*/
timeFormat?: string;
utcOffset?: number;
/**
* Set showUpdateButton to false to immediately invoke onTimeChange for all start and end changes.
+ * @default true
*/
showUpdateButton?: boolean | 'iconOnly';
diff --git a/upcoming_changelogs/7331.md b/upcoming_changelogs/7331.md
new file mode 100644
index 00000000000..b7aff7b5697
--- /dev/null
+++ b/upcoming_changelogs/7331.md
@@ -0,0 +1 @@
+- For greater flexibility, `EuiSuperDatePicker` now allows users to paste ISO 8601, RFC 2822, and Unix timestamps in the `Absolute` tab input, in addition to timestamps in the `dateFormat` prop