-
Notifications
You must be signed in to change notification settings - Fork 5
Add support for cross-page anchor links #160
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
adrianschmidt
merged 2 commits into
jgroth:main
from
adrianschmidt-bot:feat/cross-page-anchor-links
Feb 11, 2026
Merged
Changes from all commits
Commits
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,74 @@ | ||
| /** | ||
| * Utility functions for handling anchor link scrolling in shadow DOM components. | ||
| */ | ||
|
|
||
| /** | ||
| * Get the current route from the URL hash (without the leading #). | ||
| * | ||
| * For hash-based routing where the entire hash is the route. | ||
| * Example: "#/component/limel-button/examples/" → "/component/limel-button/examples/" | ||
| * @returns {string} The route extracted from the URL hash | ||
| */ | ||
| export function getRoute(): string { | ||
| return window.location.hash.substring(1); | ||
| } | ||
|
|
||
| /** | ||
| * Extract the anchor ID from the current URL hash. | ||
| * | ||
| * Handles both simple anchors (#section) and route-based anchors (#/guide/page#section). | ||
| * Returns null if no valid anchor is found. | ||
| * | ||
| * Example: "#/guide/changelog#v2-features" → "v2-features" | ||
| * @returns {string | null} The anchor ID or null if not found | ||
| */ | ||
| export function getAnchorId(): string | null { | ||
| const hash = window.location.hash; | ||
| if (!hash) { | ||
| return null; | ||
| } | ||
|
|
||
| // Match the last #fragment in the hash | ||
| // This handles both "#section" and "#/route/path#section" | ||
| const anchorMatch = hash.match(/#([^#]+)$/); | ||
|
|
||
| return anchorMatch ? anchorMatch[1] : null; | ||
| } | ||
|
|
||
| /** | ||
| * Scroll to an anchor element within a shadow root. | ||
| * | ||
| * Uses requestAnimationFrame to ensure the DOM is ready before scrolling. | ||
| * @param {ShadowRoot} shadowRoot - The shadow root to search for the element | ||
| * @param {ScrollBehavior} behavior - Scroll behavior ('auto' or 'smooth') | ||
| */ | ||
| export function scrollToAnchor( | ||
| shadowRoot: ShadowRoot, | ||
| behavior: ScrollBehavior = 'auto', | ||
| ): void { | ||
| const anchorId = getAnchorId(); | ||
| if (!anchorId) { | ||
| return; | ||
| } | ||
|
|
||
| requestAnimationFrame(() => { | ||
| scrollToElement(shadowRoot, anchorId, behavior); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Scroll to a specific element by ID within a shadow root. | ||
| * @param {ShadowRoot} shadowRoot - The shadow root to search for the element | ||
| * @param {string} id - The element ID to scroll to | ||
| * @param {ScrollBehavior} behavior - Scroll behavior ('auto' or 'smooth') | ||
| */ | ||
| export function scrollToElement( | ||
| shadowRoot: ShadowRoot, | ||
| id: string, | ||
| behavior: ScrollBehavior = 'auto', | ||
| ): void { | ||
| const element = shadowRoot.getElementById(id); | ||
| if (element) { | ||
| element.scrollIntoView({ behavior: behavior }); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.