Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NumberMask): as_number should default to locally given decimalSymbol #2810

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {
isTrue,
dispatchCustomElementEvent,
extendPropsWithContext,
} from '../../shared/component-helper'
import { safeSetSelection } from './text-mask/createTextMaskInputElement'

Expand Down Expand Up @@ -482,21 +483,19 @@ const useNumberMaskParams = () => {
const decimalSymbol = handleDecimalSeparator(locale)

if (isTrue(as_number) || isTrue(as_percent)) {
number_mask = {
number_mask = extendPropsWithContext(number_mask, null, {
decimalSymbol,
thousandsSeparatorSymbol,
...number_mask,
}
})
} else if (as_currency) {
currency_mask = {
currency_mask = extendPropsWithContext(currency_mask, null, {
decimalSymbol,
thousandsSeparatorSymbol,
currency: getCurrencySymbol(
locale,
typeof as_currency === 'string' ? as_currency : null
),
...currency_mask,
}
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,36 @@ describe('InputMasked component as_number', () => {
expect(document.querySelector('input').value).toBe('12 345,6')
})

it('will not overwrite decimalSymbol when undefined was given', () => {
const { rerender } = render(
<InputMasked
value={12345.678}
as_number
number_mask={{
thousandsSeparatorSymbol: '|',
decimalSymbol: ':',
allowDecimal: true,
}}
/>
)

expect(document.querySelector('input').value).toBe('12|345:67')

rerender(
<InputMasked
value={12345.678}
as_number
number_mask={{
thousandsSeparatorSymbol: undefined,
decimalSymbol: undefined,
allowDecimal: true,
}}
/>
)

expect(document.querySelector('input').value).toBe('12 345,67')
})

it('should merge "mask_options" properties', () => {
render(
<InputMasked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function NumberComponent(props: Props) {
percent,
mask,
thousandSeparator,
decimalSymbol = ',',
decimalSymbol,
tujoworker marked this conversation as resolved.
Show resolved Hide resolved
decimalLimit = 12,
prefix,
suffix,
Expand Down
Loading