Skip to content

Commit 96e5525

Browse files
committed
feat(ui5-input): show associated label as mobile dialog header title
The mobile full-screen dialog for Input and MultiInput 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 4ac0d74 commit 96e5525

3 files changed

Lines changed: 113 additions & 2 deletions

File tree

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import Input from "../../src/Input.js";
22
import "../../src/features/InputSuggestions.js";
33
import type ResponsivePopover from "../../src/ResponsivePopover.js";
44
import SuggestionItem from "../../src/SuggestionItem.js";
5-
import { INPUT_SUGGESTIONS_OK_BUTTON, INPUT_SUGGESTIONS_CANCEL_BUTTON } from "../../src/generated/i18n/i18n-defaults.js";
5+
import { INPUT_SUGGESTIONS_OK_BUTTON, INPUT_SUGGESTIONS_CANCEL_BUTTON, INPUT_SUGGESTIONS_TITLE } from "../../src/generated/i18n/i18n-defaults.js";
6+
import Label from "../../src/Label.js";
67

78
describe("Input on mobile device", () => {
89
beforeEach(() => {
@@ -442,3 +443,54 @@ describe("Property open", () => {
442443
.ui5ResponsivePopoverClosed();
443444
});
444445
});
446+
447+
describe("Dialog header title", () => {
448+
beforeEach(() => {
449+
cy.ui5SimulateDevice("phone");
450+
});
451+
452+
it("Should display label text as dialog header title when label for is used", () => {
453+
cy.mount(
454+
<>
455+
<Label for="myInput">Country</Label>
456+
<Input id="myInput" showSuggestions>
457+
<SuggestionItem text="Item 1" />
458+
<SuggestionItem text="Item 2" />
459+
</Input>
460+
</>
461+
);
462+
463+
cy.get("#myInput").realClick();
464+
465+
cy.get("#myInput")
466+
.shadow()
467+
.find<ResponsivePopover>("[ui5-responsive-popover]")
468+
.ui5ResponsivePopoverOpened();
469+
470+
cy.get("#myInput")
471+
.shadow()
472+
.find("[ui5-responsive-popover] .ui5-responsive-popover-header-text")
473+
.should("have.text", "Country");
474+
});
475+
476+
it("Should fallback to 'All Items' when no label is associated", () => {
477+
cy.mount(
478+
<Input id="myInput" showSuggestions>
479+
<SuggestionItem text="Item 1" />
480+
<SuggestionItem text="Item 2" />
481+
</Input>
482+
);
483+
484+
cy.get("#myInput").realClick();
485+
486+
cy.get("#myInput")
487+
.shadow()
488+
.find<ResponsivePopover>("[ui5-responsive-popover]")
489+
.ui5ResponsivePopoverOpened();
490+
491+
cy.get("#myInput")
492+
.shadow()
493+
.find("[ui5-responsive-popover] .ui5-responsive-popover-header-text")
494+
.should("have.text", INPUT_SUGGESTIONS_TITLE.defaultText);
495+
});
496+
});

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import SuggestionItem from "../../src/SuggestionItem.js";
44
import Button from "../../src/Button.js";
55
import "../../src/features/InputSuggestions.js";
66
import type ResponsivePopover from "@ui5/webcomponents/dist/ResponsivePopover.js";
7+
import { INPUT_SUGGESTIONS_TITLE } from "../../src/generated/i18n/i18n-defaults.js";
8+
import Label from "../../src/Label.js";
79

810
const createTokenFromText = (text: string): HTMLElement => {
911
const token = document.createElement("ui5-token");
@@ -213,3 +215,60 @@ describe("Multi Input on mobile device", () => {
213215
});
214216
});
215217
});
218+
219+
describe("Dialog header title", () => {
220+
beforeEach(() => {
221+
cy.ui5SimulateDevice("phone");
222+
});
223+
224+
it("Should display label text as dialog header title when label for is used", () => {
225+
cy.mount(
226+
<>
227+
<Label for="myMultiInput">Tags</Label>
228+
<MultiInput id="myMultiInput" showSuggestions>
229+
<SuggestionItem text="Item 1" />
230+
<SuggestionItem text="Item 2" />
231+
</MultiInput>
232+
</>
233+
);
234+
235+
cy.get("#myMultiInput")
236+
.shadow()
237+
.find(".ui5-input-inner")
238+
.realClick();
239+
240+
cy.get("#myMultiInput")
241+
.shadow()
242+
.find<ResponsivePopover>("[ui5-responsive-popover]")
243+
.ui5ResponsivePopoverOpened();
244+
245+
cy.get("#myMultiInput")
246+
.shadow()
247+
.find("[ui5-responsive-popover] .ui5-responsive-popover-header-text")
248+
.should("have.text", "Tags");
249+
});
250+
251+
it("Should fallback to 'All Items' when no label is associated", () => {
252+
cy.mount(
253+
<MultiInput id="myMultiInput" showSuggestions>
254+
<SuggestionItem text="Item 1" />
255+
<SuggestionItem text="Item 2" />
256+
</MultiInput>
257+
);
258+
259+
cy.get("#myMultiInput")
260+
.shadow()
261+
.find(".ui5-input-inner")
262+
.realClick();
263+
264+
cy.get("#myMultiInput")
265+
.shadow()
266+
.find<ResponsivePopover>("[ui5-responsive-popover]")
267+
.ui5ResponsivePopoverOpened();
268+
269+
cy.get("#myMultiInput")
270+
.shadow()
271+
.find("[ui5-responsive-popover] .ui5-responsive-popover-header-text")
272+
.should("have.text", INPUT_SUGGESTIONS_TITLE.defaultText);
273+
});
274+
});

packages/main/src/Input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
17601760
}
17611761

17621762
get _headerTitleText() {
1763-
return Input.i18nBundle.getText(INPUT_SUGGESTIONS_TITLE);
1763+
return this._associatedLabelsTexts || Input.i18nBundle.getText(INPUT_SUGGESTIONS_TITLE);
17641764
}
17651765

17661766
get _suggestionsOkButtonText() {

0 commit comments

Comments
 (0)