From 011eeed5205e9238012807776e61f092e0c0be1a Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Wed, 28 Jun 2023 13:27:44 -0700 Subject: [PATCH 1/2] Support setting prefix to an empty string --- src/components/CurrencyInput.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/CurrencyInput.tsx b/src/components/CurrencyInput.tsx index ce8aa8d..8c4acae 100644 --- a/src/components/CurrencyInput.tsx +++ b/src/components/CurrencyInput.tsx @@ -89,7 +89,7 @@ export const CurrencyInput: FC = forwardRef< groupSeparator, disableGroupSeparators, intlConfig, - prefix: prefix || localeConfig.prefix, + prefix: prefix ?? localeConfig.prefix, suffix: suffix, }; @@ -100,7 +100,7 @@ export const CurrencyInput: FC = forwardRef< decimalsLimit: decimalsLimit || fixedDecimalLength || 2, allowNegativeValue, disableAbbreviations, - prefix: prefix || localeConfig.prefix, + prefix: prefix ?? localeConfig.prefix, transformRawValue, }; From 03cd5f5cf1f8120c2debc3b06cade535fa9d3162 Mon Sep 17 00:00:00 2001 From: Benjamin Piouffle Date: Thu, 24 Apr 2025 09:08:48 +0200 Subject: [PATCH 2/2] test: add case for empty prefix/suffix --- .../__tests__/CurrencyInput-suffix.spec.tsx | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/components/__tests__/CurrencyInput-suffix.spec.tsx b/src/components/__tests__/CurrencyInput-suffix.spec.tsx index 414cc8d..0347edb 100644 --- a/src/components/__tests__/CurrencyInput-suffix.spec.tsx +++ b/src/components/__tests__/CurrencyInput-suffix.spec.tsx @@ -44,4 +44,41 @@ describe(' suffix', () => { expect(screen.getByRole('textbox')).toHaveValue('$1,234.9 %'); }); + + it('should handle empty prefix and suffix', () => { + render( + + ); + + expect(screen.getByRole('textbox')).toHaveValue('1,234'); + + userEvent.type(screen.getByRole('textbox'), '56'); + + expect(screen.getByRole('textbox')).toHaveValue('123,456'); + + userEvent.type(screen.getByRole('textbox'), '{backspace}{backspace}'); + + expect(screen.getByRole('textbox')).toHaveValue('1,234'); + }); + + it('should fallback to default prefix and suffix when undefined', () => { + render( + + ); + + expect(screen.getByRole('textbox')).toHaveValue('1,234'); + + userEvent.type(screen.getByRole('textbox'), '56'); + + expect(screen.getByRole('textbox')).toHaveValue('123,456'); + + userEvent.type(screen.getByRole('textbox'), '{backspace}{backspace}'); + + expect(screen.getByRole('textbox')).toHaveValue('1,234'); + }); });