Skip to content

chore: Use CSS-native :focus-visible to track visible focus state (batch 3) #3607

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

avinashbot
Copy link
Member

@avinashbot avinashbot commented Jun 25, 2025

Description

Reducing the potential blast radius of a visual change that affects tons of components. I'll be removing the internal JS-based focus-visible solution in individual batches. This one contains all the weird interesting changes I've had to make, but it's the last one before I remove useFocusVisible() from the components package entirely.

See #3585 for the big original PR.

Related links, issue #, if available: AWSUI-60845

How has this been tested?

Tested the whole big PR in my dev pipeline, and the individual changes just manually.

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

)
);
}
// stylelint-disable-next-line selector-combinator-disallowed-list
Copy link
Member Author

@avinashbot avinashbot Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This utility is used four times in the entirety of the package (and all @cloudscape-design packages). You'll see the other three in this PR too. I don't think it's worth pulling in component toolkit just for a tiny little mixin that isn't even particularly Cloudscape-specific to begin with.

@@ -14,12 +14,22 @@ import { PointerEventMock } from '../../../../../lib/components/internal/utils/p
import styles from '../../../../../lib/components/internal/components/drag-handle-wrapper/styles.css.js';
import tooltipStyles from '../../../../../lib/components/internal/components/tooltip/styles.css.js';

function mockFocusVisible(value: boolean) {
Copy link
Member Author

@avinashbot avinashbot Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some jerk (me) wrote in a dependency on the presence of data-awsui-focus-visible="true" as part of the component logic. Rewrote that to just check CSS instead (using document.body.matches()). And we can mock that just inside this file.

document.body.dataset.awsuiFocusVisible = 'true';
handle.focus();
fireEvent.pointerDown(handle);
fireEvent.pointerUp(handle);
Copy link
Member Author

@avinashbot avinashbot Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buttons show up either on click (pointer down + no drag + pointer up) or on keyboard focus. The pointer method of doing this is easier and more straightforward to implement than faking keyboard focus.

Copy link

codecov bot commented Jun 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.59%. Comparing base (c606ac5) to head (bf57dd9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3607   +/-   ##
=======================================
  Coverage   96.59%   96.59%           
=======================================
  Files         807      807           
  Lines       23582    23582           
  Branches     8261     8271   +10     
=======================================
  Hits        22780    22780           
+ Misses        795      748   -47     
- Partials        7       54   +47     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@avinashbot avinashbot marked this pull request as ready for review June 25, 2025 14:41
@avinashbot avinashbot requested a review from a team as a code owner June 25, 2025 14:42
@avinashbot avinashbot requested review from Al-Dani and removed request for a team June 25, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants