Skip to content

feat(ui5-search-field): introduce advanced filtering #11428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/fiori/cypress/specs/SearchField.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Button from "@ui5/webcomponents/dist/Button.js";
import SearchField from "../../src/SearchField.js";
import SearchScope from "../../src/SearchScope.js";
import {
Expand Down Expand Up @@ -405,4 +406,43 @@ describe("SearchField general interaction", () => {
.should("have.been.calledOnce");
});
});

describe("SearchField - Advanced and Scope Slot Rendering", () => {
it("renders the advanced slot content when only advanced filtering is provided", () => {
cy.mount(
<SearchField value="test">
<Button slot="advanced" icon="filter"></Button>
</SearchField>
);

cy.get("ui5-search-field").as("searchField");

cy.get("@searchField")
.shadow()
.find('slot[name="advanced"]')
.should("exist");
});

it("renders the scope selector and omits advanced slot when both are provided", () => {
cy.mount(
<SearchField>
<Button slot="advanced" icon="filter"></Button>
<SearchScope text="All" slot="scopes"></SearchScope>
<SearchScope text="Apps" selected slot="scopes"></SearchScope>
</SearchField>
);

cy.get("ui5-search-field").as("searchField");

cy.get("@searchField")
.shadow()
.find("ui5-select")
.should("exist");

cy.get("@searchField")
.shadow()
.find('slot[name="advanced"]')
.should("not.exist");
});
});
});
3 changes: 3 additions & 0 deletions packages/fiori/src/SearchField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ class SearchField extends UI5Element {
@slot({ type: HTMLElement, individualSlots: true, invalidateOnChildChange: true })
scopes!: Array<ISearchScope>;

@slot()
advanced!: HTMLElement;

/**
* @private
*/
Expand Down
19 changes: 12 additions & 7 deletions packages/fiori/src/SearchFieldTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,30 @@ export default function SearchFieldTemplate(this: SearchField) {
) : (
<div class="ui5-search-field-root" role="search" onFocusOut={this._onFocusOutSearch}>
<div class="ui5-search-field-content">
{!!this.scopes.length &&
{this.scopes?.length ? (
<>
<Select
onChange={this._handleScopeChange}
class="sapUiSizeCompact ui5-search-field-select"
accessibleName={this._translations.scope}
tooltip={this._translations.scope}>
{this.scopes.map(scopeOption => {
return <Option
{this.scopes.map(scopeOption => (
<Option
selected={scopeOption.selected}
data-ui5-stable={scopeOption.stableDomRef}
ref={this.captureRef.bind(scopeOption)}
>{scopeOption.text}</Option>;
},
this)}
>{scopeOption.text}
</Option>
))}
</Select>
<div class="ui5-search-field-separator"></div>
</>
}
) : this.advanced ? (
<>
<slot name="advanced"></slot>
<div class="ui5-search-field-separator"></div>
</>
) : null}

<input
class="ui5-search-field-inner-input"
Expand Down
23 changes: 23 additions & 0 deletions packages/fiori/src/themes/SearchField.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@
background-color: var(--sapShellColor);
}

/* advanced slot */
::slotted([slot="advanced"]) {
min-width: var(--_ui5_search_icon_size);
height: var(--_ui5_search_icon_size);
border: var(--_ui5-search-icon-border);
border-radius: var(--_ui5_search_icon_border_radius);
color: var(--sapShell_InteractiveTextColor);
outline: none;
background: none;
box-sizing: border-box;
margin-inline-end: 0.25rem;
margin-inline-start: 0.25rem;
}

::slotted([slot="advanced"]:hover) {
background: var(--_ui5-search-elements-active-background);
border: var(--_ui5_search_filter_button_border_hover);
}

::slotted([slot="advanced"]:focus-within){
background: var(--_ui5-search-elements-active-background);
}

/* input */
.ui5-search-field-inner-input {
font-size: var(--sapFontSize);
Expand Down
2 changes: 2 additions & 0 deletions packages/fiori/src/themes/base/SearchField-parameters.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
:root {
--_ui5_search_icon_border_radius: 1.125rem;
--_ui5_search_filter_button_border_radius: 1.125rem;
--_ui5_search_input_border_radius: 1.125rem;
--_ui5-search-border: none;
--_ui5-search-wrapper-background: var(--sapShell_InteractiveBackground);
Expand All @@ -12,6 +13,7 @@
--_ui5-search-elements-background: inherit;
--_ui5_search_wrapper_outline: var(--sapContent_FocusWidth) var(--sapContent_FocusStyle) var(--sapField_Active_BorderColor);
--_ui5_search_input_outline: none;
--_ui5_search_filter_button_border_hover: 1px solid var(--sapButton_Hover_BorderColor);
--_ui5_search_icon_size: 1.75rem;
--_ui5_search_icon_padding: 0.375rem;
--_ui5_search_icon_hover_padding: 0.3125rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
--_ui5-search-elements-hover-background: var(--sapShell_Hover_Background);
--_ui5-search-elements-active-background: var(--sapShell_Active_Background);
--_ui5_search_wrapper_outline: none;
/* --_ui5_search_filter_button_border_hover: var(--sapField_BorderWidth) var(--sapField_BorderStyle) var(--sapField_BorderColor); */
--_ui5_search_filter_button_border_hover: var(--sapButton_BorderWidth) solid var(--sapButton_BorderColor);
--_ui5_search_input_outline: var(--sapContent_FocusWidth) var(--sapContent_FocusStyle) var(--sapField_Active_BorderColor);
--_ui5_search_icon_size: 2.25rem;
--_ui5_search_icon_padding: 0.5625rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
--_ui5-search-elements-background: var(--sapShell_InteractiveBackground);
--_ui5-search-elements-hover-background: var(--sapShell_Hover_Background);
--_ui5-search-elements-active-background: var(--sapShell_Active_Background);
/* --_ui5_search_filter_button_border_hover: var(--sapField_BorderWidth) var(--sapField_BorderStyle) var(--sapField_BorderColor); */
--_ui5_search_filter_button_border_hover: var(--sapButton_BorderWidth) solid var(--sapButton_BorderColor);
--_ui5_search_wrapper_outline: none;
--_ui5_search_input_outline: var(--sapContent_FocusWidth) var(--sapContent_FocusStyle) var(--sapField_Active_BorderColor);
--_ui5_search_icon_size: 2.25rem;
Expand Down
4 changes: 4 additions & 0 deletions packages/fiori/test/pages/SearchField.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<ui5-search-scope text="Products" slot="scopes"></ui5-search-scope>
</ui5-search-field>
</div>
<ui5-label>advanced filtering search</ui5-label>
<ui5-search-field>
<ui5-button slot="advanced" icon="filter"></ui5-button>
</ui5-search-field>
<div class="container" style="padding-top: 1rem; display: flex; flex-direction: column;">
<ui5-label>Collapsed search</ui5-label>
<div class="container" style="border: 1px solid black; display: flex; padding: 4px; justify-content: flex-end;">
Expand Down
Loading