Skip to content

[css-ui] interactivity: focusable #13040

@LeaVerou

Description

@LeaVerou

Motivation

The ability to make elements focusable via CSS has come up before by @frivoal.

There is already precedent in controlling focusability via CSS, just not directly, but as a side effect of other features: overflow: auto / scroll makes scroll containers focusable, but only when there is something to scroll (demo).

Additionally, there is precedent of CSS introducing non-focusable interactive features, which is an a11y footgun:

  • resize introduces interactive UI that manipulates CSS properties, but is not keyboard focusable
  • :hover allows creating interactive UIs very easily, but there is no way to make them keyboard accessible without HTML changes and/or JS, which is an a11y footgun. Authors should not be forced to choose between DX and accessibility.
  • We’ve recently discussed image-animation, something like this could make it incredibly more useful.
  • It is very common to have content that only becomes interactive under certain conditions, e.g. smaller screen sizes.
  • Making generated content focusable would obliterate a lot of specialized pseudo-elements being proposed (especially if down the line we can control ARIA roles too)

Proposal

We now have an interactivity property that only goes the other way with interactivity: inert, so adding an interactivity: focusable value seems like the natural next step. Presumably any philosophical arguments around controlling focus with CSS would have also applied to that.

We could later even add more granular controls to facilitate patterns like tabs, radios etc.
But as an MVP, even the very simple ability to make an element focusable would eliminate a ton of custom code, and would make it much easier for authors to create accessible experiences.

Certain combinations of other properties & values could make interactivity compute to focusable (e.g. overflow: auto).

Because this is dynamic, it can also be used as a primitive to implement other features (e.g. focusgroup).
E.g. it’s conceivable this could be part of the UA stylesheet even:

[tabindex=0] { /* or [tabindex >= 0] if #354 moves forwards */
	interactivity: focusable !important;
}

Issues

  • While this makes it easier to create keyboard accessible experiences, with no ability to assign other ARIA attributes, it could be a false sense of security ("oh my popup menu is keyboard accessible, I don't need to do anything else"). But the way to solve this is to provide control over those as well, not to make it harder to make a UI keyboard accessible.
  • This would preclude a :focusable selector, as it would now be cyclical. However, I think the value of this is worth it. We can always design a slightly different version of :focusable that is not affected by CSS to solve the core problem that proposal is addressing. And given that there are already CSS properties that affect focusability, that ship has probably sailed anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Agenda+a11y-trackerGroup bringing to attention of a11y, or tracked by the a11y Group but not needing response.css-ui-4Current Workcss-ui-5open-uiIssues that desire to have Open UI input

    Type

    No type

    Projects

    Status

    Not this meeting?

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions