Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
add solution for double link problem to Tiles [DIGAUD-4518]
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhmarsh committed Dec 27, 2021
1 parent 45c07f7 commit d4601d2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/components/tile/tile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
}

.tile__image {
position: relative; // for invisible link

.tile--hero & {
margin: 0 0 $spacing-xxs 0;
}
Expand Down
58 changes: 28 additions & 30 deletions src/components/tile/tile.stories.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,60 @@
import html from "../../../.storybook/helpers/html";
import repeat from "../../../.storybook/helpers/repeat";
import { withKnobs, text, boolean, number } from "@storybook/addon-knobs";
import { sizesTemplate } from "../image-container/image-container.stories";
import greekHall from "../../../.storybook/assets/images/greek-hall";

export default { title: "Tiles", decorators: [withKnobs] };

const { image16x9 } = greekHall;

const heading = (groupName="Tile") => {
const link = boolean("Link?", true, groupName);
const title = text("Title", "The Medici: Portraits and Politicis, 1512-1570", groupName);
return link ? html`<a href="#">${title}</a>` : title;
export default {
title: "Tiles",
args: {
heading: "The Medici: Portraits and Politicis, 1512-1570",
link: "/#",
subheading: "Through October 11",
body: "The Met Fifth Avenue",
image16x9
}
};

const Tile = () => html`
const Tile = (args) => html`
<div class="tile">
<div class="tile__image image-container">
<img class="image-container__image" alt="${image16x9.alt}" width="${image16x9.width}" height="${image16x9.height}"
${args.link ? html`<a class="invisible-redundant-link" aria-hidden="true" tabindex="-1" href="${args.link}"></a>` : ""}
<img class="image-container__image" alt="${args.image16x9.alt}" width="${args.image16x9.width}" height="${args.image16x9.height}"
src="${image16x9.srcSet.fallback}" srcset="${sizesTemplate(image16x9.srcSet)}" sizes="(orientation: landscape) 21vw, 50vw" />
</div>
<div>
<h4 class="tile__heading">${heading()}</h4>
<div class="tile__subheading">${text("Subheading", "Through October 11", "Tile")}</div>
<div class="tile__body">${text("Body", "The Met Fifth Avenue", "Tile")}</div>
<h4 class="tile__heading">${args.link ? html`<a href="${args.link}">${args.heading}</a>` : args.heading}</h4>
<div class="tile__subheading">${args.subheading}</div>
<div class="tile__body">${args.body}</div>
</div>
</div>`;

const HeroTile = () => html`
const HeroTile = (args) => html`
<div class="tile tile--hero">
<div class="tile__image image-container">
${args.link ? html`<a class="invisible-redundant-link" aria-hidden="true" tabindex="-1" href="${args.link}"></a>` : ""}
<img class="image-container__image" alt="${image16x9.alt}" width="${image16x9.width}" height="${image16x9.height}"
src="${image16x9.srcSet.fallback}" srcset="${sizesTemplate(image16x9.srcSet)}" sizes="(orientation: landscape) 42.5vw, 85vw" />
</div>
<div>
<h3 class="tile__heading">${heading("Hero Tile")}</h3>
<div class="tile__subheading">${text("Subheading", "Through October 11", "Hero Tile")}</div>
<div class="tile__body">${text("Body", "The Met Fifth Avenue", "Hero Tile")}</div>
<h3 class="tile__heading">${args.link ? html`<a href="${args.link}">${args.heading}</a>` : args.heading}</h3>
<div class="tile__subheading">${args.subheading}</div>
<div class="tile__body">${args.body}</div>
</div>
</div>`;

const TileGroup = () => {
const options = {
range: true,
min: 1,
max: 36,
step: 1,
};

const numberOfTiles = number("Number of Tiles",5, options, "Tile Group");

return html`
const TileGroup = (args) => html`
<div class="tile-group">
${HeroTile()}
${HeroTile(args)}
<ul class="tile-group__list">
${repeat(numberOfTiles, html`<li class="tile-group__tile">${Tile()}</li>`)}
${repeat(args.numberOfTiles, html`<li class="tile-group__tile">${Tile(args)}</li>`)}
</ul>
</div>`;};
</div>`;

TileGroup.args = {
numberOfTiles: 5,
};

TileGroup.parameters = {
chromatic: { viewports: [320, 1280] }
Expand Down
14 changes: 14 additions & 0 deletions src/global/accessibility.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@
white-space: nowrap;
width: 1px;
}

.invisible-redundant-link {
// e.g. to solve for double link problem on cards
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;

&:not([aria-hidden="true"][tabindex="-1"]) {
// bad implementation!
border: 2px solid red;
};
};

0 comments on commit d4601d2

Please sign in to comment.