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

feat(TextInput): add note on type="number" attribute #1120

Merged
merged 3 commits into from
Apr 14, 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
5 changes: 5 additions & 0 deletions .changeset/honest-socks-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@razorpay/blade": patch
---

feat(TextInput): add note on `type="number"` attribute
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,23 @@ export const TextInput = TextInputTemplate.bind({});
// Need to do this because of storybook's weird naming convention, More details here: https://storybook.js.org/docs/react/writing-stories/naming-components-and-hierarchy#single-story-hoisting
TextInput.storyName = 'TextInput';

export const TextInputTypeNumber = TextInputTemplate.bind({});
TextInputTypeNumber.storyName = 'TextInput with type number';
TextInputTypeNumber.args = {
type: 'number',
label: 'Enter Number',
placeholder: 'Enter any random number',
};

// @ts-expect-error: Just another undocumented, untyped storybook property ;__;
TextInputTypeNumber.story = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dude how do you even find such properties? What is this sorcery?

Also, hope its not crashing on react native as some unsupported property or something 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dude how do you even find such properties? What is this sorcery?

Lol github issue comments ftw storybookjs/storybook#8527 (comment)

Also, hope its not crashing on react native as some unsupported property or something 🙈

My XCode asking me to reinstall and that is failing lol so can't check. Hopefully it won't since Component.anything = {} is fair assignment 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok finally xcode worked. checked the story its working.

parameters: {
docs: {
storyDescription: `You might notice that type number allows you to enter other characters as well. That's because instead of setting type number internally, we prefer inputMode numeric. Checkout this article for the reasoning - <b><a href="https://technology.blog.gov.uk/2020/02/24/why-the-gov-uk-design-system-team-changed-the-input-type-for-numbers/">Why the GOV.UK Design System team changed the input type for numbers</a></b> \n\nIf you have a usecase of only allowing number in field, you can handle that on validations end.`,
},
},
};

export const TextInputHelpText = TextInputTemplate.bind({});
TextInputHelpText.storyName = 'TextInput with Help Text';
TextInputHelpText.args = {
Expand Down
8 changes: 8 additions & 0 deletions packages/blade/src/components/Input/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ type TextInputProps = Pick<
/**
* Type of Input Field to be rendered. Use `PasswordInput` for type `password`
*
*
* **Note on number type**
*
* `type="number"` internally uses `inputMode="numeric"` instead of HTML's `type="number"` which also allows text characters.
* If you have a usecase where you only want to support number input, you can handle it on validations end.
*
* Check out [Why the GOV.UK Design System team changed the input type for numbers](https://technology.blog.gov.uk/2020/02/24/why-the-gov-uk-design-system-team-changed-the-input-type-for-numbers/) for reasoning
*
* @default text
*/
type?: Type;
Expand Down