npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wolfco/inclusive-card

v1.2.2

Published

A web component to make linked cards friendlier to assistive technologies (e.g., screen readers).

Downloads

54

Readme

Inclusive Card

A web component to make linked cards friendlier to assistive technologies (e.g., screen readers).

Rationale

This web component is inspired by and directly emulates the card component proposed in Heydon Pickering's collection of Inclusive Components.

A traditional approach to card layouts that have a call to action in them is to wrap the entire layout in an anchor element, which is something that HTML5 made possible. However, when a screen reader (for example) encounters that layout, it will more often than not read the entirety of whatever is enclosed by the anchor element as the "content" of the anchor itself. This could include the full URL to an image in the card, a text summary, and anything else one might put in their card layouts.

This component attempts to remedy that by allowing an author to write sensible markup that isn't wrapped in an anchor element. A card that needs to be linked can have an independent anchor in the its contents. The component adds a small amount of JavaScript to send click events on the card itself to the destination specified in the href attribute of a given link within the card.

Installation and Usage

npm install @wolfco/inclusive-card

import 'inclusive-card';

<inclusive-card link-target="[data-card-link]">
  <article>
    <img src="foo" alt="foo" />
    <h1>Article Title</h1>
    <p>Article summary...</p>
    <a data-card-link href="/foo">Learn more about foo</a>
  </article>
</inclusive-card>

Attributes

The component's primary attribute is link-target, which is a string representing a CSS selector meant to identify the anchor to derive an href from. Any valid CSS selector will work. For example: link-target="[data-card-link]" or link-target="div > .link".

Exclusions

There are cases where you might have a card with a primary CTA that also has secondary CTAs, or links within article summary text. In those cases you'd need to distinguish between a link meant to apply to the entire card and links that should take a user somewhere else when clinked on directly.

For example:

<inclusive-card link-target="[data-card-link]">
  <article >
    <img src="foo" alt="foo" />
    <h1>Article Title</h1>
    <p>Lorem ipsum dolor <a href="https://some-link.com">sit amet</a>,
    consectetur <a href="https://some-other-link.com">adipisicing elit</a>.
    A aliquam aspernatur culpa delectus eaque eum ipsum.</p>
    <a data-card-link href="/foo">Learn more about foo</a>
  </article>
</inclusive-card>

In that case, you can pass an exclusions attribute to the card, which accepts a string meant to be used as a CSS selector. Items matching that string will simply behave like regular links.

<inclusive-card exclusions="[data-exclusion]" link-target="[data-card-link]">
  <article>
    <img src="foo" alt="foo" />
    <h1>Article Title</h1>
    <p>Lorem ipsum dolor <a data-exclusion href="https://some-link.com">sit amet</a>,
    consectetur <a data-exclusion href="https://some-other-link.com">adipisicing elit</a>.
    A aliquam aspernatur culpa delectus eaque eum ipsum.</p>
    <a data-card-link href="/foo">Learn more about foo</a>
  </article>
</inclusive-card>