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

fix(TimePicker2): should support custom formatting close ##3651 #4803

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions components/time-picker2/__tests__/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,21 @@ describe('TimePicker2', () => {
done();
}, 1000);
});

it('should support custom formatting , close #3651', () => {
const div = document.createElement('div');
document.body.appendChild(div);
const wrapper = mount(<TimePicker2 format="HH" />, { attachTo: div });
wrapper
.find('.next-time-picker2-input input')
.simulate('change', { target: { value: '12' } });
wrapper.update();
assert(
document
.querySelector('li[title="12"][role="option"]')
.classList.contains('next-selected')
);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

用例内容与用户实际问题不符,用户的问题是 type "12" 不能选中 12 那一项,一定要 type "12:00:00" 才能匹配 12 那一项

});
});

Expand Down
7 changes: 4 additions & 3 deletions components/time-picker2/time-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,12 @@ class TimePicker2 extends Component {

checkValue = (value, strictly) => {
const { inputType } = this.state;
const formatter = v => (typeof v === 'string' ? datejs(v, 'HH:mm:ss') : v);
const { format, type, disabled } = this.props;
const formatter = v => (typeof v === 'string' ? datejs(v, format) : v);
const formattedValue = Array.isArray(value) ? value.map(v => formatter(v)) : formatter(value);

return this.props.type === TIME_PICKER_TYPE.RANGE
? checkRangeDate(formattedValue, inputType, this.props.disabled, strictly)
return type === TIME_PICKER_TYPE.RANGE
? checkRangeDate(formattedValue, inputType, disabled, strictly)
: checkDate(formattedValue);
};

Expand Down
Loading