The Ion-item-option button requires two clicks to activate

Within my ion-list, I have sliding items that are dynamically created using a for loop. Interestingly, when clicking on an item to navigate to another page, everything works fine. However, upon sliding an item, a button is revealed but it requires two clicks (90% of the time) to trigger any action.

I've attempted:

To use the "(click)" event in both the <ion-item> and <ion-avatar> tags without success. Additionally, the list being stored in Ionic storage via this.storage.set('list') does not seem to impact this behavior. The number of list items also has no effect. Moreover, the ion-list within the <div *ngIf = "loaded"> doesn't pose any issues either. Could it be possible that the item covers the ion-item-options causing the second click to register as a click on the actual button?

I even added a hard-coded item with sliding options to no avail...

This issue has been reported to Ionic on GitHub

<div *ngIf="loaded">
<ion-list *ngFor="let item of items; let i = index" routerDirection="forward">
      <ion-item-sliding #slidingItem (click)="dosomething()">
        <ion-item >
        <ion-avatar>
          <img [src]=items[0].imgUrl>
        </ion-avatar>
        <h2>{{item[0].name}}</h2>
      </ion-item>
      <ion-item-options side="end">
          <ion-item-option (click)="showSureAlert(i, slidingItem)">
            <ion-button class="slideButton" >
              <ion-icon name="trash"></ion-icon>
            </ion-button>
          </ion-item-option>
        </ion-item-options>
      </ion-item-sliding>
    </ion-list>
</div>
async showSureAlert(index, item) {
    console.log('clicked');
    const text: any = [];
    const alert = await this.alertCtrl.create({
      header: text.header = this.translateService.instant('delete'),
      message: text.message = this.translateService.instant('Warning.deleteHorse') + ' ' + this.horses[index][0].name + '?',
      buttons: [
        {
          text: text.next = this.translateService.instant('no'),
          handler: () => {

          }
        },
        {
          text: text.next = this.translateService.instant('yes'),
          handler: () => {
            // delete horsename
            this.deleteHorse(index);
          }
        }
      ],
      backdropDismiss: false
    });
    console.log('alert created');
    await alert.present();
    item.close();
  }


The console.log() is also affected by this peculiar behavior.

I am really keen on utilizing this feature, but if a solution cannot be found, I will need to explore alternative options... Thank you in advance for your assistance.

edit

I tried replicating the code from IonicFramework, and surprisingly, encountered the same outcome.

Following the provided example, I made slight adjustments to my code. Moving the position of the item-options (from end to start) did improve the situation slightly (now requiring only 70% of the time to be clicked twice).

Feel free to check out the example on GitHub here

Answer №1

After some experimentation, I've made a slight improvement to the functionality, though it still lacks reliability. Initially, the button worked seamlessly with just one click for the first few interactions, but then required two clicks thereafter.

In addition to its inconsistent performance, the visual aesthetics leave much to be desired :D

The issue seems to stem from the buttons within an ion-item option. Originally, the code looked like this:

<ion-item-options side="end">
          <ion-item-option (click)="showSureAlert(i, slidingItem)">
            <ion-button class="slideButton" >
              <ion-icon name="trash"></ion-icon>
            </ion-button>
          </ion-item-option>
        </ion-item-options>

Now, I have simplified it to:

<ion-item-options side="end">
          <ion-item-option (click)="showSureAlert(i, slidingItem)">
              <ion-icon name="trash"></ion-icon>
          </ion-item-option>
        </ion-item-options>

While there is no definitive solution yet, this modification represents progress...

edit: Initially, when using Ionic 4, there was a peculiar issue related to ShadowDOM where I had to encapsulate my entire CSS file within "host { }" for it to function properly. Removing this workaround has surprisingly resolved the issue. Funny how little things can make such a difference.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to constrain generic indexed access parameters?

Consider the following scenario: type Group = | { type: "string"; payload: string; } | { type: "number"; payload: number; }; A function can be created as shown below: const groupFunction = <T exte ...

What is the best way to fetch the id of the option that has been chosen from a bootstrap drop-down menu?

I recently created a basic drop-down list like this: https://i.sstatic.net/4Tlxx.png Here is the HTML code for it: <select class="form-control" id='0' (change)="retrieveValue($event.target)"> <option id='0'>{{ g ...

Exploring Typescript: Uncovering the Secrets of the navigator.connection Property

I am trying to access the NetworkInformation interface by using a simple TypeScript function like the one shown below: private checkNetworkConnection(): void { const connection = Navigator.connection || navigator.mozConnection || navigator.webkitConn ...

Angular and ngrx are experiencing an issue involving an infinite loop within a selector

Is it possible to dispatch an action within a selector in a single store? this.store$.pipe(select(selectPersonByName, {personSelectorProps: this.id[]0})) .subscribe(history => { this.store$.dispatch(selectAssignWorkHisto ...

What methods can be used to avoid getting distracted by input?

Is there a way to prevent the input field in angular-material2 from gaining focus when clicking on a visibility button? To see an example of how it works, visit: material.angular.io Image before pressing the button: https://i.stack.imgur.com/5SmKv.png ...

The Angular overlay is concealed beneath the pinned header

I am seeking a solution to have a mat-spinner displayed on top of my app while it is in the loading state. Currently, I am using an overlay component with Overlay from @angular/cdk/overlay. The issue arises when part of the spinner that should be overlai ...

Requesting for a template literal in TypeScript:

Having some trouble with my typescript code, it is giving me an error message regarding string concatenation, const content = senderDisplay + ', '+ moment(timestamp).format('YY/MM/DD')+' at ' + moment(timestamp).format(&apo ...

Communication between Angular components

My question is exactly as the title suggests. Let me explain what I need to do. Currently, I have a component widget. Whenever I click on this widget, a modal pops up with several items inside. Each item corresponds to a different section within the main ...

Storing checkbox status in Angular 7 with local storage

I am looking for a way to keep checkboxes checked even after the page is refreshed. My current approach involves storing the checked values in local storage, but I am unsure of how to maintain the checkbox status in angular 7 .html <div *ngFor="let i ...

Storing the data retrieved from an HTTP GET request in Ionic 2

I've been working on developing an app and have successfully set up an event provider. Utilizing the Eventbrite API, I am able to retrieve a list of events taking place in a specific city. However, I'm facing challenges when attempting to execute ...

What is the solution for resolving array items in a GraphQL query?

I am facing an issue with my graphql Query, specifically in trying to retrieve all the fields of a Post. { getSpaceByName(spaceName: "Anime") { spaceId spaceName spaceAvatarUrl spaceDescription followin ...

Enforcement of Class Initialization in Typescript 2.7

After initializing a sample project using the Angular template in Visual Studio 2017, I made sure to update the package.json file with the latest module versions. However, upon executing the npm install command and navigating to the site, an error related ...

Utilize an array of JSON objects to populate an array of interfaces in Angular/Typescript

I am currently facing a dilemma - my code is functioning without any errors when executed, but my text editor is flagging an issue stating that the property 'categories' does not exist on type 'CategoryInterface[]' (specifically on the ...

In an array where the first 3 images have been filtered using an if statement, how can I show the image at the 3rd index (4th image) starting from the beginning?

In my personal web development project, I'm using AngularJS for the front-end and .NET Core for the back-end to create a website for a musical instrument retailer. The model I'm working with is called "Guitar" and all the guitar data is stored in ...

When there is data present in tsconfig.json, Visual Studio Code does not display errors inline for TypeScript

After creating an empty .tsconfig file (consisting solely of "{ }"), Visual Studio Code immediately displays errors both inline and in the "problems" section. Interestingly, when I populate the tsconfig.json file with data, these errors disappear. Is there ...

Best Method for Confirming Deletion in Data Table with Shadow and UI

I have a query regarding the Shadcn/UI - Data Table component. In my case, I am working with a list of users where each row has a delete button in the last column. Upon clicking the delete button, a confirmation dialog pops up. Currently, I am implementi ...

Setting a timer in NGRX to control the interval between two actions

I am currently working with Angular and NGRX, and I have a requirement to implement a timer between two actions. The timer should start when the first action is triggered and stop when the second action occurs. I need to be able to store this timer in a gl ...

Using a dictionary of objects as the type for useState() in TypeScript and React functional components

I am in the process of transitioning from using classes to function components. If I already have an interface called datasets defined and want to create a state variable for it datasets: {[fieldName: string]: Dataset}; Example: {"a": dataset ...

Achieving dynamic text alignment within a Grid tile container using HTML and Angular

Here is the main section of my parent component. <div class="o-tile-container "> <div *ngFor="let country of Countrys"> <app-country [na ...

Testing an Angular Service method that involves a window.location.replace operation

I'm currently working on an Angular 4 application and I am facing a challenge with testing a method of a Service. This method calls a private method within the same service that includes the following line of code: window.location.replace(url); Howe ...