File tree Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -287,6 +287,40 @@ describe("Toolbar general interaction", () => {
287
287
cy . get ( "@popover" )
288
288
. should ( "have.prop" , "open" , false ) ;
289
289
} ) ;
290
+
291
+ it ( "Should focus on the last interactive element outside the overflow popover when overflow button disappears" , ( ) => {
292
+ // Mount the Toolbar with multiple buttons
293
+ cy . mount (
294
+ < Toolbar >
295
+ < ToolbarButton text = "Button 1" />
296
+ < ToolbarButton text = "Button 2" />
297
+ < ToolbarButton text = "Button 3" />
298
+ < ToolbarButton text = "Button 4" />
299
+ < ToolbarButton text = "Button 5" />
300
+ </ Toolbar >
301
+ ) ;
302
+
303
+ // Set initial viewport size to ensure the overflow button is visible
304
+ cy . viewport ( 300 , 1080 ) ;
305
+
306
+ // Focus on the overflow button
307
+ cy . get ( "ui5-toolbar" )
308
+ . shadow ( )
309
+ . find ( ".ui5-tb-overflow-btn" )
310
+ . click ( )
311
+ . click ( )
312
+ . should ( "be.focused" ) ;
313
+
314
+ // Resize the viewport to make the overflow button disappear
315
+ cy . viewport ( 800 , 1080 ) ;
316
+
317
+ // Verify the focus shifts to the last interactive element outside the overflow popover
318
+ cy . get ( "ui5-toolbar" )
319
+ . shadow ( )
320
+ . find ( ".ui5-tb-item" )
321
+ . eq ( 3 )
322
+ . should ( "be.focused" ) ;
323
+ } ) ;
290
324
} ) ;
291
325
292
326
describe ( "Accessibility" , ( ) => {
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import type ToolbarSeparator from "./ToolbarSeparator.js";
34
34
35
35
import type Button from "./Button.js" ;
36
36
import type Popover from "./Popover.js" ;
37
+ import getActiveElement from "@ui5/webcomponents-base/dist/util/getActiveElement.js" ;
37
38
38
39
type ToolbarMinWidthChangeEventDetail = {
39
40
minWidth : number ,
@@ -216,16 +217,16 @@ class Toolbar extends UI5Element {
216
217
return this . itemsToOverflow . filter ( item => ! ( item . ignoreSpace || item . isSeparator ) ) . length === 0 ;
217
218
}
218
219
219
- get interactiveItemsCount ( ) {
220
- return this . items . filter ( ( item : ToolbarItem ) => item . isInteractive ) . length ;
220
+ get interactiveItems ( ) {
221
+ return this . items . filter ( ( item : ToolbarItem ) => item . isInteractive ) ;
221
222
}
222
223
223
224
/**
224
225
* Accessibility
225
226
*/
226
227
227
228
get hasAriaSemantics ( ) {
228
- return this . interactiveItemsCount > 1 ;
229
+ return this . interactiveItems . length > 1 ;
229
230
}
230
231
231
232
get accessibleRole ( ) {
@@ -288,6 +289,10 @@ class Toolbar extends UI5Element {
288
289
onBeforeRendering ( ) {
289
290
this . detachListeners ( ) ;
290
291
this . attachListeners ( ) ;
292
+ if ( getActiveElement ( ) === this . overflowButtonDOM ?. getFocusDomRef ( ) && this . hideOverflowButton ) {
293
+ const lastItem = this . interactiveItems . at ( - 1 ) ;
294
+ lastItem ?. focus ( ) ;
295
+ }
291
296
}
292
297
293
298
async onAfterRendering ( ) {
You can’t perform that action at this time.
0 commit comments