Skip to content

Commit 40d0f8b

Browse files
Uplift GOV.UK Frontend text input component
1 parent 55d3f92 commit 40d0f8b

3 files changed

Lines changed: 246 additions & 70 deletions

File tree

packages/nhsuk-frontend/src/nhsuk/components/input/_index.scss

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
11
@use "../../core/settings" as *;
22
@use "../../core/tools" as *;
33
@use "../../core/helpers" as *;
4+
@forward "../error-message";
5+
@forward "../hint";
6+
@forward "../label";
47

58
////
69
/// Input component
710
///
8-
/// 1. Disable inner shadow and remove rounded corners
9-
/// 2. setting any background-color makes text invisible when changing colours to dark
10-
/// backgrounds in Firefox (https://bugzilla.mozilla.org/show_bug.cgi?id=1335476)
11-
/// as background-color and color need to always be set together, color should
12-
/// not be set either.
13-
///
1411
/// @group components/input
1512
////
1613

1714
@include nhsuk-exports("nhsuk/components/input") {
1815
.nhsuk-input {
19-
appearance: none; // [1]
20-
border: $nhsuk-border-width-form-element solid $nhsuk-input-border-colour; // [2]
21-
border-radius: 0;
2216
box-sizing: border-box;
23-
min-height: 40px;
17+
width: 100%;
18+
height: nhsuk-px-to-rem(40px);
2419
margin-top: 0;
2520
padding: nhsuk-spacing(1);
26-
width: 100%;
21+
// Setting any background-color makes text invisible when changing colours
22+
// to dark backgrounds in Firefox (https://bugzil.la/1335476). As
23+
// background-color and color need to always be set together, color should
24+
// not be set either
25+
border: $nhsuk-border-width-form-element solid $nhsuk-input-border-colour;
26+
border-radius: 0;
2727

28-
@include nhsuk-font(19);
28+
// Disable inner shadow and remove rounded corners
29+
appearance: none;
30+
31+
@include nhsuk-font($size: 19);
2932

3033
&:focus {
3134
@include nhsuk-focused-input;
3235
}
36+
37+
&:disabled {
38+
opacity: 0.5;
39+
color: inherit;
40+
background-color: transparent;
41+
cursor: not-allowed;
42+
}
3343
}
3444

3545
.nhsuk-input::-webkit-outer-spin-button,
3646
.nhsuk-input::-webkit-inner-spin-button {
37-
-webkit-appearance: none;
3847
margin: 0;
48+
-webkit-appearance: none;
3949
}
4050

4151
.nhsuk-input[type="number"] {
@@ -46,6 +56,10 @@
4656
border-color: $nhsuk-error-colour;
4757
}
4858

59+
.nhsuk-input--extra-letter-spacing {
60+
letter-spacing: 0.05em;
61+
}
62+
4963
// The ex measurements are based on the number of W's that can fit inside the input
5064
// Extra space is left on the right hand side to allow for the Safari prefill icon
5165
// Linear regression estimation based on visual tests: y = 1.76 + 1.81x
@@ -78,8 +92,6 @@
7892
max-width: 5.4ex;
7993
}
8094

81-
// Suffix and prefix
82-
8395
.nhsuk-input__wrapper {
8496
display: flex;
8597

@@ -92,6 +104,7 @@
92104
z-index: 1;
93105
}
94106

107+
// Split prefix/suffix onto separate lines on narrow screens
95108
@include nhsuk-media-query($until: mobile) {
96109
display: block;
97110

@@ -104,30 +117,30 @@
104117

105118
.nhsuk-input__prefix,
106119
.nhsuk-input__suffix {
107-
background-color: nhsuk-colour("grey-4");
108-
border: $nhsuk-border-width-form-element solid $nhsuk-input-border-colour;
109120
box-sizing: border-box;
110-
cursor: default; // emphasises non-editable status of prefixes and suffixes
111-
display: inline-block;
112-
flex: 0 0 auto;
113-
min-height: 40px;
121+
// Use flexbox to align text within the prefix and suffix
122+
display: flex;
123+
align-items: center;
124+
justify-content: center;
114125
min-width: nhsuk-px-to-rem(40px);
126+
height: nhsuk-px-to-rem(40px);
115127
padding: nhsuk-spacing(1);
128+
border: $nhsuk-border-width-form-element solid $nhsuk-input-border-colour;
129+
background-color: nhsuk-colour("grey-4");
116130
text-align: center;
117131
white-space: nowrap;
132+
// Emphasise non-editable status of prefixes and suffixes
133+
cursor: default;
134+
flex: 0 0 auto;
118135

119136
@include nhsuk-font($size: 19);
120137

138+
// Split prefix/suffix onto separate lines on narrow screens
121139
@include nhsuk-media-query($until: mobile) {
122140
display: block;
123141
height: 100%;
124142
white-space: normal;
125143
}
126-
127-
@include nhsuk-media-query($until: tablet) {
128-
line-height: 1.6;
129-
font-size: 1.1875rem;
130-
}
131144
}
132145

133146
.nhsuk-input__prefix {
@@ -139,6 +152,7 @@
139152
}
140153
}
141154

155+
// Split prefix/suffix onto separate lines on narrow screens
142156
.nhsuk-input__suffix {
143157
@include nhsuk-media-query($until: mobile) {
144158
border-top: 0;

packages/nhsuk-frontend/src/nhsuk/components/input/macro-options.mjs

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@ export const params = {
2626
inputmode: {
2727
type: 'string',
2828
required: false,
29-
description: 'Optional value for inputmode.'
29+
description:
30+
'Optional value for [the inputmode attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode).'
3031
},
3132
value: {
3233
type: 'string',
3334
required: false,
3435
description: 'Optional initial value of the input.'
3536
},
37+
disabled: {
38+
type: 'boolean',
39+
required: false,
40+
description: 'If `true`, input will be disabled.'
41+
},
3642
describedBy: {
3743
type: 'string',
3844
required: false,
@@ -59,14 +65,64 @@ export const params = {
5965
isComponent: true
6066
},
6167
prefix: {
62-
type: 'string',
68+
type: 'object',
6369
required: false,
64-
description: 'Optional prefix text to be displayed before the input.'
70+
description: 'Can be used to add a prefix to the text input component.',
71+
params: {
72+
text: {
73+
type: 'string',
74+
required: true,
75+
description:
76+
'If `html` is set, this is not required. Text to use within the prefix. If `html` is provided, the `text` option will be ignored.'
77+
},
78+
html: {
79+
type: 'string',
80+
required: true,
81+
description:
82+
'If `text` is set, this is not required. HTML to use within the prefix. If `html` is provided, the `text` option will be ignored.'
83+
},
84+
classes: {
85+
type: 'string',
86+
required: false,
87+
description: 'Classes to add to the prefix.'
88+
},
89+
attributes: {
90+
type: 'object',
91+
required: false,
92+
description:
93+
'HTML attributes (for example data attributes) to add to the prefix element.'
94+
}
95+
}
6596
},
6697
suffix: {
67-
type: 'string',
98+
type: 'object',
6899
required: false,
69-
description: 'Optional suffix text to be displayed after the input.'
100+
description: 'Can be used to add a suffix to the text input component.',
101+
params: {
102+
text: {
103+
type: 'string',
104+
required: true,
105+
description:
106+
'If `html` is set, this is not required. Text to use within the suffix. If `html` is provided, the `text` option will be ignored.'
107+
},
108+
html: {
109+
type: 'string',
110+
required: true,
111+
description:
112+
'If `text` is set, this is not required. HTML to use within the suffix. If `html` is provided, the `text` option will be ignored.'
113+
},
114+
classes: {
115+
type: 'string',
116+
required: false,
117+
description: 'Classes to add to the suffix.'
118+
},
119+
attributes: {
120+
type: 'object',
121+
required: false,
122+
description:
123+
'HTML attributes (for example data attributes) to add to the suffix element.'
124+
}
125+
}
70126
},
71127
formGroup: {
72128
type: 'object',
@@ -151,6 +207,31 @@ export const params = {
151207
description:
152208
'Optional field to enable or disable the spellcheck attribute on the input.'
153209
},
210+
autocapitalize: {
211+
type: 'string',
212+
required: false,
213+
description:
214+
'Optional field to enable or disable autocapitalisation of user input. [See the Autocapitalization section in the HTML spec](https://html.spec.whatwg.org/multipage/interaction.html#autocapitalization) for a full list of values that can be used.'
215+
},
216+
inputWrapper: {
217+
type: 'object',
218+
required: false,
219+
description:
220+
'If any of `prefix`, `suffix`, `formGroup.beforeInput` or `formGroup.afterInput` have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element.',
221+
params: {
222+
classes: {
223+
type: 'string',
224+
required: false,
225+
description: 'Classes to add to the wrapping element.'
226+
},
227+
attributes: {
228+
type: 'object',
229+
required: false,
230+
description:
231+
'HTML attributes (for example data attributes) to add to the wrapping element.'
232+
}
233+
}
234+
},
154235
attributes: {
155236
type: 'object',
156237
required: false,
@@ -218,6 +299,20 @@ export const examples = {
218299
selector: '#with-hint-error'
219300
}
220301
},
302+
'with extra letter spacing': {
303+
context: {
304+
label: {
305+
text: 'NHS number'
306+
},
307+
hint: {
308+
text: "It's a 10-digit number that's on any letter the NHS has sent you, for example, 485 777 3456"
309+
},
310+
id: 'with-extra-letter-spacing',
311+
name: 'example',
312+
value: '485 777 3456',
313+
classes: 'nhsuk-input--width-30 nhsuk-input--extra-letter-spacing'
314+
}
315+
},
221316
'with width-2 class': {
222317
context: {
223318
label: {

0 commit comments

Comments
 (0)