Skip to content

Commit

Permalink
Use aria-expanded for chasm (#1039)
Browse files Browse the repository at this point in the history
* Use aria-expanded for chasm

This simplifies the chasm logic and uses an a11y aware attribute.

* Remove unused var
  • Loading branch information
nmattia authored Nov 21, 2022
1 parent 898f2ad commit c2eaaac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 6 additions & 9 deletions src/frontend/src/components/authenticateBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,15 @@ const mkChasm = ({ info, message }: ChasmOpts): TemplateResult => {
/* Toggle the chasm open/closed */
const chasmToggle = () =>
withRef(chasmRef, (chasm) => {
const classes = chasm.classList;

if (classes.contains("c-chasm--closed")) {
classes.remove("c-chasm--closed");
classes.add("c-chasm--open");
const expanded = chasm.getAttribute("aria-expanded") === "true";
if (!expanded) {
chasm.setAttribute("aria-expanded", "true");

withRef(chasmToggleRef, (arrow) =>
arrow.classList.add("c-chasm__button--flipped")
);
} else if (classes.contains("c-chasm--open")) {
classes.remove("c-chasm--open");
classes.add("c-chasm--closed");
} else {
chasm.setAttribute("aria-expanded", "false");

withRef(chasmToggleRef, (arrow) =>
arrow.classList.remove("c-chasm__button--flipped")
Expand All @@ -174,7 +171,7 @@ const mkChasm = ({ info, message }: ChasmOpts): TemplateResult => {
<p class="t-paragraph t-weak"><span id="alternative-origin-chasm-toggle" class="t-action" @click="${chasmToggle}" >${info} <span ${ref(
chasmToggleRef
)} class="t-link__icon c-chasm__button">${caretDownIcon}</span></span>
<div ${ref(chasmRef)} class="c-chasm c-chasm--closed">
<div ${ref(chasmRef)} class="c-chasm" aria-expanded="false">
<div class="c-chasm__arrow"></div>
<div class="t-weak c-chasm__content">
${message}
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -1176,13 +1176,13 @@ a:hover,
margin-right: calc(-1.25 * var(--rs-card-bezel));
}

.c-chasm--closed {
.c-chasm[aria-expanded="false"] {
max-height: 0;
visibility: hidden;
transition: max-height 0.15s ease-out;
}

.c-chasm--open {
.c-chasm[aria-expanded="true"] {
max-height: calc(5em * var(--vs-line-height) + var(--rs-card-bezel) * 2);
visibility: visible;
transition: max-height 400ms cubic-bezier(0.3, 0.7, 0, 1);
Expand Down

0 comments on commit c2eaaac

Please sign in to comment.