Skip to content

Commit

Permalink
fix: edge case where suffix is a node (#646)
Browse files Browse the repository at this point in the history
* fix: suffix being node edge case

* docs(abbreviation): make examples better

* test(abbr suffix): fix tests

* style: removed out commented ugly if
  • Loading branch information
JacobBlomgren committed Oct 4, 2018
1 parent 9a9d5fe commit 6f93da2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/currency/currency.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Basic examples:
/>
</span>
<span style={{marginRight: '2rem'}} title="Million abbreviation for large values">
<Currency value={9200000} currency="EUR" abbreviation="million"/>
<Currency value={9200000} currency="SEK" abbreviation="million"/>
</span>
</div>

Expand Down
8 changes: 7 additions & 1 deletion src/components/number/number.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ function NumberComponent({
const ariaSign = value < 0 ? '−' : '';
const sign = value < 0 ? <span dangerouslySetInnerHTML={{ __html: '&ndash; ' }} /> : null;

const suffix = (rawSuffix || abbreviation) && `${abbreviationSuffix}${rawSuffix || ''}`;
const suffix = (rawSuffix || abbreviation) && (
<React.Fragment>
{abbreviationSuffix}
{rawSuffix || ''}
</React.Fragment>
);

return (
<span title={formattedNumber} {...rest} className={classes} style={styles}>
<Addon addon={prefix} className={prefixClass} position="left" separator={prefixSeparator} style={prefixStyle} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/value/value.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Simple examples:
<Value useDashForInvalidValues value={ Number.NEGATIVE_INFINITY } />
</span>
<span style={{marginRight: '2rem'}} title="Abbreviations">
<Value value={ -1.4444 } abbreviation="million"/>
<Value value={ 1420000 } abbreviation="million"/>
</span>
</div>

Expand Down
14 changes: 12 additions & 2 deletions test/components/number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ describe('<Number />', () => {
it('should be possible to add a suffix', () => {
const suffix = '987654321';
const component = shallow(<Number.WrappedComponent intl={intl} value={1} suffix={suffix} />);
expect(component.find('Addon[position="right"]').prop('addon')).to.equal(suffix);
expect(
component
.find('Addon[position="right"]')
.render()
.text(),
).to.equal(suffix);
});

it('should be possible to add a prefix and a suffix', () => {
Expand Down Expand Up @@ -265,7 +270,12 @@ describe('<Number />', () => {
it('should add M abbreviation suffix for million', () => {
const suffix = 'SEK';
const component = shallow(<Number.WrappedComponent intl={intl} value={9} suffix={suffix} abbreviation="million" />);
expect(component.find('Addon[position="right"]').prop('addon')).to.equal(`M${suffix}`);
expect(
component
.find('Addon[position="right"]')
.render()
.text(),
).to.equal(`M${suffix}`);
});

it('should transform 10,000,000 to 10 M', () => {
Expand Down

0 comments on commit 6f93da2

Please sign in to comment.