Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[selectors] Should :active match spacebar down? #7332

Open
jonathantneal opened this issue Jun 1, 2022 · 0 comments
Open

[selectors] Should :active match spacebar down? #7332

jonathantneal opened this issue Jun 1, 2022 · 0 comments
Labels
selectors-4 Current Work

Comments

@jonathantneal
Copy link
Contributor

From the Selectors Level 4 specification

The :active pseudo-class applies while an element is being activated by the user. For example, between the times the user presses the mouse button and releases it.

The :active pseudo-class is useful for providing immediate feedback about the expected click behavior of an element.

Its usage is well documented, in sources from Adobe, Google, Salesforce, Tailwind, and CSS Tricks.

The :active pseudo-class is versatile for pointers, in that it is not limited to specific elements.

Example from MDN:

p:active { background: #eee; }

There is a keyboard limitation to the :active pseudo-class that many sources do not mention. Between the time a user presses the spacebar and releases it, the :active pseudo-class is only ever applied to a <button> element. Some resources may even suggest that the pointer-triggered :active and the keyboard-triggered :active should always work the same.

The :active pseudo-class is used to style an element that has been “activated” either by a pointing device or by a tap on a touchscreen device. It can also be triggered by the keyboard, just like the :focus pseudo-class.
An Ultimate Guide To CSS Pseudo Classes And Pseudo Elements. Smashing Magazine

It is my belief that :active state is equally valuable to style for both keyboard and the pointer interactions.

Should the :active pseudo-class apply to any active element between the times the user presses the spacebar and releases it?

I think opening this behavior up to all elements should be considered, or perhaps alongside some other mechanism like :focusable.

I do not know for certain why :active does not behave this way already, but I suspect it is related to the early WWW distinctions between hyperlinks and buttons, similar to how a spacebar press-and-release does not “click” a hyperlink. This is a problematic guess, tho, since the :active state applies to non-clickable elements when used with a pointer.

I was confused by a note in the specification that reads “there may be document-language or implementation-specific limits on which elements can become :active.” This note links to the HTML5 specification which defines a list of activatable elements. However, the HTML5 specification does not list any special criteria for spacebar interaction, and the criteria for :active — which includes “if the element is focusable” — suggests to me that it could apply to any element activated.

@fantasai fantasai added the selectors-4 Current Work label Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
selectors-4 Current Work
Projects
None yet
Development

No branches or pull requests

2 participants