Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add event for clicking on searchbar search icon #19997

Open
Monomachus opened this issue Nov 25, 2019 · 7 comments
Open

feat: add event for clicking on searchbar search icon #19997

Monomachus opened this issue Nov 25, 2019 · 7 comments
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement

Comments

@Monomachus
Copy link

Feature Request

I'd like to have a possibility to assign an event listener to searchbar icon

Ionic version:

[x] 4.x

Describe the Feature Request

I have the angular (search) eventListener, but it would only be firing when we click enter on the ion-searchbar. When we click on the search icon nothing happens. What I would like to happen is actually the same search action

Describe Preferred Solution

The easiest way would be to have defined a search event and that event would apply on enter and on clicking the search icon.

Describe Alternatives

Another one way would be just allowing to define an event when clicking the icon. It that case we can still use (search) from search bar, but also an event listener for the search icon.

Related Code

Additional Context

I've seen this solution https://forum.ionicframework.com/t/ionic-search-bar-search-icon-clicked/77072/4 which implies using elementRef, but not sure if this is a great solution because of the fact that those listeners could leak if not removed, etc.

Also I've read about HostListener, but when I add it to the searchbar and set click event, it is always showing as event target the searchbar (even when I click on the icon itself)

@ionitron-bot ionitron-bot bot added the triage label Nov 25, 2019
@liamdebeasi
Copy link
Contributor

Thanks for the feature request. Can you explain your use case for this feature a bit more?

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Nov 25, 2019
@ionitron-bot ionitron-bot bot removed the triage label Nov 25, 2019
@Monomachus
Copy link
Author

Ok, so in my case, a user is typing in a search bar and the search shouldn't happen once the user ends typing, but instead, when he/she press the enter button on the keyboard or which seems more obvious (at least in my case) - press the search icon.

image

When I inspected the code I saw that 'clear' icon is, in fact, a button.
So it would be great if the search icon could also be pressed, and once it's pressed I'd have an event handler to pass a method (what should be performed when the icon is searched).
In my case only when the icon would be pressed I'd do the call to the API, and show the list of results.

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Nov 27, 2019
@AbhishekJ01
Copy link

Is there any update on how to achieve this?? As I have same exact requirement on my project.

@brandyscarney brandyscarney added package: core @ionic/core package type: feature request a new feature, enhancement, or improvement labels Jan 26, 2020
@messkan
Copy link

messkan commented May 16, 2020

any updates please?

@PulpFuture
Copy link

Is anyone aware of a workaround?

@Monomachus
Copy link
Author

Monomachus commented Aug 6, 2020

I've created a new component with a search bar and a button :(
Not ideal, but it works as asked by the end-users

image

@PulpFuture
Copy link

I've created a new component with a search bar and a button :(
Not ideal, but it works as asked by the end-users

image

Yeah I just hid the icon and put a button in the search bar for now. I couldn't get query selectors or local references to pick it up to add a click.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement
Projects
None yet
Development

No branches or pull requests

6 participants