Skip to content

Commit

Permalink
feat: add Lumo custom CSS properties to set focus-ring (#6634)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Oct 17, 2023
1 parent fb06ef3 commit fc54a1d
Show file tree
Hide file tree
Showing 24 changed files with 150 additions and 29 deletions.
80 changes: 80 additions & 0 deletions dev/focus-ring.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Focus ring</title>
<script type="module" src="./common.js"></script>

<script type="module">
import '@vaadin/avatar';
import '@vaadin/button';
import '@vaadin/checkbox';
import '@vaadin/combo-box';
import '@vaadin/date-picker';
import '@vaadin/details';
import '@vaadin/item';
import '@vaadin/list-box';
import '@vaadin/radio-group';
import '@vaadin/password-field';
import '@vaadin/rich-text-editor';
import '@vaadin/tabs';
import '@vaadin/text-field';
</script>

<style>
html {
--vaadin-focus-ring-color: purple;
--vaadin-focus-ring-width: 1px;
}

vaadin-button {
--vaadin-focus-ring-color: green;
}
</style>
</head>

<body>
<vaadin-avatar></vaadin-avatar>

<vaadin-button>Button</vaadin-button>

<vaadin-checkbox label="Checkbox"></vaadin-checkbox>

<vaadin-radio-group label="Radio group">
<vaadin-radio-button value="y" label="Yes"></vaadin-radio-button>
<vaadin-radio-button value="n" label="No"></vaadin-radio-button>
</vaadin-radio-group>

<vaadin-details summary="Details">
<div>Toggle using mouse, Enter and Space keys.</div>
</vaadin-details>

<br />

<vaadin-list-box>
<vaadin-item>Foo</vaadin-item>
<vaadin-item>Bar</vaadin-item>
</vaadin-list-box>

<br />

<vaadin-combo-box label="Combo box" items='["Foo", "Bar", "Baz"]'></vaadin-combo-box>

<vaadin-text-field label="Text field"></vaadin-text-field>

<vaadin-password-field label="Password field"></vaadin-password-field>

<vaadin-date-picker label="Date picker"></vaadin-date-picker>

<vaadin-tabs>
<vaadin-tab>Foo</vaadin-tab>
<vaadin-tab>Bar</vaadin-tab>
</vaadin-tabs>

<br />

<vaadin-rich-text-editor></vaadin-rich-text-editor>
</body>
</html>
2 changes: 1 addition & 1 deletion packages/avatar/src/vaadin-avatar-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const avatarStyles = css`
border: var(--vaadin-avatar-outline-width) solid transparent;
margin: calc(var(--vaadin-avatar-outline-width) * -1);
background-clip: content-box;
--vaadin-avatar-outline-width: 2px;
--vaadin-avatar-outline-width: var(--vaadin-focus-ring-width, 2px);
}
img {
Expand Down
2 changes: 1 addition & 1 deletion packages/avatar/theme/lumo/vaadin-avatar-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ registerStyles(
}
:host([focus-ring]) {
border-color: var(--lumo-primary-color-50pct);
border-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
}
[part='icon'],
Expand Down
4 changes: 3 additions & 1 deletion packages/button/theme/lumo/vaadin-button-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const button = css`
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
flex-shrink: 0;
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
/* Set only for the internal parts so we don't affect the host vertical alignment */
Expand Down Expand Up @@ -92,7 +94,7 @@ const button = css`
/* Keyboard focus */
:host([focus-ring]) {
box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
:host([theme~='primary'][focus-ring]) {
Expand Down
4 changes: 3 additions & 1 deletion packages/checkbox/theme/lumo/vaadin-checkbox-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ registerStyles(
cursor: default;
outline: none;
--_checkbox-size: var(--vaadin-checkbox-size, calc(var(--lumo-size-m) / 2));
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
:host([has-label]) ::slotted(label) {
Expand Down Expand Up @@ -87,7 +89,7 @@ registerStyles(
/* Focus ring */
:host([focus-ring]) [part='checkbox'] {
box-shadow: 0 0 0 1px var(--lumo-base-color), 0 0 0 3px var(--lumo-primary-color-50pct),
box-shadow: 0 0 0 1px var(--lumo-base-color), 0 0 0 calc(var(--_focus-ring-width) + 1px) var(--_focus-ring-color),
inset 0 0 0 var(--_input-border-width, 0) var(--_input-border-color);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ const comboBoxItem = css`
transition: background-color 100ms;
overflow: hidden;
--_lumo-item-selected-icon-display: block;
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
@media (any-hover: hover) {
:host([focused]:not([disabled])) {
box-shadow: inset 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: inset 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
}
`;
Expand Down
4 changes: 3 additions & 1 deletion packages/crud/theme/lumo/vaadin-crud-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ registerStyles(
css`
:host {
font-family: var(--lumo-font-family);
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
[part='scroller'] {
Expand Down Expand Up @@ -105,7 +107,7 @@ registerStyles(
position: absolute;
inset: 0;
content: '';
box-shadow: inset 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: inset 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
:host(:not([editor-position=''])) [part='editor']:not([hidden]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ registerStyles(
color: var(--lumo-body-text-color);
text-align: center;
padding: 0 var(--lumo-space-xs);
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
/* Month header */
Expand Down Expand Up @@ -98,7 +100,7 @@ registerStyles(
}
[part~='date'][part~='focused']::before {
box-shadow: 0 0 0 1px var(--lumo-base-color), 0 0 0 3px var(--lumo-primary-color-50pct);
box-shadow: 0 0 0 1px var(--lumo-base-color), 0 0 0 calc(var(--_focus-ring-width) + 1px) var(--_focus-ring-color);
}
:host(:not([focused])) [part~='date'][part~='focused']::before {
Expand All @@ -107,7 +109,7 @@ registerStyles(
@keyframes vaadin-date-picker-month-calendar-focus-date {
50% {
box-shadow: 0 0 0 1px var(--lumo-base-color), 0 0 0 3px transparent;
box-shadow: 0 0 0 1px var(--lumo-base-color), 0 0 0 calc(var(--_focus-ring-width) + 1px) transparent;
}
}
Expand Down Expand Up @@ -157,7 +159,7 @@ template.innerHTML = `
<style>
@keyframes vaadin-date-picker-month-calendar-focus-date {
50% {
box-shadow: 0 0 0 2px transparent;
box-shadow: 0 0 0 var(--_focus-ring-width) transparent;
}
}
</style>
Expand Down
4 changes: 3 additions & 1 deletion packages/details/theme/lumo/vaadin-details-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ const details = css`
:host {
margin: var(--lumo-space-xs) 0;
outline: none;
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
:host([focus-ring]) ::slotted([slot='summary']) {
box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
[part='content'] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const gridProEditor = css`
font-size: inherit;
--lumo-text-field-size: 27px;
/* outline similar to what grid uses */
box-shadow: inset 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: inset 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
:host([theme~='grid-pro-editor']) [part='input-field'] {
Expand Down
2 changes: 1 addition & 1 deletion packages/grid-pro/theme/lumo/vaadin-grid-pro-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ registerStyles(
position: absolute;
inset: 0;
pointer-events: none;
box-shadow: inset 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: inset 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
[part~='editable-cell'],
Expand Down
7 changes: 4 additions & 3 deletions packages/grid/theme/lumo/vaadin-grid-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ registerStyles(
-webkit-tap-highlight-color: transparent;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
/* For internal use only */
--_lumo-grid-border-color: var(--lumo-contrast-20pct);
--_lumo-grid-secondary-border-color: var(--lumo-contrast-10pct);
Expand Down Expand Up @@ -82,7 +83,7 @@ registerStyles(
position: absolute;
inset: 0;
pointer-events: none;
box-shadow: inset 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: inset 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
:host([navigating]) [part~='row']:focus::before {
Expand All @@ -97,7 +98,7 @@ registerStyles(
z-index: 100;
inset: 0;
pointer-events: none;
box-shadow: inset 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: inset 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
[part~='row'][dragover] {
Expand Down
4 changes: 3 additions & 1 deletion packages/item/theme/lumo/vaadin-item-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const item = css`
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-tap-highlight-color: var(--lumo-primary-color-10pct);
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
/* Checkmark */
Expand Down Expand Up @@ -69,7 +71,7 @@ const item = css`
}
:host([focus-ring]:not([disabled])) {
box-shadow: inset 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: inset 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/map/theme/lumo/vaadin-map-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ registerStyles(
--vaadin-map-icon-overview-map-expand: var(--lumo-icons-angle-up);
--vaadin-map-icon-close: var(--lumo-icons-cross);
--vaadin-map-icon-attribution-collapse: var(--lumo-icons-angle-right);
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
:host(:not([theme~='borderless'])) {
Expand All @@ -48,7 +50,7 @@ registerStyles(
}
:host([focus-ring]) {
box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
.ol-control,
Expand Down Expand Up @@ -106,13 +108,13 @@ registerStyles(
@supports not selector(:focus-visible) {
.ol-control button:focus {
outline: none;
box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
}
.ol-control button:focus-visible {
outline: none;
box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
.ol-zoom {
Expand Down
4 changes: 3 additions & 1 deletion packages/message-list/theme/lumo/vaadin-message-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ registerStyles(
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust: 100%;
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
:host([focus-ring]) {
box-shadow: inset 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: inset 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
[part='header'] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ registerStyles(
cursor: default;
outline: none;
--_radio-button-size: var(--vaadin-radio-button-size, calc(var(--lumo-size-m) / 2));
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
:host([has-label]) ::slotted(label) {
Expand Down Expand Up @@ -107,7 +109,7 @@ registerStyles(
}
:host([focus-ring]) [part='radio'] {
box-shadow: 0 0 0 1px var(--lumo-base-color), 0 0 0 3px var(--lumo-primary-color-50pct),
box-shadow: 0 0 0 1px var(--lumo-base-color), 0 0 0 calc(var(--_focus-ring-width) + 1px) var(--_focus-ring-color),
inset 0 0 0 var(--_input-border-width, 0) var(--_input-border-color);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themab
const richTextEditor = css`
:host {
min-height: calc(var(--lumo-size-m) * 8);
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
[part='toolbar'] {
Expand All @@ -32,7 +34,7 @@ const richTextEditor = css`
[part~='toolbar-button']:focus {
outline: none;
box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
[part~='toolbar-button']:hover {
Expand Down
5 changes: 4 additions & 1 deletion packages/scroller/theme/lumo/vaadin-scroller-styles.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import '@vaadin/vaadin-lumo-styles/color.js';
import '@vaadin/vaadin-lumo-styles/style.js';
import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';

const scroller = css`
:host {
outline: none;
--_focus-ring-color: var(--vaadin-focus-ring-color, var(--lumo-primary-color-50pct));
--_focus-ring-width: var(--vaadin-focus-ring-width, 2px);
}
:host([focus-ring]) {
box-shadow: 0 0 0 2px var(--lumo-primary-color-50pct);
box-shadow: 0 0 0 var(--_focus-ring-width) var(--_focus-ring-color);
}
/* Show dividers when content overflows */
Expand Down
Loading

0 comments on commit fc54a1d

Please sign in to comment.