-
Notifications
You must be signed in to change notification settings - Fork 14
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
fix(styles): Hide focus state when unnecessary and make design more coherent #2810
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d1213eb
fix(styles): Hide focus state when unnecessary and make design more c…
imagoiq bc8e8e9
Remove border-radis parameter
imagoiq b251345
Simplify
imagoiq 634c8f0
Merge branch 'main' into fix/2376-new-focus-mixins-focus-within
imagoiq 97a66f1
Add changeset
imagoiq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,8 @@ | |
} | ||
|
||
@mixin focus-style($border-radius: commons.$border-radius, $vendor-prefix: '') { | ||
&:is(:focus-visible, :focus-within, .pretend-focus)#{$vendor-prefix} { | ||
// :has(:focus-visible) mimic a focus-visible-within pseudo-class | ||
&:is(:focus-visible, :has(:focus-visible), .pretend-focus)#{$vendor-prefix} { | ||
outline-offset: spacing.$size-line; | ||
imagoiq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
outline: spacing.$size-line solid var(--post-focus-color); | ||
border-radius: $border-radius; | ||
|
@@ -100,10 +101,34 @@ | |
// In case rules need to be slightly adjusted | ||
@content; | ||
} | ||
|
||
// When a browser doesn't support :has, use focus-within as a fallback. This means that focus state is displayed on focus and not on focus-visible only (except some browsers like Safari). | ||
@supports not selector(:has(:focus-visible)) { | ||
&:is(:focus-visible, :focus-within, .pretend-focus)#{$vendor-prefix} { | ||
outline-offset: spacing.$size-line; | ||
outline: spacing.$size-line solid var(--post-focus-color); | ||
border-radius: $border-radius; | ||
|
||
@include high-contrast-mode() { | ||
outline-color: Highlight; | ||
} | ||
|
||
// In case rules need to be slightly adjusted | ||
@content; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a duplicated code, but I don't know how to improve that situation. We cannot use a placeholder here and the |
||
} | ||
} | ||
} | ||
|
||
@mixin focus-style-custom($vendor-prefix: '') { | ||
&:is(:focus-visible, :focus-within, .pretend-focus)#{$vendor-prefix} { | ||
// :has(:focus-visible) mimic a focus-visible-within pseudo-class | ||
&:is(:focus-visible, :has(:focus-visible), .pretend-focus)#{$vendor-prefix} { | ||
@content; | ||
} | ||
|
||
// When a browser doesn't support :has, use focus-within as a fallback. This means that focus state is displayed on focus and not on focus-visible only (except some browsers like Safari). | ||
@supports not selector(:has(:focus-visible)) { | ||
&:is(:focus-visible, :focus-within, .pretend-focus)#{$vendor-prefix} { | ||
@content; | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's up with that vendor prefix stuff? It's not used anywhere and is bound to break the selector. Can we remove it?
Also, I would not want to change the border radius on focus if there was none before. I think those params can go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the vendor prefix, it is used here: https://github.com/swisspost/design-system/pull/2781/files#diff-f8aaec5942d0b7bdec7264460de3a7becec65dfa3ca88797a0875320dade340fR84
Previously it was used on more lines. Sure it look a bit odd, but it looks practical right now.
The border-radius could have unwanted side effects, you are right, but we need it to shape the outline. Perhaps, we want to add the outline into a
::after
instead?