After upgrading to RC0, the searchbar for material design stopped showing the back button on the left, where it was replacing the search icon and triggering (ionCancel). It works fine on iOS, just not working on android.
Hi @michaschwab, earlier I was not aware there was a built-in cancel and back buttons so I was trying to wrap my own. I cooked up several attempts like so
The X causes the search field to clear (back arrow remains)
The back arrow causes the SearchBar to reset, like so
On Android Messenger (texter), and apparently Twitter, the back-arrow renders outside the SearchBar. Does that mean it requires a custom layout, of a separate button, to achieve a similar look?
How can I intercept this built-in back-arrow click event to hide/close the SearchBar.
What does !!searchTerm mean NotNot operator? is “searchTerm” a built-in thing or something you declare in your component code?
Note: In my use model, I would like the SearchBar to be visible by default on this page (subject to user options) so I provide a separate (conditional) magnifier button for showing the SearchBar if it were to be closed.
and similarly moving the search field to the right to make space for the cancel icon.
It’s just double negation to turn searchTerm (a string) into a boolean value. If it’s empty, it’s false, and if it’s not empty, it’s true.
It’s the model value of my search box. You can see that in my post because it is introduced at <ion-searchbar [(ngModel)]="searchTerm"></ion-searchbar> .
Thanks, I learned something new about JS/TS that negating a string turns it into a boolean. I never done anything similar in C# or even in VB (it’s probably possible)
I was not clear about the first part of your answer. You think it would be possible to intercept the built-in back-arrow click event via CSS ?
Regarding the css you provided I dropped as is and it only causes the show searchbar to left flush (dock) the back-arrow is still inside the rectangular frame of the searchbar/field. I will into the chrome console and try to see if I can decipher what’s happening.
Last, I am used to setting ngModel to a member of the component class and often directly a member of a service injected in the component in order to create a binding. However, in your case I know I do not have searchTerm defined in the code behind. So I am puzzled where/how it is causing it to refer to the search field content. So how is the value of searchTerm acquired if it is not built-in in ionic/angular?
For filtering in my case I am getting the search field content via $event.target.value according to the docs.
I understand [class.has-content]="!!searchTerm" to mean assign style class .has-content if the field is not empty. I assume .has-content is something you defined or perhaps that’s an ionic style?
I discovered that the api doc mentions how to intercept the "cancel button"
basically via
(ionCancel)="OnCancel($event)"
BTW, it’s kind of misleading that they use an X icon for clear instead of some other kind of symbol like an eraser because first I was thinking that X meant the cancel button not the back-arrow