Skip to content

Commit

Permalink
fix(date-picker): fix AM/PM display incorrect issue when switching ho…
Browse files Browse the repository at this point in the history
…urs (#1822)
  • Loading branch information
simonguo committed Aug 9, 2021
1 parent bd820c7 commit 1e67b89
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Calendar/TimeDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,12 @@ class TimeDropdown extends React.PureComponent<TimeDropdownProps> {
};

handleClick = (type: TimeType, d: number, event: React.MouseEvent) => {
const { onSelect, date } = this.props;
// $FlowFixMe
const { onSelect, date, showMeridian } = this.props;
let nextDate = date || new Date();

switch (type) {
case 'hours':
nextDate = setHours(date, d);
nextDate = setHours(date, showMeridian && getHours(nextDate) >= 12 ? d + 12 : d);
break;
case 'minutes':
nextDate = setMinutes(date, d);
Expand Down
20 changes: 20 additions & 0 deletions src/DatePicker/test/DatePickerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,24 @@ describe('DatePicker', () => {
);
assert.equal(picker.querySelector('.rs-calendar-time-dropdown-column li').innerText, '12');
});

it('Should keep AM PM unchanged', () => {
const instance = getInstance(
<DatePicker
value={parse('2017-08-14 13:00:00')}
format="hh:mm:ss A"
defaultOpen
showMeridian
/>
);

const picker = instance.menuContainerRef.current;

assert.equal(picker.querySelector('.rs-calendar-header-title-time').innerText, '01:00:00');

ReactTestUtils.Simulate.click(picker.querySelector('.rs-calendar-time-dropdown-cell'));

assert.equal(picker.querySelector('.rs-calendar-header-meridian').innerText, 'PM');
assert.equal(picker.querySelector('.rs-calendar-header-title-time').innerText, '12:00:00');
});
});

1 comment on commit 1e67b89

@vercel
Copy link

@vercel vercel bot commented on 1e67b89 Aug 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

rsuite – ./docs

rsuitejs.com
rsuite.vercel.app
rsuite-git-v4-rsuite.vercel.app
rsuite-rsuite.vercel.app

Please sign in to comment.