Skip to content

Commit 67eb583

Browse files
fix(ui5-search): change growing button to footer button (#11155)
1 parent 4d75b7d commit 67eb583

File tree

5 files changed

+62
-34
lines changed

5 files changed

+62
-34
lines changed

packages/fiori/cypress/specs/Search.cy.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,12 @@ describe("Properties", () => {
403403
cy.get("[ui5-search]")
404404
.shadow()
405405
.find("[ui5-responsive-popover]")
406-
.find("[ui5-list]")
407-
.as("list");
406+
.find(".ui5-search-footer-button")
407+
.as("button");
408408

409-
cy.get("@list")
410-
.should("have.attr", "growing", "Button")
411-
.and("have.attr", "growing-button-text", "Show All");
409+
cy.get("@button")
410+
.should("exist")
411+
.and("have.text", "Show All");
412412
});
413413
});
414414

@@ -610,12 +610,11 @@ describe("Events", () => {
610610

611611
cy.get("[ui5-search]")
612612
.shadow()
613-
.find("[ui5-list]")
614-
.as("list");
613+
.find("[ui5-responsive-popover]")
614+
.as("popup");
615615

616-
cy.get("@list")
617-
.shadow()
618-
.find(".ui5-growing-button")
616+
cy.get("@popup")
617+
.find(".ui5-search-footer-button")
619618
.realClick();
620619

621620
cy.get("@actionPressed")

packages/fiori/src/Search.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
isHome,
1919
isEnd,
2020
isRight,
21+
isTabPrevious,
2122
} from "@ui5/webcomponents-base/dist/Keys.js";
2223

2324
import SearchTemplate from "./SearchTemplate.js";
@@ -28,7 +29,7 @@ import type UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
2829
import type SearchItem from "./SearchItem.js";
2930
import { renderFinished } from "@ui5/webcomponents-base/dist/Render.js";
3031
import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
31-
import ListGrowingMode from "@ui5/webcomponents/dist/types/ListGrowingMode.js";
32+
import type Button from "@ui5/webcomponents/dist/Button.js";
3233

3334
interface ISearchSuggestionItem extends UI5Element {
3435
selected: boolean;
@@ -137,6 +138,7 @@ class Search extends SearchField {
137138

138139
/**
139140
* Defines whether the popup footer action button is shown.
141+
* Note: The footer action button is displayed only when the `popupMode` is set to `List`.
140142
* @default false
141143
* @public
142144
*/
@@ -383,18 +385,32 @@ class Search extends SearchField {
383385
this._openPickerOnInput = false;
384386
}
385387

388+
_onFooterButtonKeyDown(e: KeyboardEvent) {
389+
if (isUp(e)) {
390+
this._flattenItems[this._flattenItems.length - 1].focus();
391+
}
392+
if (isTabPrevious(e)) {
393+
this._getItemsList().focus();
394+
}
395+
}
396+
386397
_onItemKeydown(e: KeyboardEvent) {
387-
const items = this._getItemsList()?.getSlottedNodes<ISearchSuggestionItem>("items");
388-
const isFirstItemGroup = items[1] === e.target && items[0]?.hasAttribute("ui5-li-group");
389-
const isFirstItem = items[0] === e.target || isFirstItemGroup;
398+
const isFirstItem = this._flattenItems[0] === e.target;
399+
const isLastItem = this._flattenItems[this._flattenItems.length - 1] === e.target;
390400
const isArrowUp = isUp(e);
401+
const isArrowDown = isDown(e);
402+
const isTab = isTabNext(e);
391403

392404
e.preventDefault();
393405

394406
if (isFirstItem && isArrowUp) {
395407
this.nativeInput?.focus();
396408
this._shouldAutocomplete = true;
397409
}
410+
411+
if ((isLastItem && isArrowDown) || isTab) {
412+
this._getFooterButton()?.focus();
413+
}
398414
}
399415

400416
_onItemClick(e: CustomEvent) {
@@ -470,7 +486,7 @@ class Search extends SearchField {
470486
this.fireDecoratorEvent("open");
471487
}
472488

473-
_handleMore() {
489+
_onFooterButtonClick() {
474490
this.fireDecoratorEvent("popup-action-press");
475491
}
476492

@@ -503,6 +519,10 @@ class Search extends SearchField {
503519
return this._getPicker().querySelector(".ui5-search-list") as List;
504520
}
505521

522+
_getFooterButton(): Button {
523+
return this._getPicker().querySelector(".ui5-search-footer-button") as Button;
524+
}
525+
506526
get _flattenItems(): Array<ISearchSuggestionItem> {
507527
return this.getSlottedNodes<ISearchSuggestionItem>("items").flatMap(item => {
508528
return this._isGroupItem(item) ? [item, ...item.items!] : [item];
@@ -527,8 +547,8 @@ class Search extends SearchField {
527547
return !!this.headerText;
528548
}
529549

530-
get _effectiveGrowing() {
531-
return this.showPopupAction ? ListGrowingMode.Button : ListGrowingMode.None;
550+
get _showFooter() {
551+
return !!this.showPopupAction && this.popupMode === SearchPopupMode.List;
532552
}
533553
}
534554

packages/fiori/src/SearchPopoverTemplate.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import ListSeparator from "@ui5/webcomponents/dist/types/ListSeparator.js";
88
import TitleLevel from "@ui5/webcomponents/dist/types/TitleLevel.js";
99
import PopoverHorizontalAlign from "@ui5/webcomponents/dist/types/PopoverHorizontalAlign.js";
1010
import PopoverPlacement from "@ui5/webcomponents/dist/types/PopoverPlacement.js";
11+
import Button from "@ui5/webcomponents/dist/Button.js";
12+
import ButtonDesign from "@ui5/webcomponents/dist/types/ButtonDesign.js";
1113

1214
export default function SearchPopoverTemplate(this: Search) {
1315
return (
@@ -41,15 +43,23 @@ export default function SearchPopoverTemplate(this: Search) {
4143
<main>
4244
<List
4345
class="ui5-search-list"
44-
onLoadMore={this._handleMore}
4546
separators={ListSeparator.None}
46-
growingButtonText={this.popupActionText}
47-
growing={this._effectiveGrowing}
4847
onKeyDown={this._onItemKeydown}
4948
onItemClick={this._onItemClick}>
5049
<slot></slot>
5150
</List>
5251
</main>
52+
53+
{this._showFooter &&
54+
<Button
55+
slot="footer"
56+
design={ButtonDesign.Transparent}
57+
class="ui5-search-footer-button"
58+
onKeyDown={this._onFooterButtonKeyDown}
59+
onClick={this._onFooterButtonClick}>
60+
{this.popupActionText}
61+
</Button>
62+
}
5363
</>
5464
)
5565
)}

packages/fiori/src/themes/Search.css

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@
5353
width: auto;
5454
}
5555

56-
.ui5-search-list::part(growing-button-inner) {
57-
border-radius: .5rem;
56+
.ui5-search-popover::part(footer) {
57+
padding-bottom: 0.25rem;
58+
padding-top: 0.5rem;
5859
}
5960

60-
.ui5-search-list::part(growing-button) {
61-
border-bottom: none;
62-
padding-top: .25rem;
63-
box-sizing: border-box;
61+
.ui5-search-footer-button {
62+
width: 100%;
6463
}

packages/fiori/src/themes/SearchField.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@
178178
}
179179

180180
/* copy paste all button styles - could be simplified */
181-
[ui5-button][desktop]:not([active])::part(button):after,
182-
[ui5-button]:not([active])::part(button):focus-visible:after,
183-
[ui5-button][desktop][active][design="Emphasized"]::part(button):focus-within:after,
184-
[ui5-button][active][design="Emphasized"]::part(button):focus-visible:after,
185-
[ui5-button][desktop][active]::part(button):focus-within:before,
186-
[ui5-button][active]::part(button):focus-visible:before,
187-
[ui5-button][design="Emphasized"][desktop]::part(button):focus-within:before,
188-
[ui5-button][design="Emphasized"]::part(button):focus-visible:before {
181+
.ui5-shell-search-field-button[desktop]:not([active])::part(button):after,
182+
.ui5-shell-search-field-button:not([active])::part(button):focus-visible:after,
183+
.ui5-shell-search-field-button[desktop][active][design="Emphasized"]::part(button):focus-within:after,
184+
.ui5-shell-search-field-button[active][design="Emphasized"]::part(button):focus-visible:after,
185+
.ui5-shell-search-field-button[desktop][active]::part(button):focus-within:before,
186+
.ui5-shell-search-field-button[active]::part(button):focus-visible:before,
187+
.ui5-shell-search-field-button[design="Emphasized"][desktop]::part(button):focus-within:before,
188+
.ui5-shell-search-field-button[design="Emphasized"]::part(button):focus-visible:before {
189189
border-radius: var(--_ui5_search_icon_border_radius);
190190
}
191191

0 commit comments

Comments
 (0)