-
Notifications
You must be signed in to change notification settings - Fork 18
Fix/skip links mobile #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
34dad51
Fix mobile skiplinks to focus the menu toggle and add a new mobile-to…
cedric07 ec3c787
Add a JS util function to return a breakpoint value based on a CSS va…
cedric07 72874f4
refactor getBreakpoint function to generic name
cedric07 c9474ad
Fix isMobileNav function to prevent errors
cedric07 7fc7e77
fix display css utilities classes
cedric07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,18 @@ | ||
| /** | ||
| * Get the value from a CSS custom property. | ||
| * | ||
| * @param {string} name CSS custom property name (ex: '--breakpoint-mobile-to-desktop-nav'). | ||
| * @param {HTMLElement} element The element to get the CSS custom property from. | ||
| * @return {string} The value. | ||
| * @example getCssVar('--breakpoint-mobile-to-desktop-nav') => '1200' | ||
| */ | ||
| export default function getCssVar(name, element = document.documentElement) { | ||
| if (!name) { | ||
| console.warn('getCssVar: No name provided.') | ||
| return '' | ||
| } | ||
|
|
||
| const propName = name.startsWith('--') ? name : `--${name}` | ||
|
|
||
| return getComputedStyle(element).getPropertyValue(propName).trim() | ||
| } |
This file contains hidden or 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,26 @@ | ||
| import getCssVar from './getCssVar' | ||
|
|
||
| /** | ||
| * Check if the current viewport is mobile based on a CSS breakpoint. | ||
| * | ||
| * @param {string} breakpointVar CSS custom property name for the breakpoint. | ||
| * @return {boolean} True if viewport is mobile, false otherwise. | ||
| * @example isMobileNav() => true; !isMobileNav() => false | ||
| */ | ||
| export default function isMobileNav(breakpointVar = '--breakpoint-mobile-to-desktop-nav') { | ||
| const rawValue = getCssVar(breakpointVar) | ||
|
|
||
| if (!rawValue) { | ||
| console.warn(`isMobileNav: Variable ${breakpointVar} is empty or undefined. Returning false.`) | ||
| return false | ||
| } | ||
|
|
||
| const breakpoint = parseInt(rawValue, 10) | ||
|
|
||
| if (isNaN(breakpoint)) { | ||
| console.warn(`isMobileNav: Could not parse "${rawValue}" as a number.`) | ||
| return false | ||
| } | ||
|
|
||
| return window.matchMedia(`(max-width: ${breakpoint - 1}px)`).matches | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
| @use "../02-tools/m-breakpoint" as *; | ||
| @use "../02-tools/m-style-only" as *; | ||
|
|
||
| /** | ||
| * Display utilities | ||
| * | ||
| * Utility classes for showing/hiding elements based on the mobile-to-desktop-nav breakpoint. | ||
| * Used primarily for skip links and navigation-related elements. | ||
| */ | ||
|
|
||
| // Visible only on mobile (below mobile-to-desktop-nav breakpoint) | ||
| .display-mobile-only { | ||
| @include breakpoints(mobile-to-desktop-nav) { | ||
| @include style-only { | ||
| display: none !important; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Visible only on desktop (at or above mobile-to-desktop-nav breakpoint) | ||
| .display-desktop-only { | ||
| @include breakpoints(mobile-to-desktop-nav, max) { | ||
| @include style-only { | ||
| display: none !important; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.