Skip to content

Commit

Permalink
Merge pull request mui#770 from dmtrKovalenko/bugfix/find-closest-ena…
Browse files Browse the repository at this point in the history
…bled-date

Bugfix/find closest enabled date
  • Loading branch information
dmtrKovalenko authored Nov 20, 2018
2 parents 9d34905 + 4f3c72a commit c15c444
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 35 deletions.
1 change: 0 additions & 1 deletion docs/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import Layout from './layout/Layout';
import Router from './Pages/Router';
import { setPrismTheme } from './utils/prism';
import { createMuiTheme, MuiThemeProvider } from '@material-ui/core';

interface AppState {
Expand Down
7 changes: 3 additions & 4 deletions docs/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import * as serviceWorker from './serviceWorker';
import { MuiPickersUtilsProvider } from 'material-ui-pickers';
import Utils from '@date-io/date-fns';
import { BrowserRouter } from 'react-router-dom';

// @ts-ignore
window.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__ = true;

import { create } from 'jss';
import rtl from 'jss-rtl';
import JssProvider from 'react-jss/lib/JssProvider';
import { createGenerateClassName, jssPreset } from '@material-ui/core/styles';

// @ts-ignore
window.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__ = true;

// @ts-ignore Configure JSS
const jss = create({ plugins: [...jssPreset().plugins, rtl()] });

Expand Down
22 changes: 11 additions & 11 deletions lib/.size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"build/dist/material-ui-pickers.esm.js": {
"bundled": 113798,
"minified": 66892,
"gzipped": 14511,
"bundled": 114113,
"minified": 67041,
"gzipped": 14578,
"treeshaked": {
"rollup": {
"code": 49182,
"code": 49331,
"import_statements": 1317
},
"webpack": {
"code": 55986
"code": 56135
}
}
},
"build/dist/material-ui-pickers.umd.js": {
"bundled": 229613,
"minified": 100039,
"gzipped": 25343
"bundled": 230051,
"minified": 100239,
"gzipped": 25431
},
"build/dist/material-ui-pickers.umd.min.js": {
"bundled": 200494,
"minified": 90046,
"gzipped": 23670
"bundled": 201100,
"minified": 90276,
"gzipped": 23809
}
}
23 changes: 11 additions & 12 deletions lib/src/DatePicker/components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,17 @@ export class Calendar extends React.Component<CalendarProps, CalendarState> {
const { date, minDate, maxDate, utils, disablePast } = this.props;

if (this.shouldDisableDate(date)) {
this.onDateSelect(
findClosestEnabledDate({
date,
utils,
minDate,
maxDate,
disablePast: Boolean(disablePast),
disableFuture: Boolean(disablePast),
shouldDisableDate: this.shouldDisableDate,
}),
false
);
const closestEnabledDate = findClosestEnabledDate({
date,
utils,
minDate,
maxDate,
disablePast: Boolean(disablePast),
disableFuture: Boolean(disablePast),
shouldDisableDate: this.shouldDisableDate,
});

this.onDateSelect(closestEnabledDate || minDate, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/TimePicker/TimePickerInline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const TimePickerInline: React.SFC<TimePickerInlineProps> = props => {
} = props;

return (
<BasePicker {...props} autoOk>
<BasePicker mergePreviousDateOnChange autoOk {...props}>
{({
date,
utils,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/TimePicker/TimePickerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const TimePickerModal: React.SFC<TimePickerModalProps> = props => {
} = props;

return (
<BasePicker {...props}>
<BasePicker mergePreviousDateOnChange {...props}>
{({
date,
utils,
Expand Down
1 change: 1 addition & 0 deletions lib/src/_helpers/date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const findClosestEnabledDate = ({
if (disablePast && utils.isBefore(minDate, today)) {
minDate = today;
}

if (disableFuture && utils.isAfter(maxDate, today)) {
maxDate = today;
}
Expand Down
8 changes: 7 additions & 1 deletion lib/src/_shared/BasePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface BasePickerProps {
/** Date that will be initially highlighted */
initialFocusedDate?: DateType;
forwardedRef?: any;
mergePreviousDateOnChange?: boolean;
}

export interface OuterBasePickerProps extends BasePickerProps, WithUtilsProps {
Expand Down Expand Up @@ -90,7 +91,12 @@ export class BasePicker extends React.Component<
this.handleChange(this.props.utils.date(), false);

public handleTextFieldChange = (date: MaterialUiPickersDate) => {
const { onChange } = this.props;
const { onChange, utils, mergePreviousDateOnChange } = this.props;

if (mergePreviousDateOnChange) {
date = utils.mergeDateAndTime(this.state.date, date);
}

if (date === null) {
onChange(null);
} else {
Expand Down
5 changes: 2 additions & 3 deletions lib/src/_shared/DateTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,12 @@ export class DateTextField extends React.PureComponent<DateTextFieldProps> {
prevProps.emptyLabel !== this.props.emptyLabel ||
prevProps.utils !== this.props.utils
) {
/* eslint-disable-next-line react/no-did-update-set-state */
this.setState(DateTextField.updateState(this.props));
}
}

public commitUpdates = (value: string) => {
const { clearable, onClear, utils, format, onError } = this.props;
const { onChange, clearable, onClear, utils, format, onError } = this.props;

if (value === '') {
if (this.props.value === null) {
Expand All @@ -256,7 +255,7 @@ export class DateTextField extends React.PureComponent<DateTextFieldProps> {
},
() => {
if (!error && !utils.isEqual(newValue, oldValue)) {
this.props.onChange(newValue);
onChange(newValue);
}

if (error && onError) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"release": "lerna run release --scope --parallel material-ui-pickers && lerna run deploy --scope --parallel docs",
"release:patch": "npm run bump:patch && npm run release",
"release:minor": "npm run bump:minor && npm run release",
"postinstall": "lerna link"
"postinstall": "lerna bootstrap"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit c15c444

Please sign in to comment.