From 02eaf042a8123563697bb57c7717a60a97d4846a Mon Sep 17 00:00:00 2001 From: Simon Whatley Date: Fri, 22 May 2020 21:12:06 +0100 Subject: [PATCH 1/9] Add prefix and suffix --- src/govuk/components/input/_index.scss | 52 +++++++++++ src/govuk/components/input/input.yaml | 114 +++++++++++++++++++++++- src/govuk/components/input/template.njk | 37 ++++++-- 3 files changed, 194 insertions(+), 9 deletions(-) diff --git a/src/govuk/components/input/_index.scss b/src/govuk/components/input/_index.scss index 17632e077d..3809f06ab3 100644 --- a/src/govuk/components/input/_index.scss +++ b/src/govuk/components/input/_index.scss @@ -91,4 +91,56 @@ max-width: 5.4ex; } + .govuk-input__wrapper { + display: flex; + display: -ms-flexbox; // sass-lint:disable-line no-duplicate-properties + + .govuk-input { + display: inline-block; + flex: 0 1 auto; + } + + .govuk-input:focus { + z-index: 1; // increase z-index on focus so it appears over the suffix + } + } + + .govuk-input__prefix, + .govuk-input__suffix { + @include govuk-font($size: 19); + + box-sizing: border-box; + display: inline-block; + width: auto; + + min-width: 40px; + @if $govuk-typography-use-rem { + min-width: govuk-px-to-rem(40px); + } + + height: 40px; + @if $govuk-typography-use-rem { + height: govuk-px-to-rem(40px); + } + margin-top: 0; + + padding: govuk-spacing(1); + + border: $govuk-border-width-form-element solid $govuk-input-border-colour; + background-color: govuk-colour("light-grey", $legacy: "grey-3"); + + text-align: center; + white-space: nowrap; + cursor: default; // emphasise non-editable status of prefixes and suffixes + + } + + .govuk-input__prefix { + border-right: 0; + } + + .govuk-input__suffix { + border-left: 0; + } + } diff --git a/src/govuk/components/input/input.yaml b/src/govuk/components/input/input.yaml index b917dea526..fd44dc1f2c 100644 --- a/src/govuk/components/input/input.yaml +++ b/src/govuk/components/input/input.yaml @@ -38,6 +38,48 @@ params: required: false description: Options for the error message component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`. isComponent: true +- name: prefix + type: object + required: false + description: Options for the prefix tag. + params: + - name: text + type: string + required: true + description: Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored. + - name: html + type: string + required: true + description: Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored. + - name: classes + type: string + required: false + description: Classes to add to the prefix tag + - name: attributes + type: object + required: false + description: HTML attributes (for example data attributes) to add to the prefix tag. +- name: suffix + type: object + required: false + description: Options for the suffix tag. + params: + - name: text + type: string + required: true + description: Required. If `html` is set, this is not required. Text to use within the label. If `html` is provided, the `text` argument will be ignored. + - name: html + type: string + required: true + description: Required. If `text` is set, this is not required. HTML to use within the label. If `html` is provided, the `text` argument will be ignored. + - name: classes + type: string + required: false + description: Classes to add to the suffix tag + - name: attributes + type: object + required: false + description: HTML attributes (for example data attributes) to add to the suffix tag. - name: formGroup type: object required: false @@ -203,6 +245,77 @@ examples: type: text spellcheck: false + - name: with prefix element + data: + label: + text: Amount, in pounds + id: input-with-prefix-element + name: amount + type: number + classes: govuk-input--width-10 + prefix: + text: £ + - name: with prefix and error elements + data: + label: + text: Amount, in pounds + id: input-with-prefix-element-with-error + name: amount + type: number + classes: govuk-input--width-10 + errorMessage: + text: Enter an amount in pounds + prefix: + text: £ + - name: with suffix element + data: + label: + text: Weight, in kilograms + id: input-with-suffix-element + name: weight + type: number + classes: govuk-input--width-10 + suffix: + text: kg + - name: with suffix and error elements + data: + label: + text: Weight, in kilograms + id: input-with-suffix-element-with-error + name: weight + type: number + classes: govuk-input--width-10 + errorMessage: + text: Enter a weight in kilograms + suffix: + text: kg + - name: with prefix and suffix elements + data: + label: + text: Cost per item, in pounds + id: input-with-prefix-suffix-elements + name: cost + type: number + classes: govuk-input--width-10 + prefix: + text: £ + suffix: + text: per item + - name: with prefix, suffix and error elements + data: + label: + text: Cost per item, in pounds + id: input-with-prefix-suffix-elements-with-error + name: cost + type: number + classes: govuk-input--width-10 + errorMessage: + text: Enter a cost per item in pounds + prefix: + text: £ + suffix: + text: per item + # Hidden examples are not shown in the review app, but are used for tests and HTML fixtures - name: classes hidden: true @@ -256,4 +369,3 @@ examples: hidden: true data: inputmode: decimal - diff --git a/src/govuk/components/input/template.njk b/src/govuk/components/input/template.njk index 25dcb50883..fca7ab2bda 100644 --- a/src/govuk/components/input/template.njk +++ b/src/govuk/components/input/template.njk @@ -5,6 +5,18 @@ {#- a record of other elements that we need to associate with the input using aria-describedby – for example hints or error messages -#} {% set describedBy = params.describedBy if params.describedBy else "" %} + +{%- set inputTag %} + +{% endset -%} +
{{ govukLabel({ html: params.label.html, @@ -37,12 +49,21 @@ visuallyHiddenText: params.errorMessage.visuallyHiddenText }) | indent(2) | trim }} {% endif %} - +{%- if params.prefix or params.suffix %}
{% endif -%} +{%- if params.prefix %} + {%- if params.prefix.html | length or params.prefix.text | length %} + + {% endif -%} +{% endif -%} +{{- inputTag | safe -}} +{%- if params.suffix %} + {%- if params.suffix.html | length or params.suffix.text | length %} + + {% endif -%} +{% endif -%} +{%- if params.prefix or params.suffix %}
{% endif %}
From 0430f7c7e3df94dacf6a3379492330c84ee3a022 Mon Sep 17 00:00:00 2001 From: Simon Whatley Date: Fri, 3 Jul 2020 13:44:51 +0100 Subject: [PATCH 2/9] Updates following working group review --- src/govuk/components/input/_index.scss | 7 +++++++ src/govuk/components/input/template.njk | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/govuk/components/input/_index.scss b/src/govuk/components/input/_index.scss index 3809f06ab3..d1f075ad12 100644 --- a/src/govuk/components/input/_index.scss +++ b/src/govuk/components/input/_index.scss @@ -8,6 +8,7 @@ box-sizing: border-box; width: 100%; + min-width: 0; height: 40px; @if $govuk-typography-use-rem { height: govuk-px-to-rem(40px); @@ -129,10 +130,16 @@ border: $govuk-border-width-form-element solid $govuk-input-border-colour; background-color: govuk-colour("light-grey", $legacy: "grey-3"); + @include govuk-media-query($until: tablet) { + line-height: 1.6; + } + text-align: center; white-space: nowrap; cursor: default; // emphasise non-editable status of prefixes and suffixes + flex: 0 0 auto; + } .govuk-input__prefix { diff --git a/src/govuk/components/input/template.njk b/src/govuk/components/input/template.njk index fca7ab2bda..4cc2aa0948 100644 --- a/src/govuk/components/input/template.njk +++ b/src/govuk/components/input/template.njk @@ -52,7 +52,7 @@ {%- if params.prefix or params.suffix %}
{% endif -%} {%- if params.prefix %} {%- if params.prefix.html | length or params.prefix.text | length %} -