Skip to content

Commit

Permalink
chore: add utility function to detect touch screen (#1765)
Browse files Browse the repository at this point in the history
  • Loading branch information
viladimiru authored Sep 6, 2024
1 parent 4c3d070 commit aeba7a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './components';
export * from './hooks';
export * from './utils/dom';
15 changes: 15 additions & 0 deletions src/utils/dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function isTouchDevice(): boolean {
if (typeof window === 'undefined') {
return false;
}

if (typeof navigator !== 'undefined' && navigator.maxTouchPoints > 0) {
return true;
}

if (window.matchMedia && window.matchMedia('(any-pointer:coarse)').matches) {
return true;
}

return 'ontouchstart' in window;
}

0 comments on commit aeba7a0

Please sign in to comment.