Skip to content

Commit d7dcc55

Browse files
chore: Improve demo content in Text Input examples (#2157)
Co-authored-by: alimpens <[email protected]> Co-authored-by: Aram <[email protected]>
1 parent 966a9f5 commit d7dcc55

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

storybook/src/components/TextInput/TextInput.docs.mdx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,30 @@ We follow the advice against using `type="number"` by [NL Design System](https:/
9696

9797
### Size
9898

99-
The size of the input should be appropriate for the information to be entered.
100-
Use the `size` attribute to set the right size.
99+
Make the width of the input appropriate for the information to be entered.
100+
Use the `size` attribute for this.
101+
102+
Avoid making it too narrow – ensure the user has enough space to operate comfortably.
103+
This also gives browsers or extensions an opportunity to add an icon or button at the end.
104+
105+
We suggest a size of 15 for a phone number, 30 for an e-mail address, 40 for a web address, and 7 for a postal code.
101106

102107
<Canvas of={TextInputStories.Size} />
103108

104109
### Placeholder
105110

106-
This text appears in the field when it is empty. It can give a brief hint about the kind of data to enter.
111+
We advise against placing a placeholder in an input field.
112+
113+
This text would only appear in the field when it is empty, which instead may make it appear filled in.
114+
Even more so, the text disappears immediately after the user starts typing, which means they are no longer able to check whether their input matches the suggestions.
115+
Thirdly, their usual grey colour is often difficult to read.
107116

108-
Don’t try too hard to find a suitable text for a placeholder.
109-
Inputs without placeholder text are just fine – the label and a description should be clear enough.
110-
Do not use a placeholder instead of a [Label](/docs/components-forms-label--docs).
117+
Inputs without placeholder text are just fine.
118+
Any text that you consider for a placeholder can be included in the description.
111119

112-
Follow the [guidelines for placeholder text](https://www.nldesignsystem.nl/richtlijnen/formulieren/placeholders) by NL Design System.
120+
See also the [guidelines for placeholder text](https://www.nldesignsystem.nl/richtlijnen/formulieren/placeholders) by NL Design System, and [the advice to avoid them](https://design-system.service.gov.uk/components/text-input/#avoid-placeholder-text) by GOV UK.
113121

114-
<Canvas of={TextInputStories.Placeholder} />
122+
In case third party applications does use placeholders, the component does apply the correct font and colour to them.
115123

116124
### Invalid
117125

@@ -166,4 +174,4 @@ Check [the Field docs](/docs/components-forms-field--docs) for more information
166174
## Further reading
167175

168176
- Extensive [guidelines for all types of input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text) on Mozilla Developer Network.
169-
- An overview of [suitable metadata for various kinds of content](https://nl-design-system.github.io/utrecht/storybook/?path=/docs/react_react-textbox--docs) to be entered by Gemeente Utrecht.
177+
- At the same site, an overview of [autocompletion values](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/autocomplete#token_list_tokens) which help enter personal details faster.

storybook/src/components/TextInput/TextInput.stories.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
*/
55

66
import { ErrorMessage, Field, Label, Paragraph } from '@amsterdam/design-system-react'
7+
import { textInputTypes } from '@amsterdam/design-system-react/dist/TextInput/TextInput'
78
import { TextInput } from '@amsterdam/design-system-react/src'
89
import { Meta, StoryObj } from '@storybook/react-vite'
910

1011
const meta = {
1112
title: 'Components/Forms/Text Input',
1213
component: TextInput,
1314
args: {
15+
defaultValue: 'Amsterdam',
1416
disabled: false,
1517
invalid: false,
1618
},
@@ -28,6 +30,13 @@ const meta = {
2830
control: { min: 0, type: 'number' },
2931
description: 'The width, expressed in the average number of characters.',
3032
},
33+
type: {
34+
control: {
35+
labels: { undefined: 'text (default)' },
36+
type: 'radio',
37+
},
38+
options: [undefined, ...textInputTypes.filter((type) => type !== 'text')],
39+
},
3140
},
3241
} satisfies Meta<typeof TextInput>
3342

@@ -40,27 +49,30 @@ export const Default: Story = {}
4049
export const EmailAddress: Story = {
4150
args: {
4251
defaultValue: '[email protected]',
52+
size: 30,
4353
type: 'email',
4454
},
4555
}
4656

4757
export const WebAddress: Story = {
4858
args: {
4959
defaultValue: 'https://designsystem.amsterdam/',
60+
size: 40,
5061
type: 'url',
5162
},
5263
}
5364

5465
export const PhoneNumber: Story = {
5566
args: {
5667
defaultValue: '14020',
68+
size: 15,
5769
type: 'tel',
5870
},
5971
}
6072

6173
export const WholeNumber: Story = {
6274
args: {
63-
defaultValue: '1',
75+
defaultValue: '20',
6476
inputMode: 'numeric',
6577
pattern: '[0-9]*',
6678
size: 5,
@@ -70,7 +82,7 @@ export const WholeNumber: Story = {
7082

7183
export const DecimalNumber: Story = {
7284
args: {
73-
defaultValue: '1.99',
85+
defaultValue: '12.75',
7486
pattern: '[0-9.,]*',
7587
size: 5,
7688
spellCheck: false,
@@ -79,31 +91,29 @@ export const DecimalNumber: Story = {
7991

8092
export const Size: Story = {
8193
args: {
82-
size: 10,
83-
},
84-
}
85-
86-
export const Placeholder: Story = {
87-
args: {
88-
placeholder: 'Placeholder text',
94+
defaultValue: '1011 PN',
95+
size: 7,
8996
},
9097
}
9198

9299
export const Invalid: Story = {
93100
args: {
94-
defaultValue: 'Invalid value',
101+
defaultValue: 'Deze waarde is ongeldig',
95102
invalid: true,
96103
},
97104
}
98105

99106
export const Disabled: Story = {
100107
args: {
101-
defaultValue: 'Disabled input',
108+
defaultValue: 'Deze waarde kan niet veranderd worden',
102109
disabled: true,
103110
},
104111
}
105112

106113
export const InAField: Story = {
114+
args: {
115+
defaultValue: '',
116+
},
107117
render: (args) => (
108118
<Field invalid={args.invalid}>
109119
<Label htmlFor="input1">Label</Label>
@@ -116,6 +126,7 @@ export const InAField: Story = {
116126

117127
export const InAFieldWithValidation: Story = {
118128
args: {
129+
defaultValue: '',
119130
invalid: true,
120131
},
121132
render: (args) => (

0 commit comments

Comments
 (0)