Bug 52593 - SearchBar won't execute SearchCommand if there's no text
Summary: SearchBar won't execute SearchCommand if there's no text
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Chris King
Depends on:
Reported: 2017-02-17 00:50 UTC by Kent
Modified: 2017-04-21 18:04 UTC (History)
5 users (show)

Tags: searchbar behavior ac
Is this bug a regression?: ---
Last known good build:

Repro (146.46 KB, application/x-zip-compressed)
2017-02-17 00:50 UTC, Kent

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Kent 2017-02-17 00:50:53 UTC
Created attachment 19857 [details]

If there is no text entered into the SearchBar and the user presses the search button (enter), nothing happens. The SearchCommand is not executed, nor is the SearchButtonPressed event raised.

This is a problem because if the user searches for "foo", and then clears their search to go back to "all results", the SearchCommand cannot be executed and the view model must resort to hacks to make this work.

Repro is attached.
Comment 1 Paul DiPietro [MSFT] 2017-02-22 01:28:06 UTC
The reproduction provided only includes an iOS implementation. Are you expecting this behavior to be across all platforms? By default on iOS, the Search button is not enabled if there is no text in the field, so this sort of behavior would be expected. I'm setting this to NEEDINFO for now as an elaboration of expectations is required, which I hope you understand.
Comment 2 Kent 2017-02-22 01:30:56 UTC
Thanks Paul.

Yes, my expectation is consistency across platforms. I only included iOS to keep the download smaller and more focussed.

If the platform behavior is to be upheld, is there an alternative to the hack I mentioned?
Comment 3 Kent 2017-02-22 22:49:56 UTC
Setting status back to new as I believe I answered your questions.
Comment 4 Paul DiPietro [MSFT] 2017-02-23 01:03:12 UTC
For the time being I'll set this to confirmed, although something like this will need to be discussed with the team before we move further. We typically aim to keep behavior in line with what the platform does by default; there are exceptions to this, but is unfortunately no guarantee that anything will be changed from the current behavior.

Based on what you described, what I would perhaps suggest for now is hooking into TextChanged and if the Text value returns to an empty state to call whatever method you'd use to reset the search, although it's possible you're already doing something similar to this.
Comment 5 Kent 2017-02-23 01:05:33 UTC
Thanks Paul.

Yes, that is exactly what I'm doing. The problem of course is that the user experience is inconsistent. On the one hand, searching for "foo" requires that they instigate the search. On the other, clearing the text will automatically search. This is jarring if they've entered some text erroneously, and want to delete it to start again.
Comment 6 Chris King 2017-04-21 18:03:44 UTC
Kent, on a device the user has no "enter" key to hit; the user hits "search" on the onscreen keyboard to search and that "search" button is grayed out if there is no text in the search box which is typical per iOS UX. Do you suggest we offer an option to enable that button on iOS when there is no text in the search field? I'm not sure that feature would fly simply because most iOS users are accustomed to seeing a default search if there is not text in the field and even that the search populates as they type. But if you'd like to make that request please post it to the forums as the behavior now is expected as far as I can tell.