Skip to content

Commit

Permalink
fix: make sure applyPageFocus not forces all elements to use tabind…
Browse files Browse the repository at this point in the history
…ex="-1"
  • Loading branch information
tujoworker committed Feb 1, 2019
1 parent 3d93b7a commit 53c3700
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const customBodyStyle = css`
`
const toggleContent = css`
/* hide content if shown as overlay menu */
.dnb-skip-link,
.sticky-menu,
.content-wrapper {
display: none !important;
Expand Down
32 changes: 26 additions & 6 deletions packages/dnb-ui-lib/src/shared/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,34 @@ export const applyPageFocus = (key = 'default') => {
element = document.querySelector('.dnb-no-focus')
}
if (element instanceof HTMLElement) {
if (!element.hasAttribute('tabindex')) {
element.setAttribute('tabindex', '-1')
}
if (
element.classList &&
!element.classList.contains('dnb-no-focus')
[
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'p',
'div',
'main',
'nav',
'header',
'footer',
'aside',
'section',
'article'
].includes(element.type)
) {
element.classList.add('dnb-no-focus')
if (!element.hasAttribute('tabindex')) {
element.setAttribute('tabindex', '-1')
}
if (
element.classList &&
!element.classList.contains('dnb-no-focus')
) {
element.classList.add('dnb-no-focus')
}
}
element.focus({ preventScroll: true })
}
Expand Down

0 comments on commit 53c3700

Please sign in to comment.