-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scroll to label or legend when linked from error summary
By default, the browser will scroll the target into view. Because our labels or legends appear above the input, this means the user will be presented with an input without any context, as the label or legend will be off the top of the screen. Manually handling the click event, focussing the element and scrolling the question into view solves this.
- Loading branch information
Showing
5 changed files
with
201 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import './matches' | ||
|
||
(function(undefined) { | ||
|
||
// Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/detect.js | ||
var detect = ( | ||
'document' in this && "closest" in document.documentElement | ||
) | ||
|
||
if (detect) return | ||
|
||
// Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/polyfill.js | ||
Element.prototype.closest = function closest(selector) { | ||
var node = this; | ||
|
||
while (node) { | ||
if (node.matches(selector)) return node; | ||
else node = 'SVGElement' in window && node instanceof SVGElement ? node.parentNode : node.parentElement; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
}).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(function(undefined) { | ||
|
||
// Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/detect.js | ||
var detect = ( | ||
'document' in this && "matches" in document.documentElement | ||
) | ||
|
||
if (detect) return | ||
|
||
// Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/polyfill.js | ||
Element.prototype.matches = Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || function matches(selector) { | ||
var element = this; | ||
var elements = (element.document || element.ownerDocument).querySelectorAll(selector); | ||
var index = 0; | ||
|
||
while (elements[index] && elements[index] !== element) { | ||
++index; | ||
} | ||
|
||
return !!elements[index]; | ||
}; | ||
|
||
}).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {}); |