Skip to content

Rewrite focus ring logic in View#1940

Merged
matyasf merged 1 commit intomasterfrom
focus_ring_fix
May 8, 2025
Merged

Rewrite focus ring logic in View#1940
matyasf merged 1 commit intomasterfrom
focus_ring_fix

Conversation

@matyasf
Copy link
Collaborator

@matyasf matyasf commented Apr 11, 2025

The main change is to use CSS outline instead of an absolute positioned :before element. This has the following effects:

+ Now focus ring is not part of the size calculation, so there will be no scrollbars e.g. if the overflow is set to auto in some parent element.
+ View now can display focus rings even if its position is not absolute
+ Page CSS and code became simpler since we are not using :before CSS pseudo tags
+ Focus ring will follow fancy border settings (see View's focus ring examples)
~ The focus animation is very slightly different. (the old one was using scale, this uses outline-offset)
- We were using the outline prop to display the debug border with the withVisualDebug prop. To fix this conflict the debug border now uses box-shadow; this overwrite the normal shadow of the View and is not a dashed but a solid line.

For future components we should use View's focus ring for all our components, this could be done with the https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-within CSS pseudo-class, I've added a new prop for it (focusWithin). But sadly we define how the focus ring should look like in several component's theme and use there theme variables, so removing these and switching to this new prop would be a breaking change.

To test:

@matyasf matyasf requested a review from Copilot April 11, 2025 21:28
@matyasf matyasf self-assigned this Apr 11, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@matyasf matyasf changed the title Fix focus ring causing scrollbars to appear WIP Fix focus ring causing scrollbars to appear Apr 11, 2025
@github-actions
Copy link

github-actions bot commented Apr 11, 2025

PR Preview Action v1.6.1
Preview removed because the pull request was closed.
2025-05-08 16:02 UTC


When `direction` is set to `column`, Flex.Items' `overflowY` property is automagically set
to `auto` to account for content overflow with a vertical scrollbar.
to `auto` to account for content overflow with a vertical scrollbar. Add padding, so focus rings are not cut off.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't like that we are doing this automagically, but I think it would be a breaking change to remove

@matyasf matyasf force-pushed the focus_ring_fix branch 4 times, most recently from e87dc87 to 6eb8d1b Compare April 30, 2025 12:30
@matyasf matyasf changed the title WIP Fix focus ring causing scrollbars to appear Rewrite focus ring logic in View Apr 30, 2025
@instructure instructure deleted a comment from Copilot AI Apr 30, 2025
it uses now the outline CSS prop instead of a :before pseudo class.
This has several advantages:
- View can now display focus rings even if the position is not absolute
- focus rings follow border settings if they are not the same for all corners
page CSS is simpler
Also add a new prop that will be useful when we use this code for all components that need to
display a focus ring
@matyasf matyasf requested review from HerrTopi and balzss April 30, 2025 12:47
@matyasf matyasf merged commit b1bc451 into master May 8, 2025
11 checks passed
@matyasf matyasf deleted the focus_ring_fix branch May 8, 2025 16:01
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.

3 participants