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: get correct regular expression to sharing 'format' and 'customNumerals' props #594

Merged
merged 4 commits into from
Dec 1, 2021
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: 2 additions & 2 deletions src/number_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class NumberFormat extends React.Component {
}
}

return (numStr.match(/\d/g) || []).join('');
return (numStr.match(this.getNumberRegex(true)) || []).join('');
}

removeFormatting(val: string) {
Expand All @@ -442,7 +442,7 @@ class NumberFormat extends React.Component {
//condition need to be handled if format method is provide,
val = removeFormatting(val);
} else {
val = (val.match(/\d/g) || []).join('');
val = (val.match(this.getNumberRegex(true)) || []).join('');
}
return val;
}
Expand Down
12 changes: 12 additions & 0 deletions test/library/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ describe('NumberFormat as input', () => {
expect(wrapper.state().value).toEqual('1234567890');
});

it('should accept and format custom numerals together with format input field', () => {
const wrapper = mount(
<NumberFormat
customNumerals={['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']}
format="##########"
/>,
);
simulateKeyInput(wrapper.find('input'), '۱۲۳۴۵۶۷۸۹۰', 0);

expect(wrapper.state().value).toEqual('1234567890');
});

it('should render input as type text by default', () => {
const wrapper = mount(<NumberFormat />);
expect(wrapper.find('input').instance().getAttribute('type')).toEqual('text');
Expand Down