Skip to content

Commit

Permalink
[EuiSuperDatePicker] date popover onChange should only accept strings (
Browse files Browse the repository at this point in the history
…#3460)

* restrict to string; return iso string

* handleChange interface

* CL
  • Loading branch information
thompsongl authored May 14, 2020
1 parent eab1f14 commit c1a6ae2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
**Bug Fixes**

- Fixed `EuiSuperDatePicker` quick selection menu overriding specified time range with default values ([#3446](https://github.com/elastic/eui/pull/3446))
- Fixed `EuiDatePopoverContent` `onChange` event to only accept `string` date input ([#3460](https://github.com/elastic/eui/pull/3460))

**Breaking changes**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import moment, { Moment, LocaleSpecifier } from 'moment'; // eslint-disable-line

import dateMath from '@elastic/datemath';

import { EuiDatePicker } from '../../date_picker';
import { EuiDatePicker, EuiDatePickerProps } from '../../date_picker';
import { EuiFormRow, EuiFieldText, EuiFormLabel } from '../../../form';
import { toSentenceCase } from '../../../../services/string/to_case';
import { EuiDatePopoverContentProps } from './date_popover_content';
Expand Down Expand Up @@ -73,12 +73,12 @@ export class EuiAbsoluteTab extends Component<
};
}

handleChange: EuiDatePopoverContentProps['onChange'] = (date, event) => {
handleChange: EuiDatePickerProps['onChange'] = (date, event) => {
const { onChange } = this.props;
if (date === null) {
return;
}
onChange(typeof date === 'string' ? date : date.toISOString(), event);
onChange(date.toISOString(), event);

const valueAsMoment = moment(date);
this.setState({
Expand All @@ -97,7 +97,7 @@ export class EuiAbsoluteTab extends Component<
);
const dateIsValid = valueAsMoment.isValid();
if (dateIsValid) {
onChange(valueAsMoment, event);
onChange(valueAsMoment.toISOString(), event);
}
this.setState({
textInputValue: event.target.value as string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ import {
toAbsoluteString,
toRelativeString,
} from '../date_modes';
import { Moment, LocaleSpecifier } from 'moment'; // eslint-disable-line import/named
import { LocaleSpecifier } from 'moment'; // eslint-disable-line import/named

export interface EuiDatePopoverContentProps {
value: string;
onChange(
date: Moment | string | null,
event?: React.SyntheticEvent<any>
): void;
onChange(date: string | null, event?: React.SyntheticEvent<any>): void;
roundUp?: boolean;
dateFormat: string;
timeFormat: string;
Expand Down

0 comments on commit c1a6ae2

Please sign in to comment.