Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Allow errors on specific inputs of date-input #3637

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

floehopper
Copy link

What

Why

Visual Changes

Before

After

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3637 September 25, 2023 14:26 Inactive
@floehopper floehopper force-pushed the allow-errors-on-specific-inputs-of-date-input branch from e055ee9 to 3bcb385 Compare September 25, 2023 14:33
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3637 September 25, 2023 14:33 Inactive
@floehopper floehopper force-pushed the allow-errors-on-specific-inputs-of-date-input branch from 3bcb385 to eafaaad Compare September 25, 2023 14:37
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3637 September 25, 2023 14:37 Inactive
@floehopper floehopper force-pushed the allow-errors-on-specific-inputs-of-date-input branch from eafaaad to 0732c41 Compare September 25, 2023 14:54
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3637 September 25, 2023 14:55 Inactive
@floehopper floehopper force-pushed the allow-errors-on-specific-inputs-of-date-input branch from 0732c41 to 90b9844 Compare September 25, 2023 16:38
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3637 September 25, 2023 16:38 Inactive
This captures some aspects of the current behaviour of the input
component that weren't previously covered by tests.
@floehopper floehopper force-pushed the allow-errors-on-specific-inputs-of-date-input branch from 90b9844 to aa4439e Compare September 25, 2023 17:31
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3637 September 25, 2023 17:31 Inactive
It doesn't make sense to me to render an empty error-message paragraph
element if no error_message or error_items are set. However, it does
still make sense to add the error CSS class to the input element.

This commit changes the input component so it only renders the
error-message paragraph if error_message is present or there are some
error_items.

My motivation for making this change is so that I can change the
date-input component to support errors on individual input elements,
e.g. just the year input element. This usage is described in the docs
for the date-input component [1]:

> If you’re highlighting just one field - either the day, month or year
> - only style the field that has an error. The error message must say
> which field has an error, like this:

However, highlighting just one field like this is not actually currently
supported by the date-input component which is a bit confusing!

[1]: https://design-system.service.gov.uk/components/date-input/#error-messages
This captures some aspects of the current behaviour of the date-input
component that weren't previously covered by tests.
As suggested in #3510.

This changes the date-input component so it supports errors on
individual input elements, e.g. just the `year` input element. This
usage is described in the docs for the date-input component [1]:

> If you’re highlighting just one field - either the day, month or year
> - only style the field that has an error. The error message must say
> which field has an error, like this:

However, highlighting just one field like this is not actually currently
supported by the date-input component which is a bit confusing!

The new behaviour (where individual fields are highlighted as having an
error) is specified by adding values for a `name` key to the
`error_items` with the values matching the values of the `name` key in
the `items`. If none of the `error_items` have a value for the `name`
key, then we fallback to the original behaviour, i.e. all fields are
highlighted as having an error. This should hopefully make this a fairly
backwardly-compatible change.

[1]: https://design-system.service.gov.uk/components/date-input/#error-messages
@floehopper floehopper force-pushed the allow-errors-on-specific-inputs-of-date-input branch from aa4439e to 8ba27e9 Compare September 25, 2023 17:38
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3637 September 25, 2023 17:39 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants