Skip to content

Commit

Permalink
feat: add CSS variables to control focus outline (#973)
Browse files Browse the repository at this point in the history
Co-authored-by: kkmch <[email protected]>
  • Loading branch information
Kyzyl-ool and kkmch authored Sep 2, 2023
1 parent e19d0b9 commit d926ef8
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 14 deletions.
11 changes: 11 additions & 0 deletions src/components/Breadcrumbs/Breadcrumbs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ $block: '.#{variables.$ns}breadcrumbs';
white-space: nowrap;
text-overflow: ellipsis;

&:focus {
outline: 2px solid var(--g-color-line-focus);
outline-offset: -4px; // due to padding
border-radius: calc(
var(--g-focus-border-radius) + 4px
); // +4px as outline-offset is -4px
}
&:focus:not(:focus-visible) {
outline: 0;
}

&_current {
padding: 0 8px;
}
Expand Down
7 changes: 6 additions & 1 deletion src/components/Button/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $iconWidth: 16px;
#{$block} {
--yc-button-background-color: transparent;
--yc-button-background-color-hover: var(--g-color-base-simple-hover);
--yc-button-outline-color: var(--g-color-line-misc);
--yc-button-outline-color: var(--g-color-line-focus);
--yc-button-icon-space: calc(
var(--yc-button-padding) + var(--yc-button-icon-size) + var(--yc-button-icon-offset)
);
Expand Down Expand Up @@ -150,6 +150,11 @@ $iconWidth: 16px;
&_action {
--yc-button-background-color: var(--g-color-base-brand);
--yc-button-background-color-hover: var(--g-color-base-brand-hover);
--yc-button-outline-color: var(--g-color-base-brand);

&:focus::before {
outline-offset: 1px;
}

@include button-text-color(var(--g-color-text-brand-contrast));
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Card/Card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $block: '.#{variables.$ns}card';

&:focus::after {
content: '';
box-shadow: 0 0 0 2px var(--g-color-line-misc);
box-shadow: 0 0 0 2px var(--g-color-line-focus);
}

&:focus:not(:focus-visible)::after {
Expand Down Expand Up @@ -87,7 +87,7 @@ $block: '.#{variables.$ns}card';

&:focus::after {
content: '';
box-shadow: 0 0 0 2px var(--g-color-line-misc);
box-shadow: 0 0 0 2px var(--g-color-line-focus);
}

&:focus:not(:focus-visible)::after {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Card/__tests__/Card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {render, screen} from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import {Button} from '../../Button';
import {Card} from '../Card';
import type {CardSize, CardTheme, CardType, CardView} from '../Card';
import {Card} from '../Card';

const qaId = 'card-component';
const cardText = 'Some text';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Checkbox/Checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ $block: '.#{variables.$ns}checkbox';
}

&__control:focus + &__outline {
box-shadow: 0 0 0 2px var(--g-color-line-misc);
box-shadow: 0 0 0 2px var(--g-color-line-focus);
}

&__control:focus:not(:focus-visible) + &__outline {
Expand Down
7 changes: 5 additions & 2 deletions src/components/Disclosure/Disclosure.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ $gap: 8px;
font-size: inherit;
line-height: inherit;
font-weight: inherit;
border-radius: var(--g-focus-border-radius);

&:focus {
outline: 2px solid var(--g-color-line-misc);
outline: 2px solid var(--g-color-line-focus);
}

&:focus:not(:focus-visible) {
outline: none;
outline: 0;
}
}
&__trigger_arrow-right {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Link/Link.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ $block: '.#{variables.$ns}link';
touch-action: manipulation;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
cursor: pointer;
border-radius: var(--g-focus-border-radius);

&:focus {
outline: 2px solid var(--g-color-line-misc);
outline: 2px solid var(--g-color-line-focus);
}

&:focus:not(:focus-visible) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Popover/Popover.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use '../../../styles/mixins.scss';
@use '../../../styles/mixins';
@use '../variables';

$block: '.#{variables.$ns}popover';
Expand Down
4 changes: 2 additions & 2 deletions src/components/Popover/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type PopoverButtonProps = {
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
};

export type PopoverExternalProps = {
export interface PopoverExternalProps {
/** Tooltip's trigger content over which the tooltip is shown */
children?: TriggerProps['children'];
/** Tooltip's title */
Expand Down Expand Up @@ -70,7 +70,7 @@ export type PopoverExternalProps = {
autoFocus?: boolean;
/** Focused element when the popover closes */
restoreFocusRef?: React.RefObject<HTMLElement>;
};
}

export type PopoverBehaviorProps = {
/** Tooltip open/close behaviour when `openOnHover`
Expand Down
2 changes: 1 addition & 1 deletion src/components/Radio/Radio.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ $discMarginLSize: 6px;
}

&__control:focus + &__outline {
box-shadow: 0 0 0 2px var(--g-color-line-misc);
box-shadow: 0 0 0 2px var(--g-color-line-focus);
}

&__control:focus:not(:focus-visible) + &__outline {
Expand Down
2 changes: 1 addition & 1 deletion src/components/RadioButton/RadioButton.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $block: '.#{variables.$ns}radio-button';
cursor: inherit;

&:focus + #{$block}__option-outline {
box-shadow: 0 0 0 2px var(--g-color-line-misc);
box-shadow: 0 0 0 2px var(--g-color-line-focus);
}

&:focus:not(:focus-visible) + #{$block}__option-outline {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Switch/Switch.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $block: '.#{variables.$ns}switch';
}

&__control:focus + &__outline {
box-shadow: 0 0 0 2px var(--g-color-line-misc);
box-shadow: 0 0 0 2px var(--g-color-line-focus);
}

&__control:focus:not(:focus-visible) + &__outline {
Expand Down
7 changes: 7 additions & 0 deletions src/components/Tabs/Tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ $block: '.#{variables.$ns}tabs';
&-content {
display: flex;
align-items: center;
border-radius: var(--g-focus-border-radius);

#{$block}__item_overflow & {
min-width: 0;
Expand Down Expand Up @@ -79,6 +80,12 @@ $block: '.#{variables.$ns}tabs';
&-icon > svg {
display: block;
}

&:focus {
#{$block}__item-content {
outline: 2px solid var(--g-color-line-focus);
}
}
}

&_direction_horizontal {
Expand Down
2 changes: 2 additions & 0 deletions styles/themes/common/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
--g-border-radius-m: 6px;
--g-border-radius-l: 8px;
--g-border-radius-xl: 10px;

--g-focus-border-radius: 2px;
}
1 change: 1 addition & 0 deletions styles/themes/dark-hc/line.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
--g-color-line-warning: var(--g-color-private-yellow-550-solid);
--g-color-line-danger: var(--g-color-private-red-550-solid);
--g-color-line-misc: var(--g-color-private-cool-grey-550-solid);
--g-color-line-focus: var(--g-color-private-cool-grey-550-solid);

--g-color-line-light: var(--g-color-private-white-500);
}
1 change: 1 addition & 0 deletions styles/themes/dark/line.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
--g-color-line-warning: var(--g-color-private-yellow-450);
--g-color-line-danger: var(--g-color-private-red-450);
--g-color-line-misc: var(--g-color-private-cool-grey-450);
--g-color-line-focus: var(--g-color-private-cool-grey-450);

--g-color-line-light: var(--g-color-private-white-500);
}
1 change: 1 addition & 0 deletions styles/themes/light-hc/line.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
--g-color-line-warning: var(--g-color-private-yellow-600-solid);
--g-color-line-danger: var(--g-color-private-red-450);
--g-color-line-misc: var(--g-color-private-cool-grey-450);
--g-color-line-focus: var(--g-color-private-cool-grey-450);

--g-color-line-light: var(--g-color-private-white-500);
}
1 change: 1 addition & 0 deletions styles/themes/light/line.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
--g-color-line-warning: var(--g-color-private-yellow-600-solid);
--g-color-line-danger: var(--g-color-private-red-450);
--g-color-line-misc: var(--g-color-private-cool-grey-450);
--g-color-line-focus: var(--g-color-private-cool-grey-450);

--g-color-line-light: var(--g-color-private-white-500);
}

0 comments on commit d926ef8

Please sign in to comment.