Skip to content

Commit 755bf87

Browse files
authored
feat(datepicker): Turning the datepicker into a controlled component (#4)
* fix(datepicker): Adding default prop to firstDayOfWeek and improving value check in handleRangeInput * feat(datepicker): Turning the datepicker into a controlled component Closes #3 * style(calendar): Adding z-index: 2000 to the calendar
1 parent 014cb44 commit 755bf87

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"dependencies": {
3434
"classnames": "^2.2.5",
3535
"date-fns": "^1.29.0",
36-
"dayzed": "^2.2.0"
36+
"dayzed": "^2.2.0",
37+
"react-fast-compare": "^2.0.1"
3738
},
3839
"devDependencies": {
3940
"@storybook/react": "^3.4.0",

src/components/calendar/calendar.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
text-align: center;
33
position: absolute !important;
44
margin-top: 0.25rem !important;
5+
z-index: 2000;
56
}
67

78
.clndr-calendars-wrapper {

src/components/datepicker.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import isEqual from 'react-fast-compare';
34
import { formatSelectedDate, moveElementsByN, omit, pick } from '../utils';
45
import localeEn from '../locales/en-US';
56
import BasicDatePicker from '../pickers/basic';
@@ -26,6 +27,7 @@ class SemanticDatepicker extends React.Component {
2627
static propTypes = {
2728
clearable: PropTypes.bool,
2829
date: PropTypes.instanceOf(Date),
30+
firstDayOfWeek: PropTypes.number,
2931
format: PropTypes.string,
3032
keepOpenOnClear: PropTypes.bool,
3133
keepOpenOnSelect: PropTypes.bool,
@@ -44,13 +46,22 @@ class SemanticDatepicker extends React.Component {
4446
keepOpenOnClear: false,
4547
keepOpenOnSelect: false,
4648
date: undefined,
49+
firstDayOfWeek: 0,
4750
format: 'YYYY-MM-DD',
4851
locale: localeEn,
4952
placeholder: null,
5053
selected: null,
5154
type: 'basic',
5255
};
5356

57+
componentDidUpdate(prevProps) {
58+
const { selected } = this.props;
59+
60+
if (!isEqual(selected, prevProps.selected)) {
61+
this.onDateSelected(selected);
62+
}
63+
}
64+
5465
get isRangeInput() {
5566
return this.props.type === 'range';
5667
}
@@ -151,7 +162,7 @@ class SemanticDatepicker extends React.Component {
151162
handleRangeInput = newDates => {
152163
const { format, keepOpenOnSelect, onDateChange } = this.props;
153164

154-
if (!newDates.length) {
165+
if (!newDates || !newDates.length) {
155166
this.resetState();
156167

157168
return;

0 commit comments

Comments
 (0)