-
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.
fix: active header navigation links should have the option to be matc…
…hed by "exact" (#141)
- Loading branch information
Fran McDade
authored and
Fran McDade
committed
Aug 7, 2024
1 parent
5b08062
commit 7993904
Showing
4 changed files
with
37 additions
and
4 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
16 changes: 15 additions & 1 deletion
16
...ponents/Layout/components/Header/components/Content/components/Navigation/common/utils.ts
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 |
---|---|---|
@@ -1,13 +1,27 @@ | ||
import { SELECTED_MATCH } from "../../../../../common/entities"; | ||
|
||
/** | ||
* Returns true if the navigation link is selected. | ||
* @param url - The URL of the navigation link. | ||
* @param pathname - The current pathname. | ||
* @param selectedMatch - The selected match type. | ||
* @returns true if the navigation link is selected. | ||
*/ | ||
export function isNavigationLinkSelected( | ||
url: string, | ||
pathname?: string | ||
pathname?: string, | ||
selectedMatch: SELECTED_MATCH = SELECTED_MATCH.STARTS_WITH | ||
): boolean { | ||
if (!pathname) return false; | ||
if (isSelectedMatchEqual(selectedMatch)) return url === pathname; | ||
return pathname.startsWith(url); | ||
} | ||
|
||
/** | ||
* Returns true if the selected match type is "EQUAL". | ||
* @param selectedMatch - The selected match type. | ||
* @returns True if the selected match type is "EQUAL". | ||
*/ | ||
export function isSelectedMatchEqual(selectedMatch: SELECTED_MATCH): boolean { | ||
return selectedMatch === SELECTED_MATCH.EQUALS; | ||
} |
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