Skip to content

Commit f292890

Browse files
authored
fix(ui5-shellbar-item): correct getFocusDomRef return value (#12328)
Improves `ShellBarItem` focus handling when moving between the ShellBar's main area and overflow popover. **Changes** - Switched _getRealDomRef to use shadowRoot for accurate queries. - Applied data-ui5-stable only to visible items and overflow popover entries for reliable DOM targeting. - Added Cypress tests to verify getFocusDomRef() in both contexts.
1 parent 8a2ad58 commit f292890

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import ShellBar from "../../src/ShellBar.js";
2+
import ShellBarItem from "../../src/ShellBarItem.js";
3+
import Button from "@ui5/webcomponents/dist/Button.js";
4+
import Avatar from "@ui5/webcomponents/dist/Avatar.js";
5+
import Input from "@ui5/webcomponents/dist/Input.js";
6+
7+
describe("ShellBarItem getFocusDomRef", () => {
8+
it("should return the correct DOM element when item is in the bar", () => {
9+
cy.mount(
10+
<ShellBar id="shellbar-test">
11+
<ShellBarItem id="item1" icon="accept" text="Item 1" stable-dom-ref="item-1" />
12+
</ShellBar>
13+
);
14+
15+
cy.get<ShellBarItem>("#item1")
16+
.then(($item) => {
17+
const focusRef = $item[0].getFocusDomRef();
18+
expect(focusRef).to.be.instanceOf(HTMLElement);
19+
expect(focusRef).has.attr('ui5-button');
20+
expect(focusRef?.getAttribute('data-ui5-stable')).to.equal('item-1');
21+
});
22+
});
23+
24+
it("should return the correct DOM element when item is in overflow popover", () => {
25+
cy.mount(
26+
<ShellBar id="shellbar-overflow-test" showNotifications showProductSwitch>
27+
<Button icon="nav-back" slot="startButton" />
28+
<ShellBarItem id="overflow-item1" icon="accept" text="Item 1" stable-dom-ref="overflow-1" />
29+
<ShellBarItem id="overflow-item2" icon="alert" text="Item 2" stable-dom-ref="overflow-2" />
30+
<ShellBarItem id="overflow-item3" icon="attachment" text="Item 3" stable-dom-ref="overflow-3" />
31+
<Avatar slot="profile">
32+
<img src="https://sdk.openui5.org/test-resources/sap/f/images/Woman_avatar_01.png" />
33+
</Avatar>
34+
<Input placeholder="Search" slot="searchField" />
35+
</ShellBar>
36+
);
37+
38+
// Force overflow by resizing viewport
39+
cy.viewport(320, 800);
40+
41+
// Open overflow popover
42+
cy.get("#shellbar-overflow-test")
43+
.shadow()
44+
.find(".ui5-shellbar-overflow-button")
45+
.should("be.visible")
46+
.click();
47+
48+
cy.get("#shellbar-overflow-test")
49+
.shadow()
50+
.find(".ui5-shellbar-overflow-popover")
51+
.should("be.visible");
52+
53+
// Test when items are in overflow popover
54+
cy.get<ShellBarItem>("#overflow-item1")
55+
.then(($item) => {
56+
const focusRef = $item[0].getFocusDomRef();
57+
// When overflowed, should return the list item in the popover
58+
expect(focusRef?.hasAttribute('ui5-li'));
59+
expect(focusRef?.getAttribute('data-ui5-stable')).to.equal('overflow-1');
60+
});
61+
});
62+
});

packages/fiori/src/ShellBar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ class ShellBar extends UI5Element {
12721272
const bIndex = PREDEFINED_PLACE_ACTIONS.indexOf(b.icon || "");
12731273
return aIndex - bIndex;
12741274
}).map((item: ShellBarItem) => {
1275-
item._getRealDomRef = () => this.getDomRef()!.querySelector(`*[data-ui5-stable=${item.stableDomRef}]`)!;
1275+
item._getRealDomRef = () => this.shadowRoot!.querySelector(`*[data-ui5-stable=${item.stableDomRef}]`)!;
12761276
// check if included for lean mode
12771277
const show = !!item.icon || false;
12781278
return {

packages/fiori/src/ShellBarPopoverTemplate.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default function PopoversTemplate(this: ShellBar) {
3232
key={index}
3333
data-count={icon.count}
3434
data-ui5-external-action-item-id={icon.refItemid}
35+
data-ui5-stable={icon.stableDomRef}
3536
icon={icon.icon ? icon.icon : ""}
3637
type="Active"
3738
onui5-_press={icon.press}

packages/fiori/src/ShellBarTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export default function ShellBarTemplate(this: ShellBar) {
215215
tooltip={item.tooltip}
216216
data-ui5-notifications-count={this.notificationsCount}
217217
data-ui5-external-action-item-id={item.refItemid}
218-
data-ui5-stable={item.stableDomRef}
218+
data-ui5-stable={item.icon && !this.isIconHidden(item.icon) ? item.stableDomRef : undefined}
219219
onClick={item.press}
220220
accessibilityAttributes={item.accessibilityAttributes}
221221
>

0 commit comments

Comments
 (0)