From 9f9855124f917382a3b93cb4c3a3f9d251a081ee Mon Sep 17 00:00:00 2001 From: Ilaria Venturini Date: Sat, 26 Sep 2020 22:57:56 +0200 Subject: [PATCH] fix(demo/text): render 0 as number (#813) --- packages/visx-text/src/Text.tsx | 4 ++-- packages/visx-text/test/Text.test.tsx | 10 ++++++++++ yarn.lock | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/visx-text/src/Text.tsx b/packages/visx-text/src/Text.tsx index 6022b3fff..23f6c5a60 100644 --- a/packages/visx-text/src/Text.tsx +++ b/packages/visx-text/src/Text.tsx @@ -115,7 +115,7 @@ class Text extends React.Component { // Only perform calculations if using features that require them (multiline, scaleToFit) if (props.width || props.scaleToFit) { if (needCalculate) { - const words: string[] = props.children + const words: string[] = (props.children !== null && props.children !== undefined) ? props.children.toString().split(/(?:(?!\u00A0+)\s+)/) : []; @@ -138,7 +138,7 @@ class Text extends React.Component { } updateWordsWithoutCalculate(props: TextProps) { - const words = props.children ? props.children.toString().split(/(?:(?!\u00A0+)\s+)/) : []; + const words = (props.children !== null && props.children !== undefined) ? props.children.toString().split(/(?:(?!\u00A0+)\s+)/) : []; this.setState({ wordsByLines: [{ words }] }); } diff --git a/packages/visx-text/test/Text.test.tsx b/packages/visx-text/test/Text.test.tsx index 412df2a5f..fe6ba7762 100644 --- a/packages/visx-text/test/Text.test.tsx +++ b/packages/visx-text/test/Text.test.tsx @@ -101,4 +101,14 @@ describe('', () => { expect(wrapperNan.text()).not.toContain('anything'); }); + + it("Render text when children 0 is a number", () => { + const wrapper = mount( + + {0} + , + ); + + expect(wrapper.text()).toContain('0'); + }); }); diff --git a/yarn.lock b/yarn.lock index 3a0b07457..75e492a07 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5241,6 +5241,11 @@ d3-array@1, d3-array@^1.1.1, d3-array@^1.2.0: resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-2.4.0.tgz#87f8b9ad11088769c82b5ea846bcb1cc9393f242" integrity sha512-KQ41bAF2BMakf/HdKT865ALd4cgND6VcIztVQZUTt0+BH3RWy6ZYnHghVXf6NFjt2ritLr8H1T8LreAAlfiNcw== +d3-array@2.6.0: + version "2.6.0" + resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-2.6.0.tgz#b8df0c695eab26e2b2fd4ffe2d84bd703f8d0faf" + integrity sha512-1TgzIGb6hrHKSCGccdL209Ibk41HCeyv5znFEvJfBsBGhD3qpoHt/2W2ECpyLxpG1k7aNJz0BYrmLpVs9hIGNQ== + d3-chord@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/d3-chord/-/d3-chord-1.0.6.tgz#309157e3f2db2c752f0280fedd35f2067ccbb15f"