Skip to content

Commit

Permalink
Adds onClear prop to EuiDatePicker to make it "clearable" (elastic#2235)
Browse files Browse the repository at this point in the history
* Adds onClear prop to EuiDatePicker to make it "clearable"

* Adds changelog entry

* Update CHANGELOG.md

Co-Authored-By: Greg Thompson <thompsongl@users.noreply.github.com>
  • Loading branch information
jasonrhodes and thompsongl committed Sep 10, 2019
1 parent 750f661 commit 6e56e1b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Converted `EuiFacetButton` to TypeScript ([#2226](https://github.com/elastic/eui/pull/2226))
- Adds an optional `onClear` prop to the the `EuiDatePicker` component ([#2235](https://github.com/elastic/eui/pull/2235))

**Bug fixes**

Expand Down
10 changes: 10 additions & 0 deletions src-docs/src/views/date_picker/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ export default class extends Component {

<EuiSpacer size="m" />

<EuiDatePicker
showTimeSelect
selected={this.state.startDate}
onChange={this.handleChange}
onClear={() => this.handleChange(null)}
placeholder="Clearable"
/>

<EuiSpacer size="m" />

<EuiDatePicker
showTimeSelect
selected={this.state.startDate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`EuiDatePicker is rendered 1`] = `
className="euiDatePicker euiDatePicker--shadow"
>
<EuiFormControlLayout
clear={null}
fullWidth={false}
icon="calendar"
isLoading={false}
Expand Down
6 changes: 6 additions & 0 deletions src/components/date_picker/date_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class EuiDatePicker extends Component {
minDate,
minTime,
onChange,
onClear,
openToDate,
placeholder,
popperClassName,
Expand Down Expand Up @@ -127,6 +128,7 @@ export class EuiDatePicker extends Component {
<EuiFormControlLayout
icon={optionalIcon}
fullWidth={fullWidth}
clear={selected && onClear ? { onClick: onClear } : null}
isLoading={isLoading}>
<EuiValidatableControl isInvalid={isInvalid}>
<DatePicker
Expand Down Expand Up @@ -246,6 +248,10 @@ EuiDatePicker.propTypes = {
* What to do when the input changes
*/
onChange: PropTypes.func,
/**
* What to do when the input is cleared by the x icon
*/
onClear: PropTypes.func,
/**
* Opens to this date (in moment format) on first press, regardless of selection
*/
Expand Down

0 comments on commit 6e56e1b

Please sign in to comment.