Skip to content

Commit

Permalink
fix: fix touch device detection regarding #e76b5ae
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Nov 28, 2019
1 parent 6e8df02 commit f66b524
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/dnb-ui-lib/src/shared/component-helper.js
Expand Up @@ -59,11 +59,12 @@ export function defineIsTouch({ interactive = true } = {}) {
// to give it a change to have isTouch from the very beginning
if (unsafeIsTouchDeviceCheck()) {
document.documentElement.setAttribute('data-is-touch', true)
IS_TOUCH_DEVICE = true
}

window.addEventListener(
'touchstart',
function onFirstTouch() {
function onTouch() {
try {
if (IS_TOUCH_DEVICE !== true) {
document.documentElement.setAttribute('data-is-touch', true)
Expand All @@ -73,15 +74,15 @@ export function defineIsTouch({ interactive = true } = {}) {
console.warn('Could not apply "touch attribute"', e)
}
if (!interactive) {
window.removeEventListener('touchstart', onFirstTouch, false)
window.removeEventListener('touchstart', onTouch, false)
}
},
false
)

window.addEventListener(
'mouseover',
function onFirstHover() {
function onHover() {
try {
if (IS_TOUCH_DEVICE === true) {
document.documentElement.removeAttribute('data-is-touch')
Expand All @@ -91,7 +92,7 @@ export function defineIsTouch({ interactive = true } = {}) {
console.warn('Could not apply "touch attribute"', e)
}
if (!interactive) {
window.removeEventListener('mouseover', onFirstHover, false)
window.removeEventListener('mouseover', onHover, false)
}
},
false
Expand Down

0 comments on commit f66b524

Please sign in to comment.