Skip to content

Commit

Permalink
Error link to panel
Browse files Browse the repository at this point in the history
  • Loading branch information
boxadesign committed May 5, 2020
1 parent 8e31f07 commit 85043d3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
21 changes: 18 additions & 3 deletions _js/modules/inpagelink.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,24 @@ export function applyInPageLink(elTrigger) {
}

function focusOnInput(elId) {
const elIdInput = document.getElementById(elId).querySelectorAll('.input')[0]
elIdInput.focus()
return elId
const container = document.getElementById(elId);
console.log(container);
container.scrollIntoView();

const input = [
...container.getElementsByTagName('INPUT'),
...container.getElementsByTagName('TEXTAREA'),
...container.getElementsByTagName('SELECT'),
].filter(input => {
const type = input.getAttribute('type');

return type !== 'readonly' && type !== 'hidden' && type !== 'checkbox' && type !== 'radio';
})[0];

if (input) {
input.focus();
}
return elId;
}

domready(inPageLink)
47 changes: 47 additions & 0 deletions _prototypes/end-to-end/assets/inpagelink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import domready from '../../../_js/modules/domready';
import {forEach} from 'lodash'

domready(() => {

const classTrigger = 'js-inpagelink'


function inPageLink() {
const nodeList = document.getElementsByClassName(classTrigger)
forEach(nodeList, applyInPageLink)
return nodeList
}

function applyInPageLink(elTrigger) {
const elId = elTrigger.getAttribute('href').replace('#', '')
elTrigger.addEventListener('click', (e) => {
e.preventDefault()
focusOnInput(elId)
})

return { elTrigger, elId }
}

function focusOnInput(elId) {
const container = document.getElementById(elId).closest('.panel');
container.scrollIntoView();

const input = [
...container.getElementsByTagName('INPUT'),
...container.getElementsByTagName('TEXTAREA'),
...container.getElementsByTagName('SELECT'),
].filter(input => {
const type = input.getAttribute('type');

return type !== 'readonly' && type !== 'hidden' && type !== 'checkbox' && type !== 'radio';
})[0];

if (input) {
input.focus();
}
return elId;
}

inPageLink();

});
1 change: 1 addition & 0 deletions _prototypes/end-to-end/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import './assets/modules/address-input/address-input';
import './assets/modules/uac/uac';
import './assets/modules/character-check';
import './assets/previous-link';
import './assets/inpagelink';

import {
RELATIONSHIPS_STORAGE_KEY,
Expand Down

0 comments on commit 85043d3

Please sign in to comment.