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

React datepicker better responsive handling when inline #1820

Merged
merged 10 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

- Widened `EuiComboBox`'s `options[].value` / `EuiComboBoxOptionProps.value` TypeScript definition ([#2080](https://github.com/elastic/eui/pull/2080))
- Added TS defs for `EuiComboBox`'s props spreading onto a `div` ([#2080](https://github.com/elastic/eui/pull/2080))
- Fixed responsive display of inline `EuiDatePicker` ([#1820](https://github.com/elastic/eui/pull/1820))
- Removed time from default `dateFormat` of `EuiDatePicker` ([#1820](https://github.com/elastic/eui/pull/1820))

## [`12.2.0`](https://github.com/elastic/eui/tree/v12.2.0)

Expand Down
12 changes: 1 addition & 11 deletions src-docs/src/views/date_picker/time_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ export default class extends Component {
showTimeSelect
selected={this.state.startDate}
onChange={this.handleChange}
dateFormat="MM/DD/YYYY HH:mm.ss.SSS"
/>
</EuiFormRow>

<EuiSpacer />

<EuiFormRow label="Time select off">
<EuiDatePicker
selected={this.state.startDate}
onChange={this.handleChange}
dateFormat="MM/DD/YYYY"
/>
</EuiFormRow>

Expand All @@ -69,6 +58,7 @@ export default class extends Component {
selected={this.state.startDate}
onChange={this.handleChange}
dateFormat="hh:mm a"
timeFormat="hh:mm a"
injectTimes={[
moment()
.hours(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`EuiDatePicker is rendered 1`] = `
aria-label="aria-label"
className="euiDatePicker euiFieldText euiFieldText--withIcon testClass1 testClass2"
data-test-subj="test subject string"
dateFormat="MM/DD/YYYY hh:mm A"
dateFormat="MM/DD/YYYY"
dateFormatCalendar="MMMM YYYY"
disabled={false}
disabledKeyboardNavigation={false}
Expand Down
12 changes: 10 additions & 2 deletions src/components/date_picker/_date_picker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
&--next {
@include datePicker__arrow;
// Pixel value because of some padding on the icon
right: 10px;
right: 20px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligned this value with the one for previous:

before:

height: $euiSize;
width: $euiSize;
transform: rotate(-90deg);
Expand Down Expand Up @@ -635,7 +635,7 @@
.react-datepicker__month--accessible:focus {
background: $euiFocusBackgroundColor;

.react-datepicker__day--in-range {
.react-datepicker__day--in-range:not(.react-datepicker__day--selected) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes this issue:

Screen Shot 2019-06-14 at 11 28 19 AM

now:

border-top-color: $euiFocusBackgroundColor;
border-bottom-color: $euiFocusBackgroundColor;
}
Expand All @@ -661,6 +661,14 @@

// We drop the time picker on mobile. They can still type in the time directly.
@include euiBreakpoint('xs','s') {

// This resizes EUI's normal form control to be the width of the calendar
.euiDatePicker--inline {
max-width: $euiDatePickerCalendarWidth;
display: block;
}

// This hides the time entirely
.react-datepicker__time-container {
display: none;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/date_picker/_index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Uses some form mixins
@import 'variables';
@import 'date_picker';
@import 'date_picker_range';
@import 'super_date_picker/index';
1 change: 1 addition & 0 deletions src/components/date_picker/_variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$euiDatePickerCalendarWidth: 284px;
17 changes: 14 additions & 3 deletions src/components/date_picker/date_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { EuiValidatableControl } from '../form/validatable_control';

import { EuiErrorBoundary } from '../error_boundary';

export const euiDatePickerDefaultDateFormat = 'MM/DD/YYYY';
export const euiDatePickerDefaultTimeFormat = 'hh:mm A';

export class EuiDatePicker extends Component {
render() {
const {
Expand Down Expand Up @@ -75,6 +78,13 @@ export class EuiDatePicker extends Component {
optionalIcon = 'calendar';
}

// In case the consumer did not alter the default date format but wants
// to add the time select, we append the default time format
let fullDateFormat = dateFormat;
if (showTimeSelect && dateFormat === euiDatePickerDefaultDateFormat) {
fullDateFormat = `${dateFormat} ${timeFormat}`;
}

// EuiDatePicker only supports a subset of props from react-datepicker. Using any of
// the unsupported props below will spit out an error.
const PropNotSupported = () => {
Expand Down Expand Up @@ -124,7 +134,7 @@ export class EuiDatePicker extends Component {
calendarClassName={calendarClassName}
className={datePickerClasses}
customInput={customInput}
dateFormat={dateFormat}
dateFormat={fullDateFormat}
dayClassName={dayClassName}
disabled={disabled}
excludeDates={excludeDates}
Expand Down Expand Up @@ -280,11 +290,12 @@ EuiDatePicker.propTypes = {

EuiDatePicker.defaultProps = {
adjustDateOnChange: true,
dateFormat: 'MM/DD/YYYY hh:mm A',
dateFormat: euiDatePickerDefaultDateFormat,
fullWidth: false,
isLoading: false,
shadow: true,
shouldCloseOnSelect: true,
showIcon: true,
timeFormat: 'hh:mm A',
showTimeSelect: false,
timeFormat: euiDatePickerDefaultTimeFormat,
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@
.euiDatePopoverContent__padded--large {
padding: $euiSize;
}

@include euiBreakpoint('xs', 's') {
.euiDatePopoverContent {
// Small screens drop the time selector
width: $euiDatePickerCalendarWidth;
}
}