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

Prevent inputs ending up off screen or obscured by keyboards when linking from the error summary to inputs within a large fieldset #1570

Merged
merged 5 commits into from
Sep 19, 2019

Conversation

36degrees
Copy link
Contributor

Only scroll from error summary to legend if the input is a radio or checkbox, or the input would end up in the top half of the screen.

This is to prevent linking to inputs which then end up either off the bottom of the screen or obscured by a software keyboard.

Fixes #1544

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1570 September 13, 2019 09:43 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1570 September 13, 2019 09:52 Inactive
@@ -109,7 +111,32 @@ ErrorSummary.prototype.getAssociatedLegendOrLabel = function ($input) {
var legends = $fieldset.getElementsByTagName('legend')

if (legends.length) {
return legends[0]
var $candidateLegend = legends[0]
Copy link
Contributor

@NickColley NickColley Sep 13, 2019

Choose a reason for hiding this comment

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

In theory we could write tests for this logic, using puppeteer on the demo pages you've been testing, this could be useful in the future if we (hopefully not) encounter other edge cases.

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've added to the existing tests to try and cover the two new examples that have been added to the review app.

Copy link
Contributor

Choose a reason for hiding this comment

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

Epic! Thank you

@NickColley
Copy link
Contributor

NickColley commented Sep 13, 2019

For reference there's also 'IntersectionObservers' which have concepts of thresholds, a bit overkill for this I think since we're only doing it once per link click but worth sharing: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API

if (inputRect.height && window.innerHeight) {
var inputBottom = inputRect.top + inputRect.height

if (inputBottom - legendTop < window.innerHeight / 2) {
Copy link
Contributor

@NickColley NickColley Sep 13, 2019

Choose a reason for hiding this comment

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

When testing this on my machine I find that I'm always linked to the errored input for the last example despite the fieldset being able to fit all on the screen at once.

Is the issue that mobile keyboards open after the navigation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More or less – the logic checks to see whether the input would end up entirely in the top half of the viewport, to allow for keyboards.

name: "traal",
fieldset: {
legend: {
text: "Have you supplied orders signed in triplicate, sent in, sent back, queried, lost, found, subjected to public inquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters?",
Copy link
Contributor

Choose a reason for hiding this comment

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

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-review-pr-1570 September 13, 2019 12:58 Inactive
Copy link
Contributor

@NickColley NickColley left a comment

Choose a reason for hiding this comment

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

Needs a CHANGELOG entry but this is really nice!

@NickColley NickColley added this to the Next milestone Sep 13, 2019
Copy link
Contributor

@NickColley NickColley left a comment

Choose a reason for hiding this comment

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

Needs a CHANGELOG entry too

@36degrees 36degrees changed the title Improve linking from the error summary to inputs within a fieldset Prevent inputs ending up off screen or obscured by keyboards when linking from the error summary to inputs within a large fieldset Sep 19, 2019
If you use the error summary component with our current address pattern (multiple text inputs within a fieldset), clicking on the error message for the post code scrolls to the top of the fieldset which means e.g. on iOS the postcode field ends up obscured by the keyboard.

This example demonstrates that and allows us to test for sensible behaviour.
Only scroll to the fieldset’s legend (instead of the label associated with the input) if the input would end up in the top half of the screen.

This should avoid situations where the input either ends up off the screen, or obscured by a software keyboard.
@36degrees
Copy link
Contributor Author

@NickColley happy with this changelog entry?

@NickColley
Copy link
Contributor

@36degrees 👍 looks peng mate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Error Summary link handling can result in obscured inputs
3 participants