Skip to content
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 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silver-items-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-styles': patch
---

Refactored the new focus style to only be visible when using keyboard for form elements.
40 changes: 34 additions & 6 deletions packages/styles/src/mixins/_utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@
outline: none;
}

@mixin focus-style($border-radius: commons.$border-radius, $vendor-prefix: '') {
&: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;
@mixin focus-style($vendor-prefix: '') {
outline-style: none;
outline-offset: spacing.$size-line;
outline-width: spacing.$size-line;
outline-color: var(--post-focus-color);

// :has(:focus-visible) mimic a focus-visible-within pseudo-class
&:is(:focus-visible, :has(:focus-visible), .pretend-focus)#{$vendor-prefix} {
outline-style: solid;
border-radius: commons.$border-radius !important;

@include high-contrast-mode() {
outline-color: Highlight;
Expand All @@ -100,10 +105,33 @@
// 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-style: solid;
border-radius: commons.$border-radius !important;

@include high-contrast-mode() {
outline-color: Highlight;
}

// In case rules need to be slightly adjusted
@content;
}
}
}

@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;
}
}
}
Loading