Skip to content

Commit

Permalink
fix(Timepicker): Can`t select last time
Browse files Browse the repository at this point in the history
  • Loading branch information
myronliu347 committed Jul 25, 2019
1 parent b193dad commit 40b9f46
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
55 changes: 33 additions & 22 deletions src/time-picker/module/time-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,43 +71,54 @@ class TimeMenu extends React.Component {
this.menu = ref;
};

render() {
createTimeMenuItem = index => {
const {
prefix,
title,
mode,
activeIndex,
step,
disabled,
disabledItems,
onSelect,
} = this.props;
const isDisabled = disabled || disabledItems(index);
const itemCls = classnames({
[`${prefix}time-picker-menu-item`]: true,
[`${prefix}disabled`]: isDisabled,
[`${prefix}selected`]: index === activeIndex,
});
const handleClick = isDisabled ? noop : () => onSelect(index, mode);

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
<li
role="option"
aria-selected={String(index === activeIndex)}
key={index}
title={index}
className={itemCls}
onClick={handleClick}
>
{index}
</li>
);
};

render() {
const { prefix, title, mode, step } = this.props;
const total = mode === 'hour' ? 24 : 60;
const list = [];
let last = 0;
for (let i = 0; i < total; i++) {
if (i % step === 0) {
const isDisabled = disabled || disabledItems(i);
const itemCls = classnames({
[`${prefix}time-picker-menu-item`]: true,
[`${prefix}disabled`]: isDisabled,
[`${prefix}selected`]: i === activeIndex,
});
const onClick = isDisabled ? noop : () => onSelect(i, mode);
list.push(
<li
role="option"
aria-selected={String(i === activeIndex)}
key={i}
title={i}
className={itemCls}
onClick={onClick}
>
{i}
</li>
);
last = i;
list.push(this.createTimeMenuItem(i));
}
}

if (last < total - 1) {
list.push(this.createTimeMenuItem(total - 1));
}

const menuTitle = title ? (
<div className={`${prefix}time-picker-menu-title`}>{title}</div>
) : null;
Expand Down
2 changes: 1 addition & 1 deletion test/time-picker/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('TimePicker', () => {
assert(
wrapper.find(
'.next-time-picker-menu-second .next-time-picker-menu-item'
).length === 12
).length === 13
);
});
});
Expand Down

0 comments on commit 40b9f46

Please sign in to comment.