Skip to content

Commit ceded83

Browse files
authored
fix: do not lose dashboard widget focus in shadow root (#8304)
1 parent 27422d6 commit ceded83

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/dashboard/src/vaadin-dashboard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class Dashboard extends DashboardLayoutMixin(ElementMixin(ThemableMixin(PolylitM
272272
// Update the wrapper style
273273
this.__updateWrapper(wrapper, item);
274274

275-
if (!wrapper.contains(document.activeElement)) {
275+
if (wrapper !== focusedWrapper) {
276276
if (previousWrapper) {
277277
// Append the wrapper after the previous one if it's not already there
278278
if (wrapper.previousElementSibling !== previousWrapper) {

packages/dashboard/test/dashboard.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,25 @@ describe('dashboard', () => {
543543
expect(document.activeElement).to.equal(getElementFromCell(dashboard, 0, 0)!);
544544
});
545545

546+
it('should not lose focus when removing items inside shadow root', async () => {
547+
// Move the dashboard to a shadow root
548+
const wrapper = fixtureSync('<div></div>');
549+
const shadow = wrapper.attachShadow({ mode: 'open' });
550+
shadow.appendChild(dashboard);
551+
await nextFrame();
552+
553+
// Focus the second widget
554+
const secondWidget = dashboard.querySelectorAll('vaadin-dashboard-widget')[1];
555+
secondWidget.focus();
556+
557+
// Remove the first widget
558+
dashboard.items = [dashboard.items[1]];
559+
await nextFrame();
560+
561+
// Expect the second widget to remain focused
562+
expect(shadow.activeElement).to.equal(secondWidget);
563+
});
564+
546565
it('should not lose focus when reassigning section items', async () => {
547566
dashboard.items = [{ title: 'Section', items: [{ id: '0' }] }, { id: '1' }];
548567
await nextFrame();

0 commit comments

Comments
 (0)