-
Notifications
You must be signed in to change notification settings - Fork 13.5k
bug: ion-item click event emitted two times (with ion-input) #29761
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
Comments
This looks to be the same as #28803 (comment). |
@liamdebeasi this seems like a good case for a missing feature: <ion-item [do-not-click-childs]="true" ... I'm building a screen with We need an input flag to disable that click, and that would help my case and this double click stuff too. PS/ this check discards the click inside the input to avoid double-clicks? clickedWithinShadowRoot = this.el.shadowRoot!.contains(target); |
Hey there! I no longer work for Ionic, so I won't be much help in getting this resolved. However, if this issue is important for your use case I recommend adding a thumbs up reaction to the original post in addition to your comment above. |
@liamdebeasi thank you very much! |
@matheo I like the idea too |
@JulienLecoq I had to build this Directive to intercept the
|
@matheo Thanks a lot, you inspired me this that ChatGPT built for me cause I'm not a pro of those stuff haha. import { Directive, ElementRef, HostListener, inject, output, } from '@angular/core'
@Directive({
selector: 'ion-item[smartClick]',
})
export class IonItemSmartClickDirective {
private readonly element = inject(ElementRef<HTMLElement>).nativeElement
readonly smartClick = output<MouseEvent>()
@HostListener('click', ['$event'])
handleClick(event: MouseEvent) {
// Ignore synthetic or non-user-initiated click.
if (event.detail === 0) return
// Clone the event with a modified target pointing to ion-item.
const proxyEvent = new MouseEvent(event.type, event)
Object.defineProperty(proxyEvent, 'target', {
value: this.element,
writable: false,
})
this.smartClick.emit(proxyEvent)
}
} |
Prerequisites
Ionic Framework Version
v8.x
Current Behavior
When putting a ion-input inside of an ion-item, the click event on the ion-item is emitted two times when clicking just above or below the ion-input.
Expected Behavior
The click event should be emitted just once.
Steps to Reproduce
Code Reproduction URL
https://github.com/JulienLecoq/bug_ion-item_click_with_ion-input
Ionic Info
Ionic:
Ionic CLI : 7.2.0 (/Users/julien_lecoq/.nvm/versions/node/v20.14.0/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 8.2.6
@angular-devkit/build-angular : 18.1.4
@angular-devkit/schematics : 18.1.4
@angular/cli : 18.1.4
@ionic/angular-toolkit : 11.0.1
Capacitor:
Capacitor CLI : 6.1.2
@capacitor/android : not installed
@capacitor/core : 6.1.2
@capacitor/ios : not installed
Utility:
cordova-res : not installed globally
native-run : 2.0.1
System:
NodeJS : v20.14.0 (/Users/julien_lecoq/.nvm/versions/node/v20.14.0/bin/node)
npm : 10.7.0
OS : macOS Unknown
Additional Information
No response
The text was updated successfully, but these errors were encountered: