fix: ensure focus outlines match button/link size on click #453
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We used to maintain the hit area for buttons/links during click by having an unstyled element for the button and then applying all visual styles to another element nested directly within the button. This mostly worked, but it introduced a visual issue where the focus outline would be out of sync with the button size on click.
To fix this, I've switched to a different approach where the button/link elements are made with a single element, and the increased hit area is managed by an absolutely positioned pseudo element that is scaled up on click. I implemented this with CSS variables to manage the different hover and active sizes so that we can dynamically calculate the inverse scale required to maintain the hit area.
Note that this means we no longer have the
transform
property on Box since our approach is more complicated now. Instead, interaction sizing is managed by a CSS utility function calledtouchableStyles
that accepts the same values astransform
but returns the required class names.