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(APP-3978): Fix InputNumber component so that it properly handles decimals when there is a default values set #410

Merged
merged 4 commits into from
Feb 21, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- Fix `InputNumber` core component so that it properly handles decimals when there is a default values set

## [1.0.67] - 2025-02-18

### Changed
Expand Down
18 changes: 0 additions & 18 deletions src/core/components/forms/hooks/useNumberMask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,4 @@ describe('useNumberMask hook', () => {
onAccept?.('', maskValue);
expect(onChange).toHaveBeenCalledWith(maskValue.unmaskedValue);
});

it('updates the lazy option to force displaying the mask pattern when new value is not empty', () => {
const onChange = jest.fn();
const maskValue = { unmaskedValue: '1', updateOptions: jest.fn() } as unknown as InputMask;
renderHook(() => useNumberMask({ onChange }));
const { onAccept } = maskMock.mock.calls[0][1] ?? {};
onAccept?.('', maskValue);
expect(maskValue.updateOptions).toHaveBeenCalledWith({ lazy: false });
});

it('updates the lazy option to hide the mask pattern when new value is empty', () => {
const onChange = jest.fn();
const maskValue = { unmaskedValue: '', updateOptions: jest.fn() } as unknown as InputMask;
renderHook(() => useNumberMask({ onChange }));
const { onAccept } = maskMock.mock.calls[0][1] ?? {};
onAccept?.('', maskValue);
expect(maskValue.updateOptions).toHaveBeenCalledWith({ lazy: true });
});
});
4 changes: 1 addition & 3 deletions src/core/components/forms/hooks/useNumberMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ export const useNumberMask = (props: IUseNumberMaskProps): IUseNumberMaskResult
const maskMin = min != null ? Number(min) : undefined;

const handleMaskAccept = (_value: string, mask: InputMask<FactoryOpts>) => {
// Update the lazy option to display the suffix when the user is deleting the last digits of the input
const hideMask = mask.unmaskedValue === '';
mask.updateOptions({ lazy: hideMask });
onChange?.(mask.unmaskedValue);
};

const result = useIMask<HTMLInputElement>(
{
lazy: false,
mask: numberMask,
eager: true, // Displays eventual suffix on user input
blocks: {
Expand Down