1986-04-26 01:23:45 +03:00

25 lines
647 B
TypeScript

/** PettyBreadcrumbItem — single breadcrumb with current-page detection. */
export class PettyBreadcrumbItem extends HTMLElement {
static observedAttributes = ["current"];
connectedCallback(): void {
this.dataset.part = "item";
this.#sync();
}
attributeChangedCallback(): void {
this.#sync();
}
#sync(): void {
const isCurrent = this.hasAttribute("current");
const target = this.querySelector("a") ?? this;
if (isCurrent) {
target.setAttribute("aria-current", "page");
} else {
target.removeAttribute("aria-current");
}
this.dataset.state = isCurrent ? "current" : "default";
}
}