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

【DatePicker】display incorrect time after setting 'showTime' and 'allowClear' #8885

Closed
jackie19 opened this issue Jan 9, 2018 · 6 comments
Closed
Assignees

Comments

@jackie19
Copy link

@jackie19 jackie19 commented Jan 9, 2018

Version

3.1.1

Environment

macOS 10.12.6 , chrome 版本 63.0.3239.132(正式版本) (64 位),

Reproduction link

https://riddle.alibaba-inc.com/riddles/5d7aedf6?mode=jsx

spare link:
https://codesandbox.io/s/x933235xro

Steps to reproduce

1.click clear button
2.display datePicker panel
2.click a date in datePicker panel like: 2018-1-1 ( do not click other place to hide datePicker )
3.click a date (2018-1-1) again

What is expected?

2018-1-1 12:12:12

What is actually happening?

the time part is current time, not 12:12:12

code

import { DatePicker } from 'antd';
import moment from 'moment';
let defaultValue = moment('2018-12-12 12:12:12');
let cleared = false;
function onChange(value, dateString) {
  console.log('Selected Time: ', value);
  console.log('Formatted Selected Time: ', dateString);

  if (cleared) {
    value = moment(moment(value).format('YYYY-MM-DD 12:12:12'));
    cleared = false;
  }

  if (!value) {
    cleared = true;
  }

  render(value);
}

function onOk(value) {
  render(value);
  console.log('onOk: ', value);
}

function render(value) {
  ReactDOM.render(
    <div>
      <DatePicker
        showTime
        value={value}
        format="YYYY-MM-DD HH:mm:ss"
        placeholder="Select Time"
        onChange={onChange}
        onOk={onOk}
      />
      <br />
    </div>,
    mountNode,
  );
}

render(defaultValue);

want to set a default time after clear date, but when I click a date second time, the default time is overwriten by current time.

@yesmeck
Copy link
Member

@yesmeck yesmeck commented Jan 23, 2018

The behavior is expected.

1.click clear button

value is cleared.

2.display datePicker panel

nothing to show.

3.click a date in datePicker panel like: 2018-1-1 ( do not click other place to hide datePicker )

shows 2018-12-12 12:12:12 as you set in onChange.

4.click a date (2018-1-1) again

shows current date time.

@yesmeck yesmeck closed this Jan 23, 2018
@jackie19
Copy link
Author

@jackie19 jackie19 commented Jan 23, 2018

1.click clear button,
2.display datePicker panel , choose a date , click other place to hide panel,
3.display panle and choose another date, the time part will be 12:12:12,

How do you explain this?

@yesmeck
Copy link
Member

@yesmeck yesmeck commented Jan 23, 2018

As I said you set value to YYYY-MM-DD 12:12:12 in onChange.

@jackie19
Copy link
Author

@jackie19 jackie19 commented Jan 23, 2018

How do I make it show 12:12:12 on second click?
(after clear the value, and not hide panel between clicks.)

@yesmeck
Copy link
Member

@yesmeck yesmeck commented Jan 23, 2018

Hmm, that's a bug.

@yesmeck yesmeck reopened this Jan 23, 2018
@jackie19
Copy link
Author

@jackie19 jackie19 commented Jan 23, 2018

:D, shall we talk this in DingTalk ?

yesmeck added a commit that referenced this issue Jan 26, 2018
If not control Calendar value, the internal value of Calendar will keep a
different date than parent component.
@nikogu nikogu closed this in #9141 Jan 26, 2018
nikogu added a commit that referenced this issue Jan 26, 2018
If not control Calendar value, the internal value of Calendar will keep a
different date than parent component.
yesmeck added a commit that referenced this issue Jan 28, 2018
This reverts commit 98387ad.
@yesmeck yesmeck reopened this Jan 28, 2018
yesmeck added a commit that referenced this issue Jan 29, 2018
@yesmeck yesmeck closed this in #9164 Feb 1, 2018
yesmeck added a commit that referenced this issue Feb 1, 2018
yesmeck added a commit that referenced this issue Feb 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants