Skip to content

Commit 05875fe

Browse files
committed
feat(ui5-combobox, ui5-multi-combobox): show associated label as mobile dialog header title
The mobile full-screen dialog for ComboBox and MultiComboBox now displays the associated label text as the header title instead of the generic "All Items". Falls back to "All Items" when no label exists.
1 parent 96e5525 commit 05875fe

4 files changed

Lines changed: 114 additions & 4 deletions

File tree

packages/main/cypress/specs/ComboBox.mobile.cy.tsx

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import ComboBox from "../../src/ComboBox.js";
22
import ComboBoxItem from "../../src/ComboBoxItem.js";
33
import ComboBoxItemGroup from "../../src/ComboBoxItemGroup.js";
44
import type ResponsivePopover from "../../src/ResponsivePopover.js";
5-
import { COMBOBOX_DIALOG_OK_BUTTON, COMBOBOX_DIALOG_CANCEL_BUTTON } from "../../src/generated/i18n/i18n-defaults.js";
5+
import { COMBOBOX_DIALOG_OK_BUTTON, COMBOBOX_DIALOG_CANCEL_BUTTON, INPUT_SUGGESTIONS_TITLE } from "../../src/generated/i18n/i18n-defaults.js";
6+
import Label from "../../src/Label.js";
67

78
describe("Basic mobile picker rendering and interaction", () => {
89
beforeEach(() => {
@@ -618,3 +619,54 @@ describe("Mobile Highlighting", () => {
618619
.should("contain.html", "<b>A</b>");
619620
});
620621
});
622+
623+
describe("Dialog header title", () => {
624+
beforeEach(() => {
625+
cy.ui5SimulateDevice("phone");
626+
});
627+
628+
it("Should display label text as dialog header title when label for is used", () => {
629+
cy.mount(
630+
<>
631+
<Label for="myCB">Country</Label>
632+
<ComboBox id="myCB">
633+
<ComboBoxItem text="Algeria" />
634+
<ComboBoxItem text="Argentina" />
635+
</ComboBox>
636+
</>
637+
);
638+
639+
cy.get("#myCB").realClick();
640+
641+
cy.get("#myCB")
642+
.shadow()
643+
.find<ResponsivePopover>("[ui5-responsive-popover]")
644+
.ui5ResponsivePopoverOpened();
645+
646+
cy.get("#myCB")
647+
.shadow()
648+
.find("[ui5-responsive-popover] .ui5-responsive-popover-header .row span")
649+
.should("have.text", "Country");
650+
});
651+
652+
it("Should fallback to 'All Items' when no label is associated", () => {
653+
cy.mount(
654+
<ComboBox id="myCB">
655+
<ComboBoxItem text="Algeria" />
656+
<ComboBoxItem text="Argentina" />
657+
</ComboBox>
658+
);
659+
660+
cy.get("#myCB").realClick();
661+
662+
cy.get("#myCB")
663+
.shadow()
664+
.find<ResponsivePopover>("[ui5-responsive-popover]")
665+
.ui5ResponsivePopoverOpened();
666+
667+
cy.get("#myCB")
668+
.shadow()
669+
.find("[ui5-responsive-popover] .ui5-responsive-popover-header .row span")
670+
.should("have.text", INPUT_SUGGESTIONS_TITLE.defaultText);
671+
});
672+
});

packages/main/cypress/specs/MultiComboBox.mobile.cy.tsx

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { SHOW_SELECTED_BUTTON } from "../../src/generated/i18n/i18n-defaults.js";
1+
import { SHOW_SELECTED_BUTTON, INPUT_SUGGESTIONS_TITLE } from "../../src/generated/i18n/i18n-defaults.js";
22
import MultiComboBox from "../../src/MultiComboBox.js";
33
import MultiComboBoxItem from "../../src/MultiComboBoxItem.js";
44
import ResponsivePopover from "../../src/ResponsivePopover.js";
5+
import Label from "../../src/Label.js";
56

67
describe("MultiComboBox mobile general interaction", () => {
78
beforeEach(() => {
@@ -874,4 +875,61 @@ describe("Accessibility", () => {
874875
.should("have.attr", "accessible-name", SHOW_SELECTED_BUTTON.defaultText);
875876

876877
});
878+
});
879+
880+
describe("Dialog header title", () => {
881+
beforeEach(() => {
882+
cy.ui5SimulateDevice("phone");
883+
});
884+
885+
it("Should display label text as dialog header title when label for is used", () => {
886+
cy.mount(
887+
<>
888+
<Label for="myMCB">Country</Label>
889+
<MultiComboBox id="myMCB">
890+
<MultiComboBoxItem text="Item 1" />
891+
<MultiComboBoxItem text="Item 2" />
892+
</MultiComboBox>
893+
</>
894+
);
895+
896+
cy.get("#myMCB")
897+
.shadow()
898+
.find("input")
899+
.realClick();
900+
901+
cy.get("#myMCB")
902+
.shadow()
903+
.find<ResponsivePopover>("[ui5-responsive-popover]")
904+
.ui5ResponsivePopoverOpened();
905+
906+
cy.get("#myMCB")
907+
.shadow()
908+
.find("[ui5-responsive-popover] .ui5-responsive-popover-header-text")
909+
.should("have.text", "Country");
910+
});
911+
912+
it("Should fallback to 'All Items' when no label is associated", () => {
913+
cy.mount(
914+
<MultiComboBox id="myMCB">
915+
<MultiComboBoxItem text="Item 1" />
916+
<MultiComboBoxItem text="Item 2" />
917+
</MultiComboBox>
918+
);
919+
920+
cy.get("#myMCB")
921+
.shadow()
922+
.find("input")
923+
.realClick();
924+
925+
cy.get("#myMCB")
926+
.shadow()
927+
.find<ResponsivePopover>("[ui5-responsive-popover]")
928+
.ui5ResponsivePopoverOpened();
929+
930+
cy.get("#myMCB")
931+
.shadow()
932+
.find("[ui5-responsive-popover] .ui5-responsive-popover-header-text")
933+
.should("have.text", INPUT_SUGGESTIONS_TITLE.defaultText);
934+
});
877935
});

packages/main/src/ComboBox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ class ComboBox extends UI5Element implements IFormInputElement {
15331533
}
15341534

15351535
get _headerTitleText() {
1536-
return ComboBox.i18nBundle.getText(INPUT_SUGGESTIONS_TITLE);
1536+
return getAssociatedLabelForTexts(this) || ComboBox.i18nBundle.getText(INPUT_SUGGESTIONS_TITLE);
15371537
}
15381538

15391539
get _iconAccessibleNameText() {

packages/main/src/MultiComboBox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,7 @@ class MultiComboBox extends UI5Element implements IFormInputElement {
22592259
}
22602260

22612261
get _headerTitleText() {
2262-
return MultiComboBox.i18nBundle.getText(INPUT_SUGGESTIONS_TITLE);
2262+
return getAssociatedLabelForTexts(this) || MultiComboBox.i18nBundle.getText(INPUT_SUGGESTIONS_TITLE);
22632263
}
22642264

22652265
get _iconAccessibleNameText() {

0 commit comments

Comments
 (0)