ionic-team / ionic-team/ionic-framework

feat: add event for clicking on searchbar search icon

Open
#19,997 7 comments 3 reactions 0 assignees View on GitHub
package: core type: feature request
Dominant language
TypeScript
Stars
52.7k
Forks
13.3k
Avg merge
1d 15h
Merged PRs (30d)
51

Description

# 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)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.