Skip to content

Commit

Permalink
fix(DatePikcer2): timePanelProps.defaultValue issue, close alibaba-fu…
Browse files Browse the repository at this point in the history
  • Loading branch information
皆虚 authored and youluna committed Jul 21, 2021
1 parent 2287c39 commit 1a7b25c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/date-picker2/demo/disabledDate.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Disable date cells by `disabledDate`.

````jsx
import { DatePicker2 } from '@alifd/next';
import moment from 'moment';
import dayjs from 'dayjs';

const { RangePicker, MonthPicker, YearPicker } = DatePicker2;
const currentDate = moment();
const currentDate = dayjs();

// Disable all dates before today
const disabledDate = function (date, mode) {
Expand Down
6 changes: 2 additions & 4 deletions docs/date-picker2/demo/show-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@ Enable `showTime` to create a DatePicker2/RangePicker with time.

````jsx
import { DatePicker2 } from '@alifd/next';
import dayjs from 'dayjs';

const { RangePicker } = DatePicker2;
const onChange = (value) => console.log('onChange: ', value);
const onOk = (value) => console.log('onOK: ', value.format('YYYY-MM-DD HH:mm:ss'));
const onRangeOk = (value) => console.log('onOk: [%s, %s]', ...value);

const defaultTimeValue = dayjs('09:00:00', 'HH:mm:ss', true);
const defaultTimeValues = [dayjs('09:00:00', 'HH:mm:ss', true), dayjs('23:59:59', 'HH:mm:ss', true)];
const defaultTimeValue = '09:00:00';

ReactDOM.render(<div className="app">
<div><DatePicker2 showTime onChange={onChange} onOk={onOk} /></div>
<div><DatePicker2 showTime timePanelProps={{ defaultValue: defaultTimeValue, secondStep: 10 }} onChange={onChange} onOk={onOk} /></div>
<div><RangePicker showTime onChange={onChange} onOk={onRangeOk} /></div>
<div><RangePicker showTime timePanelProps={{ defaultValue: defaultTimeValues, format: 'HH:mm', minuteStep: 15 }} onChange={onChange} onOk={onRangeOk} /></div>
<div><RangePicker showTime timePanelProps={{ defaultValue: ['09:00', '23:59'], format: 'HH:mm', minuteStep: 15 }} onChange={onChange} onOk={onRangeOk} /></div>
</div>, mountNode);
````
```css
Expand Down
8 changes: 6 additions & 2 deletions src/date-picker2/panels/date-panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ class DatePanel extends React.Component {

// 默认时间
const { timePanelProps = {} } = props;

let defaultTime = timePanelProps.defaultValue;

if (defaultTime) {
defaultTime = datejs(defaultTime, timePanelProps.format || 'HH:mm:ss');
// fix: https://github.com/alibaba-fusion/next/issues/3203
defaultTime = datejs(
defaultTime,
typeof defaultTime === 'string' ? timePanelProps.format || 'HH:mm:ss' : undefined
);
}

this.state = {
Expand Down
1 change: 0 additions & 1 deletion src/date-picker2/panels/time-panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class TimePanel extends React.PureComponent {
locale: PT.object,
value: SharedPT.date,
timePanelProps: PT.object,
defaultValue: SharedPT.value,
onSelect: PT.func,
};

Expand Down

0 comments on commit 1a7b25c

Please sign in to comment.