Skip to content
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

fix(about): focus states #12225

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions client/src/about/custom-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,45 @@ 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");
}
_focusout() {
const hx = this.querySelector("h4, h5");
const panel = hx?.closest(".tabpanel");
window.history.pushState({}, "", `#${panel?.id || ""}`);
}

createRenderRoot() {
return this;
}

_mousedown(ev) {
if (ev?.target?.tagName === "A") {
ev?.preventDefault?.();
}
}

connectedCallback() {
super.connectedCallback();
this.tabIndex = 0;
this._setID();
this.addEventListener("focus", this._focus);
if (window.location.hash === `#${this.id}`) {
setTimeout(() => this.focus(), 100);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have something competing here, or we're not yet in the DOM. Take a look @LeoMcA

If we keep it we might wanna manage it the lit way.

}
this.addEventListener("mousedown", this._mousedown);
this.addEventListener("focusin", this._focusin);
this.addEventListener("focusout", this._focusout);
}

disconnectedCallback() {
super.disconnectedCallback();
this.removeEventListener("focus", this._focus);
this.removeEventListener("mousedown", this._mousedown);
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
Loading