Skip to content

Commit

Permalink
chore(Number): document percentage and add test (#3085)
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker authored Dec 15, 2023
1 parent 7b83a7a commit cb89fa4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ export const ValidateMinimum = () => {
)
}

export const Percentage = () => {
return (
<ComponentBox>
<Field.Number
value={80}
label="Percentage"
onChange={(value) => console.log('onChange', value)}
minimum={90}
/>
</ComponentBox>
)
}

export const ValidateMaximumCustomError = () => {
return (
<ComponentBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ import * as Examples from './Examples'
### Validation - Maximum and custom error message

<Examples.ValidateMaximumCustomError />

### Percentage

<Examples.Percentage />
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import DataValueReadwriteProperties from '../../data-value-readwrite-properties.
| `decimalSymbol` | `string` | _(optional)_ What character to use for separating digits and decimals. Defaults to ','. |
| `decimals` | `number` | _(optional)_ Max number of decimals. Values with more decimals will be rounded. |
| `fixedDecimals` | `number` | _(optional)_ Fixed number of decimals. Will round numbers with more decimals, and add trailing zeros when less. |
| `percent` | `boolean` | _(optional)_ Format a number as percentage. |
| `prefix` | `string` | _(optional)_ Text added before the value input. |
| `suffix` | `string` | _(optional)_ Text added after the value input. |
| `minimum` | `number` | _(optional)_ Validation for inclusive minimum number value (greater than or equal). |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ describe('Field.Number', () => {
expect(screen.getByDisplayValue('97531:2468')).toBeInTheDocument()
})

it('formats with percent', () => {
render(<Field.Number value={12345} percent />)
expect(document.querySelector('input').value).toBe('12 345 %')
})

it('formats with same decimal limit', () => {
render(<Field.Number value={42.51} decimalLimit={2} />)
expect(screen.getByDisplayValue('42,51')).toBeInTheDocument()
Expand Down

0 comments on commit cb89fa4

Please sign in to comment.