fix: null value tooltip (#22482)

This commit is contained in:
二货机器人 2020-03-22 11:18:35 +08:00 committed by GitHub
parent 66e53fb91d
commit 4e270e1873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -87,4 +87,10 @@ describe('Slider', () => {
await sleep(20); await sleep(20);
expect(wrapper.find('Tooltip').instance().tooltip.forcePopupAlign).toHaveBeenCalled(); expect(wrapper.find('Tooltip').instance().tooltip.forcePopupAlign).toHaveBeenCalled();
}); });
it('tipFormatter should not crash with undefined value', () => {
[undefined, null].forEach(value => {
mount(<Slider value={value} tooltipVisible />);
});
});
}); });

View File

@ -64,7 +64,7 @@ export interface SliderState {
export default class Slider extends React.Component<SliderProps, SliderState> { export default class Slider extends React.Component<SliderProps, SliderState> {
static defaultProps = { static defaultProps = {
tipFormatter(value: number) { tipFormatter(value: number) {
return value.toString(); return typeof value === 'number' ? value.toString() : '';
}, },
}; };