FIX: Bookmark search input can't be cleared with backspace with ?q= present (#31919)

Meta:
https://meta.discourse.org/t/cant-erase-the-bookmark-search-input/357861/4

> When we fill in the bookmark search input and send the request, then
we can’t delete the input’s content.

After removing the last character, the `searchTerm` getter is called. At
this point, `_searchTerm` is empty.
However, `this._searchTerm || this.q` will treat the empty string as
_falsy_, and the `q` value is displayed instead.
It makes it impossible to clear the input.

To fix this, we check specifically on the initial state of
`_searchTerm,` which is _undefined_, to include an empty string as a
valid value.

Note: because of `@computed`, the issue is not triggered when the
content is selected and deleted.
This commit is contained in:
Arkshine
2025-03-21 09:50:05 +08:00
committed by GitHub
parent 0dd2d4c1b5
commit dd0a6bd188
3 changed files with 20 additions and 1 deletions
@@ -30,7 +30,7 @@ export default class UserActivityBookmarksController extends Controller {
@computed("q")
get searchTerm() {
return this._searchTerm || this.q;
return this._searchTerm !== undefined ? this._searchTerm : this.q;
}
set searchTerm(value) {
@@ -20,11 +20,24 @@ module PageObjects
self
end
def clear_query_with_backspace
search_element.value.length.times { search_element.send_keys(:backspace) }
self
end
def fill_in_search(query)
fill_in("bookmark-search", with: query)
self
end
def search_element
find_by_id("bookmark-search")
end
def has_empty_search?
search_element.value == ""
end
def has_topic?(topic)
has_content?(topic.title)
end
@@ -58,4 +58,10 @@ describe "User activity bookmarks", type: :system do
expect(user_activity_bookmarks).to have_topic(bookmark_1.bookmarkable.topic)
expect(user_activity_bookmarks).to have_topic(bookmark_2.bookmarkable.topic)
end
it "can clear the query with backspace" do
user_activity_bookmarks.visit(current_user, q: "dog")
user_activity_bookmarks.clear_query_with_backspace
expect(user_activity_bookmarks).to have_empty_search
end
end