Skip to content

Commit 7fb68ed

Browse files
victorghJoren Broekema
authored andcommitted
fix(input-amount): pass string instead of object in parser
1 parent 41e12da commit 7fb68ed

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/input-amount/src/parsers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ function getParseMode(value) {
6060
* @param {object} options Locale Options
6161
*/
6262
function parseWithLocale(value, options) {
63-
const separator = getDecimalSeparator(options);
63+
const locale = options && options.locale ? options.locale : null;
64+
const separator = getDecimalSeparator(locale);
6465
const regexNumberAndLocaleSeparator = new RegExp(`[0-9${separator}-]`, 'g');
6566
let numberAndLocaleSeparator = value.match(regexNumberAndLocaleSeparator).join('');
6667
if (separator === ',') {

packages/input-amount/test/parsers.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,17 @@ describe('parseAmount()', () => {
145145
it('returns undefined when value is empty string', () => {
146146
expect(parseAmount('')).to.equal(undefined);
147147
});
148+
149+
it('parseAmount with locale set and length is more than four', () => {
150+
expect(
151+
parseAmount('6,000', {
152+
locale: 'gb-GB',
153+
}),
154+
).to.equal(6000);
155+
expect(
156+
parseAmount('6.000', {
157+
locale: 'es-ES',
158+
}),
159+
).to.equal(6000);
160+
});
148161
});

0 commit comments

Comments
 (0)