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

Make radios and checkboxes components easier to link to from error summary #1426

Merged
merged 3 commits into from
Jun 6, 2019

Conversation

NickColley
Copy link
Contributor

@NickColley NickColley commented Jun 4, 2019

Updates the radios, checkboxes and date input components so it's easier to link to their first items from the error summary component.

I have tried to simplify the date input component in a similar way but the complexity was the same after I changed it, if not worse. So if we want to make the date input component easier to use in the future we'll need to think about something else.

Closes #929

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1426 June 4, 2019 16:46 Inactive
@@ -8,7 +8,7 @@ module.exports = (app) => {
body('passport-number')
.exists()
.not().isEmpty().withMessage('Enter your passport number'),
body('expiry-day')
body('expiry')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced making these changes on the date input component actually makes it any easier.

You can see that I was not able to simplify the logic in the validation section:

// If any of the date inputs error apply a general error.
const expiryNamePrefix = 'expiry'
const expiryErrors = Object.values(errors).filter(error => error.id.includes(expiryNamePrefix + '-'))
if (expiryErrors) {
const firstExpiryErrorId = expiryErrors[0].id
// Get the first error message and merge it into a single error message.
errors[expiryNamePrefix] = {
id: expiryNamePrefix,
href: '#' + firstExpiryErrorId
}
// Construct a single error message based on all three error messages.
errors[expiryNamePrefix].text = 'Enter your expiry '
if (expiryErrors.length === 3) {
errors[expiryNamePrefix].text += 'date'
} else {
errors[expiryNamePrefix].text += expiryErrors.map(error => error.text.replace('Enter your expiry ', '')).join(' and ')
}
}
let errorSummary = Object.values(errors)
if (expiryErrors) {
// Remove all other errors from the summary so we only have one message that links to the expiry input.
errorSummary = errorSummary.filter(error => !error.id.includes(expiryNamePrefix + '-'))
}

Is it worth changing the date input considering this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that the full page example that features the date input doesnt work anymore, so maybe I will have to change this logic, will see if it makes it simpler or not, I suspect it'll be more complex than it already is...

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1426 June 4, 2019 16:50 Inactive
@NickColley NickColley force-pushed the make-components-easier-to-link-to-from-error-summary branch from 7c9706e to 36be88e Compare June 4, 2019 16:58
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1426 June 4, 2019 16:59 Inactive
@NickColley NickColley force-pushed the make-components-easier-to-link-to-from-error-summary branch from 36be88e to 78691cd Compare June 5, 2019 11:08
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1426 June 5, 2019 11:08 Inactive
@NickColley NickColley force-pushed the make-components-easier-to-link-to-from-error-summary branch from 78691cd to 8407a10 Compare June 5, 2019 11:23
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1426 June 5, 2019 11:23 Inactive
@NickColley NickColley force-pushed the make-components-easier-to-link-to-from-error-summary branch from 8407a10 to 84f05a0 Compare June 5, 2019 11:24
@NickColley NickColley marked this pull request as ready for review June 5, 2019 11:24
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1426 June 5, 2019 11:24 Inactive
@NickColley NickColley added this to the v3.0.0 milestone Jun 5, 2019
@NickColley NickColley changed the title Make components easier to link to from error summary Make radios and checkboxes components easier to link to from error summary Jun 5, 2019
Copy link
Contributor

@36degrees 36degrees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thorough cleanup @NickColley, thanks!

CHANGELOG.md Outdated
@@ -4,6 +4,35 @@

💥 Breaking changes:

- Make radios and checkboxes components easier to link to from the error summary component

The first input in the radios and checkboxes will have an `id` and `name` attribute that match, allowing for easier generation of error summary links.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only true if you haven't specified your own idPrefix, I think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should be more explicit about what's actually changed here?

Perhaps something like…

The ID of the first input in a set of radios or checkboxes will no longer be suffixed with -1. This means that it will be the same as your idPrefix, or if idPrefix is not set it'll be the same as the name

We've made this change to make it easier to link from the error summary to radios or checkboxes.

CHANGELOG.md Outdated

The first input in the radios and checkboxes will have an `id` and `name` attribute that match, allowing for easier generation of error summary links.

You should check that clicking an error link for a radios or checkboxes results in the first input being focused.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it clear enough what we mean by 'error link'? Would it be better to use something like:

Suggested change
You should check that clicking an error link for a radios or checkboxes results in the first input being focused.
You should check that clicking a link from the error summary to radios or checkboxes results in the first input being focused.


You should check that clicking an error link for a radios or checkboxes results in the first input being focused.

To migrate you can update your error summary so it links to the first element, for example if you are using an `idPrefix` option of `question`, your error summary can now link to `#question` instead of `#question-1`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users might also be overriding the id of the first radio/checkbox, which I think is what we suggested in #929. In that case, they could remove the id as it won't be doing anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured since this wasnt required that I'd leave the up to people themselves rather than potentially confusing things... maybe should just have this in

Copy link
Contributor Author

@NickColley NickColley Jun 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this and I'm worried that there's just a lot of steps being described that could confuse people so I wanted to focus on the things they definitely need to do...

There's no real harm leaving those item.ids around, it's just not necessary anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind I've included it after all..

If you cannot change your error summary, you could change your component to set the `item.id` option for the first input, for example:

```javascript
{{ govukRadios({

This comment was marked as resolved.

{%- set id = item.id -%}
{%- else -%}
{%- set id = idPrefix -%}
{#- The first id should not have a prefix so it's easy to link to from the error summary component -#}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number is a suffix, not a prefix 🙂

Suggested change
{#- The first id should not have a prefix so it's easy to link to from the error summary component -#}
{#- The first id should not have a number suffix so it's easy to link to from the error summary component -#}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i always get these mixed up lol :)

{%- set id = idPrefix -%}
{#- The first id should not have a prefix so it's easy to link to from the error summary component -#}
{%- if not loop.first -%}
{%- set id = id + "-" + loop.index -%}

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give this a go thanks for the comment

@NickColley NickColley force-pushed the make-components-easier-to-link-to-from-error-summary branch from 84f05a0 to bb86303 Compare June 6, 2019 15:09
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1426 June 6, 2019 15:10 Inactive
@NickColley NickColley force-pushed the make-components-easier-to-link-to-from-error-summary branch from bb86303 to 0b4ad6b Compare June 6, 2019 15:14
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1426 June 6, 2019 15:14 Inactive
Copy link
Contributor

@36degrees 36degrees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

If the user has not specified an id for the first item, it will by default render without a suffix number which will make it easier to link to from the error summary as it'll match the `name` attribute.
If the user has not specified an id for the first item, it will by default render without a suffix number which will make it easier to link to from the error summary as it'll match the `name` attribute.
@NickColley NickColley force-pushed the make-components-easier-to-link-to-from-error-summary branch from 0b4ad6b to a33f173 Compare June 6, 2019 16:19
@NickColley NickColley merged commit 0cf4bc0 into v3 Jun 6, 2019
@NickColley NickColley deleted the make-components-easier-to-link-to-from-error-summary branch June 6, 2019 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

3 participants