Skip to content

Commit f38b1b8

Browse files
fix: preserve focus rings in dialog content for base and Aura (#12990)
Co-authored-by: Minwook Shin <163576506+minwookshin@users.noreply.github.com>
1 parent 213f8b5 commit f38b1b8

29 files changed

Lines changed: 129 additions & 3 deletions

‎packages/crud/src/styles/vaadin-crud-dialog-overlay-base-styles.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ const crudDialogOverlay = css`
3232
overflow: auto;
3333
overscroll-behavior: contain;
3434
padding: var(--vaadin-crud-form-padding, var(--vaadin-padding-l));
35-
padding-top: 0;
35+
padding-top: calc(var(--vaadin-focus-ring-width, 2px) + 2px);
36+
margin-top: calc(var(--vaadin-focus-ring-width, 2px) * -1 - 2px);
37+
margin-bottom: 0;
3638
}
3739
3840
::slotted([slot='form']) {

‎packages/crud/test/visual/aura/crud.test.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { fixtureSync, nextRender } from '@vaadin/testing-helpers';
22
import { visualDiff } from '@web/test-runner-visual-regression';
33
import '@vaadin/aura/aura.css';
4+
import '@vaadin/form-layout/vaadin-form-layout.js';
5+
import '@vaadin/text-field/vaadin-text-field.js';
46
import '../../not-animated-styles.css';
57
import '../../../vaadin-crud.js';
68

@@ -29,6 +31,29 @@ describe('crud', () => {
2931
await visualDiff(element, 'no-row-borders');
3032
});
3133

34+
describe('custom form', () => {
35+
let form;
36+
37+
beforeEach(async () => {
38+
form = document.createElement('vaadin-form-layout');
39+
form.slot = 'form';
40+
form.innerHTML = `
41+
<vaadin-text-field path="name.first"></vaadin-text-field>
42+
<vaadin-text-field path="name.last"></vaadin-text-field>
43+
`;
44+
element.appendChild(form);
45+
await nextRender();
46+
});
47+
48+
it('editor-first-field-focus', async () => {
49+
element.editedItem = element.items[0];
50+
await nextRender();
51+
form.querySelector('vaadin-text-field').focus();
52+
const overlay = element.$.dialog.shadowRoot.querySelector('vaadin-crud-dialog-overlay');
53+
await visualDiff(overlay.shadowRoot.querySelector('[part="overlay"]'), 'editor-first-field-focus');
54+
});
55+
});
56+
3257
['default', 'aside', 'bottom'].forEach((position) => {
3358
describe(`editor-position-${position}`, () => {
3459
beforeEach(async () => {
7.93 KB
Loading
8.14 KB
Loading

‎packages/crud/test/visual/base/crud.test.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { fixtureSync, nextRender } from '@vaadin/testing-helpers';
22
import { visualDiff } from '@web/test-runner-visual-regression';
3+
import '@vaadin/form-layout/vaadin-form-layout.js';
4+
import '@vaadin/text-field/vaadin-text-field.js';
35
import '../../not-animated-styles.css';
46
import '../../../src/vaadin-crud.js';
57

@@ -29,6 +31,29 @@ describe('crud', () => {
2931
await visualDiff(div, 'no-toolbar');
3032
});
3133

34+
describe('custom form', () => {
35+
let form;
36+
37+
beforeEach(async () => {
38+
form = document.createElement('vaadin-form-layout');
39+
form.slot = 'form';
40+
form.innerHTML = `
41+
<vaadin-text-field path="name.first"></vaadin-text-field>
42+
<vaadin-text-field path="name.last"></vaadin-text-field>
43+
`;
44+
element.appendChild(form);
45+
await nextRender();
46+
});
47+
48+
it('editor-first-field-focus', async () => {
49+
element.editedItem = element.items[0];
50+
await nextRender();
51+
form.querySelector('vaadin-text-field').focus();
52+
const overlay = element.$.dialog.shadowRoot.querySelector('vaadin-crud-dialog-overlay');
53+
await visualDiff(overlay.shadowRoot.querySelector('[part="overlay"]'), 'editor-first-field-focus');
54+
});
55+
});
56+
3257
describe('flex', () => {
3358
beforeEach(async () => {
3459
div.style.display = 'flex';
6.38 KB
Loading

‎packages/dialog/src/styles/vaadin-dialog-overlay-base-styles.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ export const dialogOverlayBase = css`
6868
6969
:host([theme~='no-padding']) [part='content'] {
7070
padding: 0 !important;
71+
margin: 0 !important;
7172
}
7273
74+
/* Keep focus outlines inside the scrollable content's clipping area. */
7375
:host(:is([has-header], [has-title])) [part='content'] {
74-
padding-top: 0;
76+
padding-top: calc(var(--vaadin-focus-ring-width, 2px) + 2px);
77+
margin-top: calc(var(--vaadin-focus-ring-width, 2px) * -1 - 2px);
7578
}
7679
7780
:host([has-footer]) [part='content'] {
78-
padding-bottom: 0;
81+
padding-bottom: calc(var(--vaadin-focus-ring-width, 2px) + 2px);
82+
margin-bottom: calc(var(--vaadin-focus-ring-width, 2px) * -1 - 2px);
7983
}
8084
8185
[part='header'] {

‎packages/dialog/test/helpers.d.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { DialogRenderer } from '../vaadin-dialog.js';
2+
3+
export function createRenderer(text: string): DialogRenderer;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import '@vaadin/aura/aura.css';
2+
import { defineContentFocusRingTests } from '../focus-ring.common.ts';
3+
4+
defineContentFocusRingTests();
3.68 KB
Loading

0 commit comments

Comments
 (0)