Skip to content

Commit

Permalink
fix(menu): adapt triggerFix to work with small screens with hover
Browse files Browse the repository at this point in the history
  • Loading branch information
elbotho committed Jan 30, 2024
1 parent 9b9f6ba commit cbd5d27
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function SubContent({ subItems, parent }: SubContentProps) {
(isLast || isParticipate) && 'md:right-0'
)}
onPointerEnter={preventHover}
onPointerLeave={preventHover}
>
{isParticipateMega ? (
<SubParticipateMega subItems={subItems} parent={parent} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,19 @@ export function useNavMenuTriggerFix() {
// make sure click directly after hover closes menu again
onClick: preventMouseClick,
onPointerEnter: () => {
if (hasTouchSupportAndSmallScreen()) return
if (isSmallScreen()) return
if (clickDisabled) clearTimeout(clickDisabled)
clickDisabled = setTimeout(() => (clickDisabled = false), 1000)
},
// disable hover completely on small screens with touch support
onPointerLeave: preventHover,
onPointerMove: preventHover,
}
}, [])
}

function hasTouchSupportAndSmallScreen() {
return (
('ontouchstart' in window || navigator.maxTouchPoints > 0) &&
window.innerWidth < 1024
)
}
const isSmallScreen = () => window.innerWidth < 1024

export const preventHover: PointerEventHandler = (event) => {
if (hasTouchSupportAndSmallScreen()) event.preventDefault()
if (isSmallScreen()) event.preventDefault()
}

0 comments on commit cbd5d27

Please sign in to comment.