Skip to content

Commit fec01bd

Browse files
Petya MarkovaPetyaMarkovaBogdanova
andauthored
fix(ui5-toolbar): fix console warning in Toolbar (#11692)
* fix(ui5-toolbar): fix console warning in Toolbar * fix(ui5-toolbar): fix console warning in Toolbar component * fix(ui5-toolbar): fix console warning in Toolbar component --------- Co-authored-by: PetyaMarkovaBogdanova <[email protected]>
1 parent 6c716bc commit fec01bd

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

packages/main/cypress/specs/Toolbar.cy.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,40 @@ describe("Toolbar general interaction", () => {
287287
cy.get("@popover")
288288
.should("have.prop", "open", false);
289289
});
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+
});
290324
});
291325

292326
describe("Accessibility", () => {

packages/main/src/Toolbar.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import type ToolbarSeparator from "./ToolbarSeparator.js";
3434

3535
import type Button from "./Button.js";
3636
import type Popover from "./Popover.js";
37+
import getActiveElement from "@ui5/webcomponents-base/dist/util/getActiveElement.js";
3738

3839
type ToolbarMinWidthChangeEventDetail = {
3940
minWidth: number,
@@ -216,16 +217,16 @@ class Toolbar extends UI5Element {
216217
return this.itemsToOverflow.filter(item => !(item.ignoreSpace || item.isSeparator)).length === 0;
217218
}
218219

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);
221222
}
222223

223224
/**
224225
* Accessibility
225226
*/
226227

227228
get hasAriaSemantics() {
228-
return this.interactiveItemsCount > 1;
229+
return this.interactiveItems.length > 1;
229230
}
230231

231232
get accessibleRole() {
@@ -288,6 +289,10 @@ class Toolbar extends UI5Element {
288289
onBeforeRendering() {
289290
this.detachListeners();
290291
this.attachListeners();
292+
if (getActiveElement() === this.overflowButtonDOM?.getFocusDomRef() && this.hideOverflowButton) {
293+
const lastItem = this.interactiveItems.at(-1);
294+
lastItem?.focus();
295+
}
291296
}
292297

293298
async onAfterRendering() {

0 commit comments

Comments
 (0)