ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
50.48k stars 13.53k forks source link

bug: IonChange event not fired when clear button is clicked on ion-searchbar #28613

Closed adedayojs closed 5 months ago

adedayojs commented 5 months ago

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

When I have ionChange event in . Clicking the clear button, The ionChange event isn't triggered.

Expected Behavior

According to the documentation

The ionChange event is fired when the value has been committed by the user. This can happen when the element loses focus or when the "Enter" key is pressed. ionChange can also fire when clicking the clear or cancel buttons.

Steps to Reproduce

  1. use this line of code <ion-searchbar (ionChange)="updateFilter($event)" show-clear-button="always"></ion-searchbar>
  2. Type in an input
  3. Exit the box or press enter (The ionChange event is fired)
  4. Now click the clear button
  5. Change event is not fired until i click out of the field

Note: I am using the standalone approach

https://github.com/ionic-team/ionic-framework/assets/52340442/3653aea8-c301-42e5-8828-df89993b194d

Code Reproduction URL

No response

Ionic Info

Ionic:

Ionic CLI : 7.1.5 (/Users/adedayojs/.config/yarn/global/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 7.5.6 @angular-devkit/build-angular : 16.2.9 @angular-devkit/schematics : 15.2.10 @angular/cli : 16.2.9 @ionic/angular-toolkit : 9.0.0

Capacitor:

Capacitor CLI : 5.5.1 @capacitor/android : 5.5.1 @capacitor/core : 5.5.1 @capacitor/ios : not installed

Utility:

cordova-res : not installed globally native-run (update available: 2.0.0) : 1.7.4

System:

NodeJS : v20.9.0 (/Users/adedayojs/.nvm/versions/node/v20.9.0/bin/node) npm : 10.1.0 OS : macOS Unknown

Additional Information

No response

liamdebeasi commented 5 months ago

Thanks for the issue. I am going to close this as this is not a bug in Ionic Framework. As per the documentation, ionChange is only fired once the value has been committed including when the clear button is clicked. The input is still focused even after clicking the clear button, so the value has not been committed yet. As a result, ionChange only fires after you blur the input.

adedayojs commented 5 months ago

Thanks for the issue. I am going to close this as this is not a bug in Ionic Framework. As per the documentation, ionChange is only fired once the value has been committed including when the clear button is clicked. The input is still focused even after clicking the clear button, so the value has not been committed yet. As a result, ionChange only fires after you blur the input.

Thanks for the timely response. I guess the last part of the documentation was misleading in this case and i'd suggest it should be revisited.

Thanks

liamdebeasi commented 5 months ago

If you have ideas for how the documentation could be improved, I'd be happy to review a PR. The following area of Ionic should be updated: https://github.com/ionic-team/ionic-framework/blob/a3cd204f616606ccffc35082655e55fdfb19fe28/core/src/components/searchbar/searchbar.tsx#L177-L184

You'll need to run npm run build so any generated changes can also show up on the docs website.

ionitron-bot[bot] commented 4 months ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.