Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2universalStack: React
eventstouchaccessibilityux
Cover both touch and pointer devices when listening for outside taps
Use touchstart for touch devices and mousedown for pointer devices (selected via a coarse-pointer media query) so dismiss-on-outside works everywhere without firing twice.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codejavascript
| 1 | document.addEventListener('mousedown', handleOutsideClick); // touch devices have a delay |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | const isTouch = useMediaQuery('(pointer: coarse)'); |
| 2 | const eventType = isTouch ? 'touchstart' : 'mousedown'; |
| 3 | document.addEventListener(eventType, handleOutsideClick, { signal }); |
Explanation (EN)
Objašnjenje (HR)