From cc2d5c264ab39ab57b1bc5c72fba422bb481ee65 Mon Sep 17 00:00:00 2001 From: "Martin R. Hristov" Date: Thu, 11 Dec 2025 16:11:46 +0200 Subject: [PATCH] fix(ui5-search-field): add scope-value property --- .../fiori/cypress/specs/SearchField.cy.tsx | 42 +++++++++++++++++++ packages/fiori/src/SearchField.ts | 22 +++++++++- packages/fiori/src/SearchFieldTemplate.tsx | 6 ++- packages/fiori/src/SearchScope.ts | 9 ++-- packages/fiori/test/pages/Search.html | 10 ++--- packages/fiori/test/pages/SearchField.html | 8 ++-- .../fiori/test/pages/ShellBar_evolution.html | 8 ++-- .../docs/_samples/fiori/Search/Basic/main.js | 2 +- .../_samples/fiori/Search/Basic/sample.html | 8 ++-- .../patterns/UXCIntegration/Basic/main.js | 2 +- .../patterns/UXCIntegration/Basic/sample.html | 8 ++-- 11 files changed, 95 insertions(+), 30 deletions(-) diff --git a/packages/fiori/cypress/specs/SearchField.cy.tsx b/packages/fiori/cypress/specs/SearchField.cy.tsx index 4461ccfea3d3..db80dffd555b 100644 --- a/packages/fiori/cypress/specs/SearchField.cy.tsx +++ b/packages/fiori/cypress/specs/SearchField.cy.tsx @@ -396,6 +396,48 @@ describe("SearchField general interaction", () => { .should("have.length", 2); }); + it("preselected scope option should be applied", () => { + cy.mount( + + + ); + + cy.get("[ui5-search-field]") + .shadow() + .find("[ui5-select]") + .as("select"); + + cy.get("@select") + .should("have.prop", "value", "products"); + }); + + it("changes scope-value on option select", () => { + cy.mount( + + + ); + + cy.get("[ui5-search-field]") + .as("searchfield"); + + cy.get("@searchfield") + .shadow() + .find("[ui5-select]") + .as("scope"); + + cy.get("@scope") + .realClick(); + + cy.get("@scope") + .realPress("ArrowDown"); + + cy.get("@scope") + .realPress("Enter"); + + cy.get("@searchfield") + .should("have.prop", "scopeValue", "products"); + }); + it("scope-change event should be fired, when a scope option is selected", () => { cy.mount( diff --git a/packages/fiori/src/SearchField.ts b/packages/fiori/src/SearchField.ts index 2fa543c1147a..4956195e1b9d 100644 --- a/packages/fiori/src/SearchField.ts +++ b/packages/fiori/src/SearchField.ts @@ -28,7 +28,7 @@ import { */ interface ISearchScope extends UI5Element { text?: string, - selected: boolean, + value?: string, stableDomRef: string, } @@ -153,6 +153,20 @@ class SearchField extends UI5Element { @property() accessibleDescription?: string; + /** + * Defines the value of the component: + * + * Applications are responsible for setting the correct scope value. + * + * **Note:** If the given value does not match any existing scopes, + * no scope will be selected and the SearchField scope component will be displayed as empty. + * @public + * @default "" + * @since 2.18.0 + */ + @property() + scopeValue?: string; + /** * Defines the component scope options. * @public @@ -241,6 +255,12 @@ class SearchField extends UI5Element { _handleScopeChange(e: CustomEvent) { const item = e.detail.selectedOption as IOption & { scopeOption: ISearchScope }; + + // Set the scopeValue property if the selected scope has a value defined + if (item.value) { + this.scopeValue = item.value; + } + this.fireDecoratorEvent("scope-change", { scope: item.scopeOption, }); diff --git a/packages/fiori/src/SearchFieldTemplate.tsx b/packages/fiori/src/SearchFieldTemplate.tsx index 8f593f613b9f..27335c257a7f 100644 --- a/packages/fiori/src/SearchFieldTemplate.tsx +++ b/packages/fiori/src/SearchFieldTemplate.tsx @@ -36,10 +36,12 @@ export default function SearchFieldTemplate(this: SearchField, options?: SearchF onChange={this._handleScopeChange} class="sapUiSizeCompact ui5-search-field-select" accessibleName={this._translations.scope} - tooltip={this._translations.scope}> + tooltip={this._translations.scope} + value={this.scopeValue} + > {this.scopes.map(scopeOption => (