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

(web components) Standardize focus treatment #24771

Merged
merged 4 commits into from
Sep 16, 2022
Merged
Changes from 1 commit
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
Next Next commit
Standardized focus treatment to use outline instead of a combinatio…
…n of `border` and `box-shadow`
bheston committed Sep 12, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 1801b73b3c11c58f6670137c7130a95d1effefe6
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@ import { Swatch } from '../../color/swatch';
import {
controlCornerRadius,
designUnit,
focusStrokeOuter,
focusStrokeWidth,
layerCornerRadius,
neutralFillLayerAltRest,
neutralFillLayerRecipe,
@@ -23,6 +21,7 @@ import {
neutralStrokeLayerRest,
strokeWidth,
} from '../../design-tokens';
import { insetFocusTreatment } from '../../styles/patterns/focus';
import { typeRampBase } from '../../styles/patterns/type-ramp';
import { heightNumber } from '../../styles/size';

@@ -96,18 +95,16 @@ export const accordionItemStyles: (
.button::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
top: calc(${strokeWidth} * -1px);
left: calc(${strokeWidth} * -1px);
right: calc(${strokeWidth} * -1px);
bottom: calc(${strokeWidth} * -1px);
cursor: pointer;
}

.button:${focusVisible}::before {
outline: none;
border: calc(${strokeWidth} * 1px) solid ${focusStrokeOuter};
${insetFocusTreatment}
border-radius: calc(${layerCornerRadius} * 1px);
box-shadow: 0 0 0 calc((${focusStrokeWidth} - ${strokeWidth}) * 1px) ${focusStrokeOuter};
}

:host(.expanded) .button:${focusVisible}::before {
@@ -184,8 +181,7 @@ export const accordionItemStyles: (
forcedColorsStylesheetBehavior(
css`
.button:${focusVisible}::before {
border-color: ${SystemColors.Highlight};
box-shadow: 0 0 0 calc((${focusStrokeWidth} - ${strokeWidth}) * 1px) ${SystemColors.Highlight};
outline-color: ${SystemColors.Highlight};
}
.icon {
fill: ${SystemColors.ButtonText};
Original file line number Diff line number Diff line change
@@ -9,15 +9,13 @@ import {
import { SystemColors } from '@microsoft/fast-web-utilities';
import {
controlCornerRadius,
focusStrokeOuter,
focusStrokeWidth,
neutralForegroundActive,
neutralForegroundHover,
neutralForegroundRest,
strokeWidth,
} from '../design-tokens';
import { typeRampBase } from '../styles/patterns/type-ramp';
import { heightNumber } from '../styles/index';
import { offsetFocusTreatment } from '../styles/patterns/focus';

export const breadcrumbItemStyles: (
context: ElementDefinitionContext,
@@ -32,7 +30,6 @@ export const breadcrumbItemStyles: (
${typeRampBase};
min-width: calc(${heightNumber} * 1px);
border-radius: calc(${controlCornerRadius} * 1px);
outline: none;
}

.listitem {
@@ -63,12 +60,8 @@ export const breadcrumbItemStyles: (
color: ${neutralForegroundActive};
}

.control:${focusVisible}::after {
content: '';
position: absolute;
inset: calc(${strokeWidth} * -1px);
box-shadow: 0 0 0 calc(${focusStrokeWidth} * 1px) ${focusStrokeOuter} inset;
border-radius: inherit;
.control:${focusVisible} {
${offsetFocusTreatment}
}

:host(:not([href])),
@@ -115,8 +108,8 @@ export const breadcrumbItemStyles: (
color: ${SystemColors.HighlightText};
fill: currentcolor;
}
:host([href]) .control:${focusVisible}::after {
box-shadow: 0 0 0 calc(${focusStrokeWidth} * 1px) ${SystemColors.LinkText} inset;
.control:${focusVisible} {
outline-color: ${SystemColors.LinkText};
}
`,
),
12 changes: 3 additions & 9 deletions packages/web-components/src/checkbox/checkbox.styles.ts
Original file line number Diff line number Diff line change
@@ -16,8 +16,6 @@ import {
controlCornerRadius,
designUnit,
disabledOpacity,
fillColor,
focusStrokeOuter,
foregroundOnAccentRest,
neutralFillInputAltActive,
neutralFillInputAltFocus,
@@ -30,6 +28,7 @@ import {
strokeWidth,
} from '../design-tokens';
import { typeRampBase } from '../styles/patterns/type-ramp';
import { offsetFocusTreatment } from '../styles/patterns/focus';

export const checkboxStyles: (context: ElementDefinitionContext, definition: CheckboxOptions) => ElementStyles = (
context: ElementDefinitionContext,
@@ -55,7 +54,6 @@ export const checkboxStyles: (context: ElementDefinitionContext, definition: Che
border-radius: calc(${controlCornerRadius} * 1px);
border: calc(${strokeWidth} * 1px) solid ${neutralStrokeStrongRest};
background: ${neutralFillInputAltRest};
outline: none;
cursor: pointer;
}

@@ -107,9 +105,8 @@ export const checkboxStyles: (context: ElementDefinitionContext, definition: Che
}

:host(:${focusVisible}) .control {
box-shadow: 0 0 0 1px ${fillColor}, 0 0 0 3px ${focusStrokeOuter};
background: ${neutralFillInputAltFocus};
border-color: ${focusStrokeOuter};
${offsetFocusTreatment}
}

:host(.checked) .control {
@@ -160,7 +157,7 @@ export const checkboxStyles: (context: ElementDefinitionContext, definition: Che
}
:host(:${focusVisible}) .control {
forced-color-adjust: none;
box-shadow: 0 0 0 1px ${SystemColors.Field}, 0 0 0 3px ${SystemColors.FieldText};
outline-color: ${SystemColors.FieldText};
background: ${SystemColors.Field};
border-color: ${SystemColors.Highlight};
}
@@ -173,9 +170,6 @@ export const checkboxStyles: (context: ElementDefinitionContext, definition: Che
background: ${SystemColors.HighlightText};
border-color: ${SystemColors.Highlight};
}
:host(.checked:${focusVisible}) .control {
box-shadow: 0 0 0 1px ${SystemColors.Field}, 0 0 0 3px ${SystemColors.FieldText};
}
:host(.checked) slot[name='checked-indicator'],
:host(.checked) slot[name='indeterminate-indicator'] {
fill: ${SystemColors.HighlightText};
25 changes: 17 additions & 8 deletions packages/web-components/src/combobox/combobox.styles.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { css, ElementStyles } from '@microsoft/fast-element';
import { ComboboxOptions, disabledCursor, ElementDefinitionContext, focusVisible } from '@microsoft/fast-foundation';
import { ComboboxOptions, disabledCursor, ElementDefinitionContext } from '@microsoft/fast-foundation';
import { selectFilledStyles, selectStyles } from '../select/select.styles';
import { appearanceBehavior } from '../utilities/behaviors';
import { strokeWidth } from '../design-tokens';
import { neutralFillInputActive, neutralFillInputHover, neutralFillInputRest, neutralStrokeInputActive, neutralStrokeInputHover, neutralStrokeInputRest, strokeWidth } from '../design-tokens';
import { typeRampBase } from '../styles/patterns/type-ramp';

export const comboboxStyles: (context: ElementDefinitionContext, definition: ComboboxOptions) => ElementStyles = (
@@ -12,6 +12,21 @@ export const comboboxStyles: (context: ElementDefinitionContext, definition: Com
css`
${selectStyles(context, definition)}

:host {
background: padding-box linear-gradient(${neutralFillInputRest}, ${neutralFillInputRest}),
border-box ${neutralStrokeInputRest};
}

:host(:not([disabled]):not([open]):hover) {
background: padding-box linear-gradient(${neutralFillInputHover}, ${neutralFillInputHover}),
border-box ${neutralStrokeInputHover};
}

:host(:not([disabled]):not([open]):active) {
background: padding-box linear-gradient(${neutralFillInputActive}, ${neutralFillInputActive}),
border-box ${neutralStrokeInputActive};
}

:host(:empty) .listbox {
display: none;
}
@@ -35,12 +50,6 @@ export const comboboxStyles: (context: ElementDefinitionContext, definition: Com
height: calc(100% - ${strokeWidth} * 1px));
margin: auto 0;
width: 100%;
}

.selected-value:hover,
.selected-value:${focusVisible},
.selected-value:disabled,
.selected-value:active {
outline: none;
}
`.withBehaviors(
12 changes: 3 additions & 9 deletions packages/web-components/src/data-grid/data-grid-cell.styles.ts
Original file line number Diff line number Diff line change
@@ -9,11 +9,10 @@ import {
import {
controlCornerRadius,
designUnit,
focusStrokeOuter,
focusStrokeWidth,
neutralForegroundRest,
} from '../design-tokens';
import { typeRampBase } from '../styles/patterns/type-ramp';
import { insetFocusTreatment } from '../styles/patterns/focus';

export const dataGridCellStyles: (
context: ElementDefinitionContext,
@@ -25,9 +24,7 @@ export const dataGridCellStyles: (
color: ${neutralForegroundRest};
box-sizing: border-box;
${typeRampBase}
border: transparent calc(${focusStrokeWidth} * 1px) solid;
overflow: hidden;
outline: none;
white-space: nowrap;
border-radius: calc(${controlCornerRadius} * 1px);
}
@@ -37,22 +34,19 @@ export const dataGridCellStyles: (
}

:host(:${focusVisible}) {
border-color: ${focusStrokeOuter};
${insetFocusTreatment}
}
`.withBehaviors(
forcedColorsStylesheetBehavior(
css`
:host {
forced-color-adjust: none;
border-color: transparent;
background: ${SystemColors.Field};
color: ${SystemColors.FieldText};
}

:host(:${focusVisible}) {
border-color: ${SystemColors.FieldText};
box-shadow: 0 0 0 2px inset ${SystemColors.Field};
color: ${SystemColors.FieldText};
outline-color: ${SystemColors.FieldText};
}
`,
),
12 changes: 5 additions & 7 deletions packages/web-components/src/flipper/flipper.styles.ts
Original file line number Diff line number Diff line change
@@ -13,14 +13,14 @@ import {
controlCornerRadius,
designUnit,
disabledOpacity,
focusStrokeOuter,
focusStrokeWidth,
neutralFillRest,
neutralFillStrongActive,
neutralFillStrongHover,
neutralFillStrongRest,
neutralStrokeControlRest,
strokeWidth,
} from '../design-tokens';
import { insetFocusTreatment } from '../styles/patterns/focus';

export const flipperStyles: (context: ElementDefinitionContext, definition: FlipperOptions) => ElementStyles = (
context: ElementDefinitionContext,
@@ -36,9 +36,8 @@ export const flipperStyles: (context: ElementDefinitionContext, definition: Flip
background: padding-box linear-gradient(${neutralFillRest}, ${neutralFillRest}),
border-box ${neutralStrokeControlRest};
box-sizing: border-box;
border: calc(${focusStrokeWidth} * 1px) solid transparent;
border: calc(${strokeWidth} * 1px) solid transparent;
border-radius: calc(${controlCornerRadius} * 1px);
outline: none;
padding: 0;
}

@@ -66,7 +65,7 @@ export const flipperStyles: (context: ElementDefinitionContext, definition: Flip
}

:host(:${focusVisible}) {
border-color: ${focusStrokeOuter};
${insetFocusTreatment}
}

:host::-moz-focus-inner {
@@ -104,8 +103,7 @@ export const flipperStyles: (context: ElementDefinitionContext, definition: Flip
}
:host(:${focusVisible}) {
forced-color-adjust: none;
border-color: ${SystemColors.Highlight};
box-shadow: 0 0 0 2px ${SystemColors.ButtonFace}, 0 0 0 4px ${SystemColors.ButtonText};
outline-color: ${SystemColors.Highlight};
}
`,
),
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ import {
controlCornerRadius,
designUnit,
disabledOpacity,
focusStrokeOuter,
focusStrokeWidth,
neutralFillSecondaryActive,
neutralFillSecondaryHover,
@@ -26,6 +25,7 @@ import {
neutralForegroundRest,
} from '../design-tokens';
import { typeRampBase } from '../styles/patterns/type-ramp';
import { insetFocusTreatment } from '../styles/patterns/focus';

export const optionStyles: (
context: ElementDefinitionContext,
@@ -37,13 +37,11 @@ export const optionStyles: (
${typeRampBase}
background: ${neutralFillStealthRest};
border-radius: calc(${controlCornerRadius} * 1px);
border: calc(${focusStrokeWidth} * 1px) solid transparent;
box-sizing: border-box;
color: ${neutralForegroundRest};
cursor: pointer;
fill: currentcolor;
height: calc(${heightNumber} * 1px);
outline: none;
overflow: hidden;
align-items: center;
padding: 0 calc(${designUnit} * 2.25px);
@@ -81,7 +79,7 @@ export const optionStyles: (
}

:host(:${focusVisible}) {
border-color: ${focusStrokeOuter};
${insetFocusTreatment}
background: ${neutralFillStealthFocus};
}

@@ -156,6 +154,9 @@ export const optionStyles: (
fill: currentcolor;
opacity: 1;
}
:host(:${focusVisible}) {
outline-color: ${SystemColors.CanvasText};
}
`,
),
);
6 changes: 2 additions & 4 deletions packages/web-components/src/listbox/listbox.styles.ts
Original file line number Diff line number Diff line change
@@ -8,10 +8,10 @@ import {
import {
controlCornerRadius,
designUnit,
focusStrokeOuter,
neutralStrokeRest,
strokeWidth,
} from '../design-tokens';
import { insetFocusTreatment } from '../styles/patterns/focus';

export const listboxStyles: (
context: ElementDefinitionContext,
@@ -24,15 +24,13 @@ export const listboxStyles: (
box-sizing: border-box;
flex-direction: column;
padding: calc(${designUnit} * 1px) 0;
outline: none;
}

::slotted(${context.tagFor(ListboxOption)}) {
margin: 0 calc(${designUnit} * 1px);
}

:host(:focus-within:not([disabled])) {
border-color: ${focusStrokeOuter};
box-shadow: 0 0 0 1px ${focusStrokeOuter} inset;
${insetFocusTreatment}
}
`
Loading