Skip to content

Commit

Permalink
fix(daterangepicker): fix time disabled logic (#851)
Browse files Browse the repository at this point in the history
  • Loading branch information
byeval authored and cpylua committed Jun 1, 2018
1 parent 8c12a74 commit c8a67aa
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions packages/zent/src/datetimepicker/time/TimePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,14 @@ export default class TimePanel extends PureComponent {
openPanel = type => {
return () => {
const key = stateMap[type];
this.setState({
[key]: true,
});
this.setState({ [key]: true });
};
};

hidePanel = type => {
return () => {
const key = stateMap[type];
this.setState({
[key]: false,
});
this.setState({ [key]: false });
};
};

Expand All @@ -60,7 +56,26 @@ export default class TimePanel extends PureComponent {
let fns;
if (disabledTime) {
return disabledTime[disabledMap[type]];
} else if (min && isSameDate(min, actived)) {
}

if (min && max && isSameDate(min, actived) && isSameDate(max, actived)) {
fns = {
hour: val => val < min.getHours() || val > max.getHours(),
minute: val =>
(actived.getHours() === min.getHours() && val < min.getMinutes()) ||
(actived.getHours() === max.getHours() && val > max.getMinutes()),
second: val =>
(actived.getHours() === min.getHours() &&
actived.getMinutes() === min.getMinutes() &&
val < min.getSeconds()) ||
(actived.getHours() === max.getHours() &&
actived.getMinutes() === max.getMinutes() &&
val > max.getSeconds()),
};
return fns[type];
}

if (min && isSameDate(min, actived)) {
fns = {
hour: val => val < min.getHours(),
minute: val =>
Expand All @@ -71,7 +86,9 @@ export default class TimePanel extends PureComponent {
val < min.getSeconds(),
};
return fns[type];
} else if (max && isSameDate(max, actived)) {
}

if (max && isSameDate(max, actived)) {
fns = {
hour: val => val > max.getHours(),
minute: val => val > max.getMinutes(),
Expand Down Expand Up @@ -122,13 +139,16 @@ export default class TimePanel extends PureComponent {

<div className="time-panel__preview">
<span className="time__number" onClick={this.openPanel('hour')}>
{padLeft(actived.getHours())} {i18n.panel.hour}
{padLeft(actived.getHours())}
{i18n.panel.hour}
</span>
<span className="time__number" onClick={this.openPanel('minute')}>
{padLeft(actived.getMinutes())} {i18n.panel.minute}
{padLeft(actived.getMinutes())}
{i18n.panel.minute}
</span>
<span className="time__number" onClick={this.openPanel('second')}>
{padLeft(actived.getSeconds())} {i18n.panel.second}
{padLeft(actived.getSeconds())}
{i18n.panel.second}
</span>
</div>
</div>
Expand Down

0 comments on commit c8a67aa

Please sign in to comment.