Skip to content

Commit

Permalink
Don't append hash when error summary link clicked
Browse files Browse the repository at this point in the history
When error summary links are clicked, this adds a hash to the URL.
As reported in #1398,
if the form is submitted again with further errors, the hash will stop
the error summary being focused as should happen and instead the element
with the hash ID is scrolled to which is confusing for the user.

This behaviour was prevented in GOV.UK Elements but we were not sure at
the time why this was necessary so it wasn't reintroduced in GOV.UK Frontend.
As we need to use preventDefault() to stop the page scrolling to the form element
itself and to show the error message above to make it clear what happened,
we programmatically reintroduced the hash to the URL to replicate browser
behaviour.

Following the bug report #1398, the code that adds the hash is redundant
and can be removed.

Co-authored-by: Oliver Byford <oliver.byford@digital.cabinet-office.gov.uk>
  • Loading branch information
2 people authored and aliuk2012 committed Jun 14, 2019
1 parent ef66ce9 commit fd65f89
Showing 1 changed file with 0 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/components/error-summary/error-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ ErrorSummary.prototype.focusTarget = function ($target) {
return false
}

// Prefer using the history API where possible, as updating
// window.location.hash causes the viewport to jump to the input briefly
// before then scrolling to the label/legend in IE10, IE11 and Edge (as tested
// in Edge 17).
if (window.history.pushState) {
window.history.pushState(null, null, '#' + inputId)
} else {
window.location.hash = inputId
}

// Scroll the legend or label into view *before* calling focus on the input to
// avoid extra scrolling in browsers that don't support `preventScroll` (which
// at time of writing is most of them...)
Expand Down

0 comments on commit fd65f89

Please sign in to comment.