Skip to content

Commit

Permalink
fix: a11y workaround for splide
Browse files Browse the repository at this point in the history
  • Loading branch information
maxakuru committed Oct 19, 2023
1 parent 9d4fe70 commit 1f6a286
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
38 changes: 20 additions & 18 deletions blocks/card-carousel/card-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ import { loadCSS } from '../../scripts/lib-franklin.js';

const TAG_NAME = 'card-carousel';
const BUNDLE_PATH = (ext) => `${window.hlx.codeBasePath}/blocks/card-carousel/splide.min.${ext}`;
const TEMPLATE = /* html */ `
// NOTE: using divs instead of lists due to an a11y bug in splide
// see: https://github.com/radix-ui/primitives/issues/1703
const TEMPLATE = /* html */ `\
<div class="card-carousel">
<section class="splide">
<div class="splide__track">
<ul class="splide__list">
<li class="splide__slide">
<a href="/" class="card">
<span class="chip">Blog</span>
<h5 class="title">
<span class="eyebrow">Research Report</span>
AppSec for the Modern Engineering Ecosystem
</h5>
</a>
</li>
</ul>
</div>
</section>
</div>
`;
<section class="splide">
<div class="splide__track">
<div class="splide__list">
<div class="splide__slide">
<a href="/" class="card">
<span class="chip">Blog</span>
<h5 class="title">
<span class="eyebrow">Research Report</span>
AppSec for the Modern Engineering Ecosystem
</h5>
</a>
</li>
</ul>
</div>
</section>
</div>`;

const SPLIDE_CONFIG = {
arrowPath:
Expand Down Expand Up @@ -97,6 +98,7 @@ export class CardCarousel extends HTMLElement {
if (loaded && splideRoot) {
const splide = new window.Splide(splideRoot, SPLIDE_CONFIG);
splide.mount();

// Wait a tick and then trigger a refresh on the size
setTimeout(() => {
splide.refresh();
Expand Down
25 changes: 13 additions & 12 deletions blocks/resources/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,21 @@ async function renderXMLAsCards(url) {
year: 'numeric',
});

cards += `
<li class="splide__slide">
<a href="${link[0].textContent}" class="card ${
// NOTE: using divs instead of lists due to an a11y bug in splide
// see: https://github.com/radix-ui/primitives/issues/1703
cards += `\
<div class="splide__slide">
<a href="${link[0].textContent}" class="card ${
background && 'has-custom-background'
}" style="background: ${backgroundStyle}; background-size: cover;">
<span class="chip">${readTime[0].textContent} min. read</span>
<h5 class="title">
<span class="eyebrow"></span>
${title[0].textContent}
${pubDate && `<span class='date'>${pubDateToLocale}</span>`}
</h5>
</a>
</li>
`;
<span class="chip">${readTime[0].textContent} min. read</span>
<h5 class="title">
<span class="eyebrow"></span>
${title[0].textContent}
${pubDate && `<span class='date'>${pubDateToLocale}</span>`}
</h5>
</a>
</div>`;
}

const carouselList = document.querySelector(
Expand Down

0 comments on commit 1f6a286

Please sign in to comment.