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

@utrecht/focus-ring-css

v1.2.0

Published

Form component for the Municipality of Utrecht based on the NL Design System architecture

Downloads

164

Readme

Focus

In CSS there are two important pseudo-classes we use: :focus and :focus-visible.

Browser support for :focus-visible unfortunately does not include Safari 15.

Comparison

:focus:

  • Not visible on disabled interactive elements.
  • Only in this state for a very short time when a mouse click or touch interaction triggers activation, for components such as a button or link.
  • In this state for longer for elements that cannot be activated, such as a textbox.
  • Remains in this state after activation for some components, such as a checkbox.
  • Visual effect can vary per component:
    • different background color
    • different border width
    • different border color
    • different text underline style

:focus-visible:

  • Visible even on disabled interactive elements.
  • Looks very similar across components, because user needs to keep track of focused element.
  • Should draw attention.

Design for :focus

  • The design for :focus should be distinguishable from the :hover design. When a user did not configure their system to always make focus visible using for example a focus ring, the user should be able to know which component will be activated when pressing the Enter key. When focus and hover state look similar, it might not possible to know which element would be activated.
  • When using color, use a consistent color to convey focus. Choose a color that can be combined with other states, such as combining the red color for invalid state with your color for focus state.
  • When changing the font-weight of a component as focus state, it might cause unintended layout shifts, so it might not be the ideal option.

Design for :focus-visible

  • A focus ring should not obscure the content inside the focused area.
  • A focus ring should not obscure surrounding content. This consideration can also affect the minimum space between focusable elements.
  • A focus ring should be visible with sufficient contrast on both dark and light backgrounds.
  • A focus ring should be visible on backgrounds with unknown and mixed colors, such as background images.
  • When using CSS with overflow: hidden in your component, the outline rendering can become partially or completely invisible. Be careful not to break the focus indication when using overflow: hidden.

CSS

  • The default browser focus outline must not be removed, but it may be replaced by something better suited for the design.
  • The default browser focus outline is not perceivable on certain background colors, so for many designs it is benificial to replace the default styling with a higher contrast focus ring.
  • When CSS outline properties are set to a CSS variable, make sure use revert as fallback value: this way the default styling is not removed when the custom property is not set.

Related reading