Skip to content

Commit 722bdd4

Browse files
Uplift GOV.UK Frontend password input component
1 parent 8c08970 commit 722bdd4

13 files changed

Lines changed: 1090 additions & 1 deletion

File tree

docs/configuration/javascript-api-reference.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This page lists the options available for the following components:
1010
- [Button](#button)
1111
- [CharacterCount](#charactercount)
1212
- [ErrorSummary](#errorsummary)
13+
- [FileUpload](#fileupload)
1314
- [NotificationBanner](#notificationbanner)
1415

1516
## Button
@@ -196,6 +197,98 @@ Default
196197
false
197198
```
198199

200+
## FileUpload
201+
202+
### i18n
203+
204+
Type: object
205+
206+
Messages the component uses for screen reader announcements relating to choosing
207+
and dropping files.
208+
209+
All of these strings should be short and in plain text.
210+
211+
#### Properties
212+
213+
##### chooseFilesButton
214+
215+
Type: string
216+
217+
The text of the button that opens the file picker.
218+
219+
Default:
220+
221+
```json5
222+
'Choose file'
223+
```
224+
225+
##### dropInstruction
226+
227+
Type: string
228+
229+
The text informing users they can drop files.
230+
231+
Default:
232+
233+
```json5
234+
'or drop file'
235+
```
236+
237+
##### noFileChosen
238+
239+
Type: string
240+
241+
The text to display when no file has been chosen by the user.
242+
243+
Default:
244+
245+
```json5
246+
'No file chosen'
247+
```
248+
249+
##### multipleFilesChosen
250+
251+
Type: object
252+
253+
The text displayed when multiple files have been chosen by the user.
254+
255+
Default:
256+
257+
```json5
258+
{
259+
// the 'one' string isn't used as the component displays the filename
260+
// instead, however it's here for coverage's sake
261+
one: '%{count} file chosen',
262+
other: '%{count} files chosen'
263+
},
264+
```
265+
266+
##### enteredDropZone
267+
268+
Type: string
269+
270+
The text announced by assistive technology when the user drags files and enters
271+
the drop zone
272+
273+
Default:
274+
275+
```json5
276+
'Entered drop zone'
277+
```
278+
279+
##### leftDropZone
280+
281+
Type: string
282+
283+
The text announced by assistive technology when user drags files and leaves the
284+
drop zone without dropping
285+
286+
Default:
287+
288+
```json5
289+
'Left drop zone'
290+
```
291+
199292
## NotificationBanner
200293

201294
### disableAutoFocus

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@forward "pagination";
2727
@forward "panel";
2828
@forward "checkboxes";
29+
@forward "password-input";
2930
@forward "radios";
3031
@forward "select";
3132
@forward "skip-link";

packages/nhsuk-frontend/src/nhsuk/components/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './checkboxes/checkboxes.mjs'
44
export * from './error-summary/error-summary.mjs'
55
export * from './header/header.mjs'
66
export * from './notification-banner/notification-banner.mjs'
7+
export * from './password-input/password-input.mjs'
78
export * from './radios/radios.mjs'
89
export * from './skip-link/skip-link.mjs'
910
export * from './tabs/tabs.mjs'
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@use "../../core/settings" as *;
2+
@use "../../core/tools" as *;
3+
@use "../../core/helpers" as *;
4+
@forward "../button";
5+
@forward "../input";
6+
7+
////
8+
/// Password input component
9+
///
10+
/// @group components/password-input
11+
////
12+
13+
@include nhsuk-exports("nhsuk/components/password-input") {
14+
.nhsuk-password-input__wrapper {
15+
// This element inherits styles from .nhsuk-input__wrapper, including:
16+
// - being display: block with contents in a stacked column below the mobile
17+
// breakpoint
18+
// - being display: flex above the mobile breakpoint
19+
20+
@include nhsuk-media-query($from: mobile) {
21+
flex-direction: row;
22+
23+
// The default of `stretch` makes the toggle button appear taller than the
24+
// input, due to using box-shadow, which we don't particularly want in
25+
// this situation
26+
align-items: flex-start;
27+
}
28+
}
29+
30+
.nhsuk-password-input__input {
31+
// IE 11 and Microsoft Edge comes with its own password reveal function. We
32+
// want to hide it, so that there aren't two controls presented to the user
33+
// that do the same thing but aren't in sync with one another. This doesn't
34+
// affect the function that allows Edge users to toggle password visibility
35+
// by pressing Alt+F8, which cannot be programmatically disabled.
36+
&::-ms-reveal {
37+
display: none;
38+
}
39+
}
40+
41+
.nhsuk-password-input__toggle {
42+
// Add top margin so the button doesn't obscure the input's focus style
43+
margin-top: nhsuk-spacing(1);
44+
45+
// Remove default margin-bottom from button
46+
margin-bottom: 0;
47+
48+
// Hide the button by default, JS removes this attribute
49+
&[hidden] {
50+
display: none;
51+
}
52+
53+
@include nhsuk-media-query($from: mobile) {
54+
// Buttons are normally 100% wide on mobile, but we don't want that here
55+
width: auto;
56+
flex-shrink: 0;
57+
flex-basis: 5em;
58+
59+
// Move the spacing from top to the left
60+
margin-top: 0;
61+
margin-left: nhsuk-spacing(1);
62+
}
63+
}
64+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@forward ".";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { axe, goToComponent } from '@nhsuk/frontend-helpers/puppeteer.mjs'
2+
3+
import { examples } from './macro-options.mjs'
4+
5+
describe('Password input', () => {
6+
/** @type {Page} */
7+
let page
8+
9+
describe('Component examples', () => {
10+
it('passes accessibility tests', async () => {
11+
for (const example in examples) {
12+
page = await goToComponent(browser, 'password-input', { example })
13+
await expect(axe(page)).resolves.toHaveNoViolations()
14+
}
15+
}, 120000)
16+
})
17+
})
18+
19+
/**
20+
* @import { Page } from 'puppeteer'
21+
*/

0 commit comments

Comments
 (0)