mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-04 22:31:33 +09:00
fix: Keep current page links active after anchor navigation (#6711)
A link to the current page loses its Current page styling after an anchor jump or when opened with a hash. Keep the page link active, and select only the matching section link when the URL has a fragment. Ref #5377 ## Changes - Match path and query exactly. - With no current fragment, match all links with that path and query. - With a current fragment, match links without a fragment and links with that exact fragment. - Keep the existing `:local-link` polyfill to `[aria-current=page]`. An explicit `aria-current` value can override that styling. - Give static pages the browser URL after hydration and update link state on fragment changes. ## Todo - [x] Implement the mixed path, query, and fragment matching rule. - [x] Cover plain links, router links, direct fragment loads, anchor navigation, and static hydration. - [x] Document the rule and its difference from standard `:local-link` behavior, with the MDN reference. - [x] Remove the redundant CSS selector rewrite, parser dependency, generated schema snapshot, and unneeded history listener. - [x] Run focused tests, typechecks, lint, formatting, and review the final diff. - [x] Confirm required CI checks pass on the latest cleanup commit. ## Verification - SDK link URL tests: 18 passed. - Plain React Link and hydration tests: 10 passed; hydration test passed again after narrowing the subscription to fragment changes. - Router Link tests: 23 passed. - SDK, React Link, router, and CSS engine typechecks passed. - Changed code passed oxlint, oxfmt, and `git diff --check`. - Native fragment event behavior was checked in Chromium, Firefox, and WebKit; hydration behavior was checked in Chromium. - Required GitHub CI passed on `9758b19a6d92c7ab8a2efc7efa553f725a68109f`; the empty Builder core shard passed on retry. ## Behavior note This mixed rule is Webstudio behavior, not the current CSS `:local-link` draft, which ignores fragments on both URLs. Local Link styling follows this mixed match. The mixed match also sets `aria-current="page"` by default, including on section links. Authors can set another value explicitly.
This commit is contained in:
1 parent
aeb34e3c70
commit
b9801bb731
16 files changed
+472
-49
No files matched your search
@@ -72,6 +72,15 @@ When using links for navigation and wanting to highlight the current page, the l
|
||||
|
||||
<figure><picture><source srcset="../../.gitbook/assets/link-local-link-state-dark.png" media="(prefers-color-scheme: dark)"><img src="../../.gitbook/assets/link-local-link-state-light.png" alt="Style sources menu with the local-link state" width="240"></picture></figure>
|
||||
|
||||
Webstudio applies the Local Link state when the link's path and query string match the current URL. The part after `#` controls which links match:
|
||||
|
||||
- At `/faq`, links to `/faq`, `/faq#one`, and `/faq#two` all match.
|
||||
- At `/faq#one`, links to `/faq` and `/faq#one` match, but `/faq#two` does not.
|
||||
|
||||
This differs from the [CSS `:local-link` definition](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors/:local-link), which ignores the part after `#` in both URLs. Webstudio keeps it when the current URL points to a section, so a different section link does not get the Local Link state. When the current URL has no `#`, multiple section links can be highlighted at once.
|
||||
|
||||
By default, Webstudio marks every matching link with `aria-current="page"`, including section links. You can set a different `aria-current` value on a link when needed.
|
||||
|
||||
## Related
|
||||
|
||||
- [Button](button.md) – Clickable action buttons
|
||||
|
||||
Reference in new issue
Block a user