-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge develop into main for CAN-89, CAN-60 & CAN-80 (#73)
* [CAN-89] Disable Scrolling on Mobile Nav Problem - When mobile overlay up, scrolling still enabled Solution - When component is mounted - disable scrolling on events - DOM Mouse Scrolls - Wheel Events (checked by searching property on div element) - Touch Move - Any Key Events - Package as a helper hook that can be reused on other component - Enable Scrolling when unmount the overlay - ASIDE: Passive Event listeners prevent blocking js code when scrolling - We need to tell the browser (if it is supported) to not block our event listeners as when need to check if the user is scrolling Note * [CAn-60] Overlay Not Closing on Logo Click Mobile Problem - Overlay not closing on logo click Solution - Change the condition to match exact matches instead of regex matches Note - This will need to be changed in future to suit params * [CAN-60] Refactor Logo To Accept OnClick Problem - Clicking on mobile logo doesn't close Solution - Enable onclick to be a prop - Pass close overlay to logo - Close Note * [CAN-60] Refactor Logo to Accept onClick Problem - Logo doesn't close overlay when already on homepage Solution - Refactor logo to accept onClick - If on homepage and component is clicked, execute onClick Note * [CAN-60] Refactor click handlers readability Problem - onClick doesn't really describe what is happening Solution - Refactor hamburger button from .jsx to .tsx - Refactor prop name on overlaynav form handleClick to closeOverlay - Refactor prop name hamburger button from handleClick to showOverlay Note * CAN-80 - Generate custom description and keywords for each club (#70) Problem: need custom meta for SEO Solution: painstakingly generate and paste in --------- Co-authored-by: Fabrizio <[email protected]> Co-authored-by: Fabrizio Catinella <[email protected]>
- Loading branch information
1 parent
c7d3e94
commit c5df426
Showing
10 changed files
with
500 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
'use client'; | ||
import { useEffect } from 'react'; | ||
|
||
const scrollKeys: Set<String> = new Set([ | ||
'Enter', | ||
'Return', | ||
' ', | ||
'PageUp', | ||
'PageDown', | ||
'End', | ||
'Home', | ||
'ArrowLeft', | ||
'ArrowUp', | ||
'ArrowRight', | ||
'ArrowDown', | ||
]); | ||
|
||
export default function usePreventScrolling() { | ||
useEffect(() => { | ||
const preventDefault = (e: Event) => e.preventDefault(); | ||
const preventDefaultOnScrollKeys = (e: KeyboardEvent) => { | ||
if (scrollKeys.has(e.key)) e.preventDefault(); | ||
return false; | ||
}; | ||
|
||
// Needed in Modern Browsers | ||
// See: https://stackoverflow.com/questions/37721782/what-are-passive-event-listeners | ||
var supportsPassive = false; | ||
|
||
try { | ||
const options = Object.defineProperty({}, 'passive', { | ||
get: function () { | ||
supportsPassive = true; | ||
}, | ||
}); | ||
|
||
window.addEventListener( | ||
'testPassiveIsSupported', | ||
null as any, | ||
options | ||
); | ||
|
||
window.removeEventListener( | ||
'testPassiveIsSupported', | ||
null as any, | ||
options | ||
); | ||
} catch (e) {} | ||
|
||
var wheelOpt = supportsPassive ? { passive: false } : false; | ||
var wheelEvent = | ||
'onwheel' in document.createElement('div') ? 'wheel' : 'mousewheel'; | ||
|
||
function preventScroll() { | ||
window.addEventListener('DOMMouseScroll', preventDefault, false); // older FF | ||
window.addEventListener(wheelEvent, preventDefault, wheelOpt); // modern desktop | ||
window.addEventListener('touchmove', preventDefault, wheelOpt); // mobile | ||
window.addEventListener( | ||
'keydown', | ||
preventDefaultOnScrollKeys, | ||
false | ||
); | ||
} | ||
|
||
function enableScroll() { | ||
window.removeEventListener('DOMMouseScroll', preventDefault, false); | ||
window.removeEventListener( | ||
wheelEvent, | ||
preventDefault, | ||
wheelOpt as any | ||
); | ||
window.removeEventListener( | ||
'touchmove', | ||
preventDefault, | ||
wheelOpt as any | ||
); | ||
window.removeEventListener( | ||
'keydown', | ||
preventDefaultOnScrollKeys, | ||
false | ||
); | ||
} | ||
|
||
preventScroll(); | ||
|
||
return () => enableScroll(); | ||
}, []); | ||
} |
8 changes: 6 additions & 2 deletions
8
app/ui/Navigation/hamburgerbutton.jsx → app/ui/Navigation/hamburgerbutton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.