Skip to content

Conversation

kgogov
Copy link
Member

@kgogov kgogov commented Aug 29, 2025

The cancel button now clears the search field value by default. Previously, the search field value was preserved. To maintain the previous behavior, listen for the search-field-clear event and call preventDefault().

  • Add search-field-clear event with preventDefault support
  • Change default behavior to clear search field value on cancel
  • Separate clearing behavior from closing behavior
  • Add comprehensive test coverage for both scenarios

Jira: BGSOFUIPIRIN-6909

@dobrinyonkov
Copy link
Contributor

Looks good overall, just two comments:

  1. Let’s mark the new event as experimental for now.
  2. BUG: If the event is prevented and the search field isn’t cleared, the field cannot be reopened.

@kgogov kgogov force-pushed the shellbar-clear-search-value branch 2 times, most recently from 43cd0d7 to 6114c0e Compare September 1, 2025 14:36
@@ -661,7 +680,7 @@ class ShellBar extends UI5Element {
this._detachSearchFieldListeners(e.target as HTMLElement);
return;
}
if (!isPhone() && !this.search?.value) {
if (!isPhone()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This covers a case in how the search opens/collapses. Instead, we should extend it with || !this.showSearchField, so that we also cover the case when the search field is explicitly closed.

To test this, you can type something in the filed and press the search icon - it shouldn't close the filed, the users will instead trigger a search.

The logic here ensures:

  • On mobile, the search opens on its own (we don’t interfere).
  • If there’s already a value, the search event is responsible for triggering the search (we don’t interfere).
  • (the new condition) If the field is closed, we must open it regardless.

It's not well documented, lets add a comment above to have this info in mind when making changes in future, e.g,:

// Decide when to toggle the search field:
// -  On mobile, the search opens on its own (we don’t interfere).
// - If there’s already a value, onSearch is responsible for triggering the search (we don’t interfere)
// - If the field is closed, we must open it regardless.
if (!isPhone() && (!this.search?.value || !this.showSearchField)) {
	this.setSearchState(!this.showSearchField);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor (optional): We could also flip the condition for readability, e.g.:

if (isPhone() || (this.search?.value && this.showSearchField)) {
return;
}

this.setSearchState(!this.showSearchField);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the well-done review! I really didn’t know about this!

The cancel button now clears the search field value
by default. Previously, the search field value was preserved. To
maintain the previous behavior, listen for the search-field-clear
event and call preventDefault().

- Add search-field-clear event with preventDefault support
- Change default behavior to clear search field value on cancel
- Separate clearing behavior from closing behavior
- Add comprehensive test coverage for both scenarios

Jira: BGSOFUIPIRIN-6909
@kgogov kgogov force-pushed the shellbar-clear-search-value branch from 6114c0e to 02c0ad0 Compare September 2, 2025 08:39
@kgogov kgogov requested a review from dobrinyonkov September 2, 2025 08:42
@kgogov kgogov merged commit c178acd into main Sep 2, 2025
19 of 20 checks passed
@kgogov kgogov deleted the shellbar-clear-search-value branch September 2, 2025 10:46
@ui5-webcomponents-bot
Copy link
Collaborator

🎉 This PR is included in version v2.14.0-rc.7 🎉

The release is available on v2.14.0-rc.7

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants