From 6b58fd3055c4d35ed3ab9806afac183214f3722b Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Wed, 8 May 2019 11:38:42 +0200 Subject: [PATCH] Don't split words on non-breaking space char Currency strings output by Number.toLocaleString, for example, can contain non-breaking space characters. The emitted SVG tspan elements should not be split by these characters. --- packages/vx-text/src/Text.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vx-text/src/Text.js b/packages/vx-text/src/Text.js index cdee2483d..6b91ab67b 100644 --- a/packages/vx-text/src/Text.js +++ b/packages/vx-text/src/Text.js @@ -25,7 +25,7 @@ class Text extends Component { // Only perform calculations if using features that require them (multiline, scaleToFit) if (props.width || props.scaleToFit) { if (needCalculate) { - const words = props.children ? props.children.toString().split(/\s+/) : []; + const words = props.children ? props.children.toString().split(/(?:(?!\u00A0+)\s+)/) : []; this.wordsWithComputedWidth = words.map(word => ({ word, @@ -46,7 +46,7 @@ class Text extends Component { } updateWordsWithoutCalculate(props) { - const words = props.children ? props.children.toString().split(/\s+/) : []; + const words = props.children ? props.children.toString().split(/(?:(?!\u00A0+)\s+)/) : []; this.setState({ wordsByLines: [{ words }] }); }