Skip to content

Commit

Permalink
fix(InputMasked): handle initial empty string value
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Nov 16, 2021
1 parent 2b61dc7 commit 70c5fd8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,7 @@ export const correctNumberValue = ({
value = localValue
}

if (
localNumberValue === ''
// TODO: Not sure if we need this check
// String(value).replace(/[^\d]/g, '') === '0'
) {
if (localNumberValue === '' && numberValue === '0') {
value = ''
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/dnb-eufemia/src/components/input-masked/TextMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export default class TextMask extends React.PureComponent {
isPipeChanged

// Сalculate that value was changed
const isValueChanged = value !== this.inputRef.current.value
const isValueChanged =
value !== this.inputRef.current.value || prevProps.value !== value

// Check value and settings to prevent duplicating update() call
if (isValueChanged || isSettingChanged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ describe('InputMasked component', () => {
expect(Comp.find('input').instance().value).toBe('NOK 0 012,01 kr')
})

it('should update value when initial value was an empty string', () => {
const Comp = mount(<Component value="" number_mask />)

expect(Comp.find('input').instance().value).toBe('')

Comp.setProps({ value: 1234 })

expect(Comp.find('input').instance().value).toBe('1 234')
})

it('should update value when value has leading zero', () => {
const Comp = mount(
<Component
Expand Down

0 comments on commit 70c5fd8

Please sign in to comment.