Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): keep :focus-visible outlines on coarse-pointer devices (#4349)

Baraa Hamodi3592019795d3
diff --git a/.changeset/a11y-reset-focus-visible.md b/.changeset/a11y-reset-focus-visible.md
new file mode 100644
index 0000000000..e54eef43fe
--- /dev/null
+++ b/.changeset/a11y-reset-focus-visible.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] reset: stop suppressing `:focus-visible` outlines on coarse-pointer devices so keyboard users keep the WCAG 2.4.7 focus indicator
+@bhamodi
diff --git a/packages/core/src/reset.css b/packages/core/src/reset.css
index f8941ed48e..b6211f6f38 100644
--- a/packages/core/src/reset.css
+++ b/packages/core/src/reset.css
@@ -360,32 +360,6 @@
-webkit-tap-highlight-color: transparent;
}
- /* ===========================================================================
- Touch Devices
- =========================================================================== */
-
- /*
- * Suppress focus-visible outlines on touch-only devices.
- *
- * Focus rings exist to show keyboard users where focus is. On devices
- * with no hover capability and a coarse pointer (phones, tablets),
- * there's no keyboard navigation — focus rings are visual noise that
- * can flash on tap, on dialog open (showModal auto-focus), or on
- * programmatic focus.
- *
- * This targets touch-only devices specifically:
- * - (hover: none) — no hover capability (not a mouse)
- * - (pointer: coarse) — imprecise pointer (finger, not stylus)
- *
- * Hybrid devices (laptop with touchscreen) are NOT affected because
- * their primary pointer is fine (trackpad/mouse) and hover is available.
- */
- @media (hover: none) and (pointer: coarse) {
- :where(:focus-visible) {
- outline: none;
- }
- }
-
/* ===========================================================================
Color Scheme
=========================================================================== */
diff --git a/packages/core/src/reset.test.ts b/packages/core/src/reset.test.ts
new file mode 100644
index 0000000000..cc57640ab2
--- /dev/null
+++ b/packages/core/src/reset.test.ts
@@ -0,0 +1,60 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * Tests for reset.css invariants that components rely on.
+ *
+ * reset.css is a plain stylesheet, so these tests assert on its source
+ * text (same approach as the reset.css baseline checks in
+ * theme/onMediaTokens.test.ts and AspectRatio/AspectRatio.test.tsx).
+ */
+
+import fs from 'fs';
+import path from 'path';
+
+import {beforeAll, describe, expect, it} from 'vitest';
+
+describe('reset.css accessibility invariants', () => {
+ let ruleBlocks: {selector: string; body: string}[];
+
+ beforeAll(() => {
+ const resetCSS = fs.readFileSync(
+ path.resolve(__dirname, './reset.css'),
+ 'utf-8',
+ );
+ // Strip comments, then collect every innermost `selector { body }`
+ // block. `[^{}]` keeps at-rule preludes (@media, @layer) out of the
+ // selector capture, since their own `{` terminates any earlier match.
+ const stripped = resetCSS.replace(/\/\*[\s\S]*?\*\//g, '');
+ ruleBlocks = [...stripped.matchAll(/([^{}]+)\{([^{}]*)\}/g)].map(
+ ([, selector, body]) => ({selector: selector.trim(), body}),
+ );
+ });
+
+ it('parses rule blocks out of reset.css', () => {
+ // Guards the WCAG assertion below against silently passing if the
+ // block parsing ever breaks.
+ expect(ruleBlocks.length).toBeGreaterThan(20);
+ expect(
+ ruleBlocks.some(({body}) => body.includes('box-sizing: border-box')),
+ ).toBe(true);
+ });
+
+ /**
+ * WCAG 2.4.7 (Focus Visible, Level AA): keyboard focus indicators must
+ * not be suppressed. `:focus-visible` only matches keyboard-style focus,
+ * so any `outline: none` on it removes the focus indicator for keyboard
+ * users — and a `@media (hover: none) and (pointer: coarse)` guard does
+ * not exempt keyboard users on coarse-pointer devices (iPad/phone with a
+ * Bluetooth keyboard, switch-control users).
+ */
+ it('does not suppress :focus-visible outlines (WCAG 2.4.7)', () => {
+ const focusVisibleBlocks = ruleBlocks.filter(({selector}) =>
+ selector.includes(':focus-visible'),
+ );
+ for (const {selector, body} of focusVisibleBlocks) {
+ expect
+ .soft(body, `":focus-visible" rule "${selector}" must keep the outline`)
+ .not.toMatch(/outline(?:-style|-width)?\s*:\s*(?:none|0)/);
+ }
+ });
+});