From b7c2e7254efd9075f1c74b84ae2a86c12b0bd35e Mon Sep 17 00:00:00 2001 From: Flaminia Cavallo Date: Wed, 4 Dec 2024 11:49:50 +0100 Subject: [PATCH 1/3] fix: allow zero as a value for input field --- components/input/src/input-field/input-field.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/input/src/input-field/input-field.js b/components/input/src/input-field/input-field.js index d9275dca1..169e7773a 100644 --- a/components/input/src/input-field/input-field.js +++ b/components/input/src/input-field/input-field.js @@ -66,7 +66,13 @@ class InputField extends React.Component { onChange={onChange} name={name} type={type} - value={value || ''} + value={ + value === null || + value === undefined || + Number.isNaN(value) + ? '' + : value + } placeholder={placeholder} disabled={disabled} max={max} From 963586aab5c275db53941facc3686d7bd4498c7b Mon Sep 17 00:00:00 2001 From: Flaminia Cavallo Date: Wed, 4 Dec 2024 12:07:10 +0100 Subject: [PATCH 2/3] fix: allow 0 as a value for input field --- .../input/src/input-field/__tests__/input-field.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/input/src/input-field/__tests__/input-field.test.js b/components/input/src/input-field/__tests__/input-field.test.js index 17f7d383e..51d717958 100644 --- a/components/input/src/input-field/__tests__/input-field.test.js +++ b/components/input/src/input-field/__tests__/input-field.test.js @@ -24,4 +24,12 @@ describe('', () => { expect(onKeyDown).toHaveBeenCalledTimes(1) }) + + it('should render a field with value zero', () => { + const screen = render( + + ) + + expect(screen.getByLabelText('label')).toHaveValue(0) + }) }) From c7006f47908f4a7ce1694eb64aa593dbe43caeb2 Mon Sep 17 00:00:00 2001 From: Flaminia Cavallo Date: Wed, 4 Dec 2024 13:46:43 +0100 Subject: [PATCH 3/3] fix: use nullish coalescing operatorin input field to check if value is given --- components/input/src/input-field/input-field.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/components/input/src/input-field/input-field.js b/components/input/src/input-field/input-field.js index 169e7773a..6eba9d99e 100644 --- a/components/input/src/input-field/input-field.js +++ b/components/input/src/input-field/input-field.js @@ -66,13 +66,7 @@ class InputField extends React.Component { onChange={onChange} name={name} type={type} - value={ - value === null || - value === undefined || - Number.isNaN(value) - ? '' - : value - } + value={value ?? ''} placeholder={placeholder} disabled={disabled} max={max}