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

WETGPCII-2788-trailing-decimal-truncation #3221

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -63,7 +63,7 @@ describe('Mask', function () {
const input = screen.getByRole('textbox');
expect(input.classList).toContain('ds-c-field--currency');
expect(input).toHaveAttribute('type', 'text');
expect(input).toHaveAttribute('pattern', '[0-9.,-]*');
expect(input).toHaveAttribute('pattern', '[0-9\\.\\,\\-]*');
expect(input).toHaveAttribute('inputmode', 'numeric');
});

Expand Down
8 changes: 6 additions & 2 deletions packages/design-system/src/components/TextField/Mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const maskPattern = {
phone: '[0-9-]*',
ssn: '[0-9-*]*',
zip: '[0-9-]*',
currency: '[0-9.,-]*',
currency: '[0-9\\.\\,\\-]*',
};

const maskOverlayContent = {
Expand Down Expand Up @@ -87,7 +87,7 @@ export class Mask extends PureComponent<MaskProps, any> {
* @param {React.Element} field - Child TextField
*/
handleBlur(evt: React.ChangeEvent<HTMLInputElement>, field: React.ReactElement): void {
const value = maskValue(evt.target.value, this.props.mask);
const value = (evt.target.value = maskValue(evt.target.value, this.props.mask));

// We only debounce the onBlur when we know for sure that
// this component will re-render (AKA when the value changes)
Expand All @@ -103,6 +103,10 @@ export class Mask extends PureComponent<MaskProps, any> {
this.debouncedOnBlurEvent = evt;
}

if (typeof field.props.onChange === 'function') {
field.props.onChange(evt);
}

this.setState({
value,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ const ControlledTemplate: Story = {
// controlled or uncontrolled. The TextField itself is always controlled by our story,
// but whether this story is controlled by args depends on whether the user has
// supplied a new value of the `value` arg to this story.
const [localValue, setLocalValue] = useState();
const [localValue, setLocalValue] = useState<string>('');
const value = args.value ?? localValue ?? '';
const onChange = (event) => {
const onChange = (event: React.FormEvent<HTMLInputElement>) => {
action('onChange')(event);
setLocalValue(event.currentTarget.value);
};
Expand Down Expand Up @@ -105,6 +105,20 @@ const disabledArg = {
},
};

export const MaskedCurrency: Story = {
...ControlledTemplate,
args: {
name: 'mask-currency',
label: 'Enter your estimated yearly income.',
hint: 'This should be a dollar amount.',
mask: 'currency',
numeric: true,
},
argTypes: {
mask: disabledArg,
},
};

export const AllMaskedFields: Story = {
argTypes: {
labelMask: disabledArg,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.