Skip to content

Commit

Permalink
docs: enhance intro keydown feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Sep 12, 2019
1 parent 06665bc commit e83ba2b
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/dnb-design-system-portal/src/shared/tags/Intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,26 @@ import {
} from 'dnb-ui-lib/src/elements'
import { Button } from 'dnb-ui-lib/src/components'

const onKeyDownHandler = e => {
try {
if (e.key === 'ArrowRight' && ref && ref.current) {
const elem = ref.current.querySelector('a[href*="/intro"]')
const href = elem.getAttribute('href')
navigate(href)
}
if (e.key === 'ArrowLeft') {
window.history.back()
}
} catch (e) {
console.log(e)
}
}

const ref = React.createRef()
const Intro = ({ children }) => {
useEffect(() => {
const onKeyDownHandler = e => {
if (/textarea|input/i.test(document.activeElement.tagName)) {
return
}
try {
if (e.key === 'ArrowRight' && ref && ref.current) {
const elem = ref.current.querySelector('a[href*="/intro"]')
const href = elem.getAttribute('href')
navigate(href)
}
if (e.key === 'ArrowLeft') {
window.history.back()
}
} catch (e) {
console.log(e)
}
}
try {
document.addEventListener('keydown', onKeyDownHandler)
} catch (e) {
Expand Down

0 comments on commit e83ba2b

Please sign in to comment.