Skip to content

Commit 1404bfd

Browse files
Uplift GOV.UK Frontend select component
1 parent 40d0f8b commit 1404bfd

2 files changed

Lines changed: 43 additions & 32 deletions

File tree

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,53 @@
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
/// Select component
710
///
8-
/// Input sizing:
9-
///
10-
/// 1. Uses rems so that safari input scales with font size
11-
/// 2. This min-width was chosen because:
12-
/// - it makes the Select wider than it is tall (which is what users expect)
13-
/// - 20ex + 3ex matches the 'width-10' variant of the input component
14-
/// - it fits comfortably on screens as narrow as 240px wide
15-
///
1611
/// @group components/select
1712
////
1813

1914
@include nhsuk-exports("nhsuk/components/select") {
2015
.nhsuk-select {
21-
background-color: $nhsuk-input-background-colour;
22-
border: $nhsuk-border-width-form-element solid $nhsuk-input-border-colour;
2316
box-sizing: border-box;
24-
color: $nhsuk-text-colour;
25-
height: 2.5rem; // [1]
26-
min-width: 20ex + 3ex; // [2]
17+
18+
// This min-width was chosen because:
19+
// - it makes the Select wider than it is tall (which is what users expect)
20+
// - 20ex + 3ex matches the 'length-10' variant of the input component
21+
// - it fits comfortably on screens as narrow as 240px wide
22+
min-width: 20ex + 3ex;
2723
max-width: 100%;
24+
height: nhsuk-px-to-rem(40px);
2825
padding: nhsuk-spacing(1);
26+
border: $nhsuk-border-width-form-element solid $nhsuk-input-border-colour;
2927

30-
@include nhsuk-font(19);
28+
// Default user agent colours for selects can have low contrast,
29+
// and may look disabled (https://github.com/alphagov/govuk-frontend/issues/2435)
30+
color: $nhsuk-text-colour;
31+
background-color: $nhsuk-input-background-colour;
32+
33+
@include nhsuk-font($size: 19, $line-height: 1.25);
3134

3235
&:focus {
3336
@include nhsuk-focused-input;
3437
}
38+
39+
&:disabled {
40+
opacity: 0.5;
41+
color: inherit;
42+
cursor: not-allowed;
43+
}
3544
}
3645

3746
.nhsuk-select option:active,
3847
.nhsuk-select option:checked,
3948
.nhsuk-select:focus::-ms-value {
40-
background-color: nhsuk-colour("blue");
4149
color: $nhsuk-reverse-text-colour;
50+
background-color: nhsuk-colour("blue");
4251
}
4352

4453
.nhsuk-select--error {

packages/nhsuk-frontend/src/nhsuk/components/select/template.njk

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
{% from "nhsuk/macros/attributes.njk" import nhsukAttributes %}
12
{% from "nhsuk/components/error-message/macro.njk" import errorMessage -%}
23
{% from "nhsuk/components/hint/macro.njk" import hint %}
34
{% from "nhsuk/components/label/macro.njk" import label %}
4-
{% from "nhsuk/macros/attributes.njk" import nhsukAttributes %}
55

66
{#- a record of other elements that we need to associate with the input using
7-
aria-describedby – for example hints or error messages -#}
8-
{%- set describedBy = params.describedBy if params.describedBy else "" -%}
7+
aria-describedby – for example hints or error messages -#}
8+
{% set describedBy = params.describedBy if params.describedBy else "" %}
99
{%- set id = params.id if params.id else params.name -%}
1010

1111
<div class="nhsuk-form-group {%- if params.errorMessage %} nhsuk-form-group--error{% endif %} {%- if params.formGroup.classes %} {{ params.formGroup.classes }}{% endif %}"
@@ -17,28 +17,30 @@
1717
isPageHeading: params.label.isPageHeading,
1818
attributes: params.label.attributes,
1919
for: id
20-
}) | indent(2) | trim }}
21-
{%- if params.hint %}
22-
{%- set hintId = id + '-hint' %}
23-
{%- set describedBy = describedBy + ' ' + hintId if describedBy else hintId %}
20+
}) | trim | indent(2) }}
21+
{% if params.hint %}
22+
{% set hintId = id + '-hint' %}
23+
{% set describedBy = describedBy + ' ' + hintId if describedBy else hintId %}
2424
{{ hint({
2525
id: hintId,
2626
classes: params.hint.classes,
2727
attributes: params.hint.attributes,
2828
html: params.hint.html,
2929
text: params.hint.text
30-
}) | indent(2) | trim }}
31-
{%- endif -%}
32-
{%- if params.errorMessage %}
33-
{%- set errorId = id + '-error' %}
34-
{%- set describedBy = describedBy + ' ' + errorId if describedBy else errorId %}
30+
}) | trim | indent(2) }}
31+
{% endif %}
32+
{% if params.errorMessage %}
33+
{% set errorId = id + '-error' %}
34+
{% set describedBy = describedBy + ' ' + errorId if describedBy else errorId %}
3535
{{ errorMessage({
3636
id: errorId,
3737
classes: params.errorMessage.classes,
38+
attributes: params.errorMessage.attributes,
3839
html: params.errorMessage.html,
39-
text: params.errorMessage.text
40-
}) | indent(2) | trim }}
41-
{%- endif %}
40+
text: params.errorMessage.text,
41+
visuallyHiddenText: params.errorMessage.visuallyHiddenText
42+
}) | trim | indent(2) }}
43+
{% endif %}
4244
{% if params.formGroup.beforeInput %}
4345
{{ params.formGroup.beforeInput.html | safe | trim | indent(2) if params.formGroup.beforeInput.html else params.formGroup.beforeInput.text }}
4446
{% endif %}
@@ -47,7 +49,7 @@
4749
{%- if params.disabled %} disabled{% endif %}
4850
{%- if describedBy %} aria-describedby="{{ describedBy }}"{% endif %}
4951
{{- nhsukAttributes(params.attributes) }}>
50-
{%- for item in params.items %}
52+
{% for item in params.items %}
5153
{% if item %}
5254
{#- Allow selecting by text content (the value for an option when no value attribute is specified) #}
5355
{%- set effectiveValue = item.value | default(item.text) %}
@@ -58,7 +60,7 @@
5860
{{- item.text -}}
5961
</option>
6062
{% endif %}
61-
{%- endfor %}
63+
{% endfor %}
6264
</select>
6365
{% if params.formGroup.afterInput %}
6466
{{ params.formGroup.afterInput.html | safe | trim | indent(2) if params.formGroup.afterInput.html else params.formGroup.afterInput.text }}

0 commit comments

Comments
 (0)