Skip to content

Commit

Permalink
feat(shs-6003): remove aria attributes in summary and details since t…
Browse files Browse the repository at this point in the history
…hey are not needed
  • Loading branch information
Mari Nez committed Feb 27, 2025
1 parent 15a3922 commit 1c72762
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{% if description %}
<details {{ attributes }} open>
<summary class="hb-timeline-item__summary" aria-expanded="true" aria-pressed="true">
<summary class="hb-timeline-item__summary">
<div class="hb-timeline-item__heading">
{{ summary }}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,11 @@
items.forEach((item) => {
item.removeAttribute('open');
});

// Find the summary element and update the aria attribute values
const summaries = timeline.querySelectorAll(
'.hb-timeline-item__summary',
);

summaries.forEach((summary) => {
summary.setAttribute('aria-expanded', 'false');
summary.setAttribute('aria-pressed', 'false');
});
});

// When a user clicks on a timeline, update the aria properties accordingly
// When a user clicks on a timeline, set open property accordingly
const timelineItems = once('timeline-item', '.hb-timeline-item', context);

if (timelineItems) {
timelineItems.forEach((timelineItem) => {
const summary = timelineItem.querySelector(
'.hb-timeline-item__summary',
);

// Find the value of aria-expanded for a timeline item summary
let ariaExpanded = summary.getAttribute('aria-expanded');

// Update aria values!
summary.addEventListener(('keypress', 'click'), () => {
if (ariaExpanded === 'true') {
summary.setAttribute('aria-expanded', 'false');
summary.setAttribute('aria-pressed', 'false');
} else {
summary.setAttribute('aria-expanded', 'true');
summary.setAttribute('aria-pressed', 'true');
}

// Retain updated value for the aria-expanded attribute
ariaExpanded = summary.getAttribute('aria-expanded');
});
});
}

const searchQuery = new URLSearchParams(window.location.search);
const params = Object.fromEntries(searchQuery.entries());

Expand All @@ -67,10 +32,7 @@

timelineItems.forEach((timeline) => {
if (timeline.textContent.toLowerCase().includes(searchTerm)) {
const summary = timeline.querySelector('summary');
timeline.setAttribute('open', '');
summary.setAttribute('aria-expanded', 'true');
summary.setAttribute('aria-pressed', 'true');
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
transition: transform 150ms ease-in-out;
}

[aria-expanded="true"] & {
[open] & {
&::after {
transform: scaleY(-1);
}
Expand Down

0 comments on commit 1c72762

Please sign in to comment.