From 4e270e187389e02e8feeb15c55a324c917014d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Sun, 22 Mar 2020 11:18:35 +0800 Subject: [PATCH] fix: null value tooltip (#22482) --- components/slider/__tests__/index.test.js | 6 ++++++ components/slider/index.tsx | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/components/slider/__tests__/index.test.js b/components/slider/__tests__/index.test.js index 17e7ffa827..504346a09e 100644 --- a/components/slider/__tests__/index.test.js +++ b/components/slider/__tests__/index.test.js @@ -87,4 +87,10 @@ describe('Slider', () => { await sleep(20); expect(wrapper.find('Tooltip').instance().tooltip.forcePopupAlign).toHaveBeenCalled(); }); + + it('tipFormatter should not crash with undefined value', () => { + [undefined, null].forEach(value => { + mount(); + }); + }); }); diff --git a/components/slider/index.tsx b/components/slider/index.tsx index 1c7248f7bd..d0d905d862 100644 --- a/components/slider/index.tsx +++ b/components/slider/index.tsx @@ -64,7 +64,7 @@ export interface SliderState { export default class Slider extends React.Component { static defaultProps = { tipFormatter(value: number) { - return value.toString(); + return typeof value === 'number' ? value.toString() : ''; }, };