fix: active links consider query params and respect existing aria-current (#3755)
## Summary - `matchesUrl()` now considers query parameters — links with query params that don't match the current URL get `Ancestor` instead of `Current` status - Links with a user-set `aria-current` attribute are left untouched (both server and client side), fixing daisyUI tab components and similar use cases - Client-side `updateLinks()` passes search params and respects user-set attributes Closes #3474 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
895bcacdae
commit
fc0ff66b80
@@ -304,7 +304,15 @@ document.addEventListener("submit", async (e) => {
|
||||
|
||||
function updateLinks(url: URL) {
|
||||
document.querySelectorAll("a").forEach((link) => {
|
||||
const match = matchesUrl(url.pathname, link.href);
|
||||
// Don't override aria-current if it was explicitly set by the user
|
||||
// (detected by absence of data-current/data-ancestor attributes which
|
||||
// Fresh always sets alongside aria-current)
|
||||
const hasFreshAria = link.hasAttribute(DATA_CURRENT) ||
|
||||
link.hasAttribute(DATA_ANCESTOR);
|
||||
const hasUserAria = !hasFreshAria && link.hasAttribute("aria-current");
|
||||
if (hasUserAria) return;
|
||||
|
||||
const match = matchesUrl(url.pathname, link.href, url.search);
|
||||
|
||||
if (match === UrlMatchKind.Current) {
|
||||
link.setAttribute(DATA_CURRENT, "true");
|
||||
|
||||
Reference in New Issue
Block a user