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

iOS - Button Click is ignored when there is a dynamic view created based on a touch or mouse Event #50230

Open
jbchr opened this issue May 10, 2023 · 5 comments
Labels
area: core Issues related to the framework runtime iOS Issue related to Apple's iOS operating system needs reproduction This issue needs a reproduction in order for the team to investigate further state: needs more investigation
Milestone

Comments

@jbchr
Copy link

jbchr commented May 10, 2023

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

This bug is only happening in iOS:

If a view is created through *ngIf or ViewContainerRef.createEmbeddedView based on an event listener to touchstart or other mouse events and there is a button outside of the dynamic view then this button need to be clicked twice in order for the click event to be fired.

A minimal reproduction example is this:

import { CommonModule } from '@angular/common';
import { bootstrapApplication } from '@angular/platform-browser';
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [CommonModule],
  template: `
    <h1>Angular iOS Click Bug Demo</h1>
    <p> In all browsers clicking the 'Hello' button will trigger an alert immediately.</p>
    <p> But in iOS Safari two clicks are needed. However this only happens if the dynamic view inside the ngIf contains an interactive element.<p>
    <p> If you remove the click listener manually it will work.</p>
    <button (click)="alert('test')">Hello</button>
    <div *ngIf="active"><span (click)="alert('you clicked the span')">Some interactive element</span></div>
  `
})
export class AppComponent {
  active = false;
  alert = alert;

  constructor() {
      window.addEventListener('touchstart', () => this.setActive());
  }

  setActive() {
    if (!this.active) {
      this.active = true;
    }
  }
}


bootstrapApplication(AppComponent)

In this example the Hello button needs to be clicked twice in iOS. If you remove the (click) event from the span inside the dynamic view then the Hello button needs to be clicked only once

Please provide a link to a minimal reproduction of the bug

https://github.com/jbchr/angular-ios-click-bug

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 16.0.0
Node: 16.20.0
Package Manager: npm 8.19.4
OS: darwin arm64

Angular: 16.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1600.0
@angular-devkit/build-angular   16.0.0
@angular-devkit/core            16.0.0
@angular-devkit/schematics      16.0.0
@schematics/angular             16.0.0
rxjs                            7.8.1
typescript                      5.0.4

But this is happening also at least from Angular V12

Anything else?

No response

@pkozlowski-opensource
Copy link
Member

@pkozlowski-opensource
Copy link
Member

@jbchr does it need RxJS in the mix to reproduce? I'm trying to narrow it down to the bare minimum, the equivalent without RxJS would be: https://stackblitz.com/edit/angular-n3ttvb?file=src%2Fmain.ts,src%2Findex.html

Also, does it need to have both touchstart and mousedown to reproduce?

Again, I suspect some subtle timing issue and want to make sure that we've got absolutely minimal reproduce scenario so we can understand what is going on.

@pkozlowski-opensource pkozlowski-opensource added needs reproduction This issue needs a reproduction in order for the team to investigate further iOS Issue related to Apple's iOS operating system state: needs more investigation area: core Issues related to the framework runtime labels May 10, 2023
@ngbot ngbot bot added this to the Backlog milestone May 10, 2023
@jbchr
Copy link
Author

jbchr commented May 10, 2023

@pkozlowski-opensource thanks for getting back to me so quickly.

RxJS is not needed, also mousedown is not needed, I only added it to have the same behaviour (rendering the dynamic view) in the desktop browser.

Removed both from the code above and in the github repo

@jbchr
Copy link
Author

jbchr commented May 17, 2023

@pkozlowski-opensource is this info sufficient?

@jbchr
Copy link
Author

jbchr commented Oct 11, 2023

@pkozlowski-opensource are there any more infos needed from my side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues related to the framework runtime iOS Issue related to Apple's iOS operating system needs reproduction This issue needs a reproduction in order for the team to investigate further state: needs more investigation
Projects
None yet
Development

No branches or pull requests

2 participants