File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -272,7 +272,7 @@ class Dashboard extends DashboardLayoutMixin(ElementMixin(ThemableMixin(PolylitM
272
272
// Update the wrapper style
273
273
this . __updateWrapper ( wrapper , item ) ;
274
274
275
- if ( ! wrapper . contains ( document . activeElement ) ) {
275
+ if ( wrapper !== focusedWrapper ) {
276
276
if ( previousWrapper ) {
277
277
// Append the wrapper after the previous one if it's not already there
278
278
if ( wrapper . previousElementSibling !== previousWrapper ) {
Original file line number Diff line number Diff line change @@ -543,6 +543,25 @@ describe('dashboard', () => {
543
543
expect ( document . activeElement ) . to . equal ( getElementFromCell ( dashboard , 0 , 0 ) ! ) ;
544
544
} ) ;
545
545
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
+
546
565
it ( 'should not lose focus when reassigning section items' , async ( ) => {
547
566
dashboard . items = [ { title : 'Section' , items : [ { id : '0' } ] } , { id : '1' } ] ;
548
567
await nextFrame ( ) ;
You can’t perform that action at this time.
0 commit comments