Skip to content

Commit

Permalink
fix(TimePicker2): use props.format to validate value, close #3651 (#4803
Browse files Browse the repository at this point in the history
)

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

* feat(TimePicker2): test case modification
  • Loading branch information
YunMeng99 authored Apr 3, 2024
1 parent 66437cd commit aac4730
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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')
);
});
});
});

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

0 comments on commit aac4730

Please sign in to comment.