Skip to content

Commit

Permalink
fix(about): focus states
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Dec 2, 2024
1 parent 6c396d4 commit e77ee23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions client/src/about/custom-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,17 @@ export class TeamMember extends LitElement {
}
}

_focus({ currentTarget }) {
_focusin({ currentTarget }) {
if (currentTarget instanceof HTMLElement) {
window.history.pushState({}, "", `#${currentTarget.id}`);
this.classList.add("open");
this.scrollIntoView({ block: "nearest", inline: "nearest" });
}
}

_focusout({ relatedTarget }) {
if (!(relatedTarget instanceof Node && this.contains(relatedTarget))) {
this.classList.remove("open");
}
const hx = this.querySelector("h4, h5");
const panel = hx?.closest(".tabpanel");
window.history.pushState({}, "", `#${panel?.id || ""}`);
}

createRenderRoot() {
Expand All @@ -59,13 +58,16 @@ export class TeamMember extends LitElement {
super.connectedCallback();
this.tabIndex = 0;
this._setID();
this.addEventListener("focus", this._focus);
if (window.location.hash === `#${this.id}`) {
setTimeout(() => this.focus(), 100);
}
this.addEventListener("focusin", this._focusin);
this.addEventListener("focusout", this._focusout);
}

disconnectedCallback() {
super.disconnectedCallback();
this.removeEventListener("focus", this._focus);
this.removeEventListener("focusin", this._focusin);
this.removeEventListener("focusout", this._focusout);
}
}
2 changes: 1 addition & 1 deletion client/src/about/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ main.about-container {
}
}

&.open {
&:focus-within {
align-content: start;
cursor: unset;
display: grid;
Expand Down

0 comments on commit e77ee23

Please sign in to comment.