question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Programmatically slide an ion-item-sliding

See original GitHub issue

Short description of the problem:

I would like to have a way to slide an item to open programmatically. It is not always intuitive to users the slide movement, but a button with an action that animates the slide could help to show how. To enable that, a public version of something like fireSwipeEventwould would help.

What behavior are you expecting?

I would like to have a method like slide() or open() that animate the ion-item-sliding to reveal the ion-item-options of that item.

Which Ionic Version? 2.x

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:15
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
adamdurencommented, Mar 4, 2018

For anyone looking to do this I found a way that is working quite well for me. It is behaving the same as the default drag method. Code is below. The HTML has extraneous markup but this has allowed me to put a more icon at the end of each item which is the click handler to programmatically open the item.

    <ion-item-sliding #slidingItem (tap)="slidingItem.close()">
        <ion-item>
          <ion-row>
            <ion-col col-auto>
              {{ item.date | date:'shortTime' }}
            </ion-col>
            <ion-col>
              {{ item.description }}
            </ion-col>
            <ion-col text-right>
              <button ion-button clear large (click)="openSlidingItem($event, slidingItem)">
                <ion-icon name="more"></ion-icon>
              </button>
            </ion-col>
          </ion-row>
        </ion-item>
        <ion-item-options>
          <button ion-button expandable type="button">
            Undo
          </button>
        </ion-item-options>
      </ion-item-sliding>
import { Component, ViewChildren, QueryList } from '@angular/core';
import { IonicPage, ItemSliding } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-my-page',
  templateUrl: 'my-page.html',
})
export class MyPage {
  @ViewChildren(ItemSliding) private slidingItems: QueryList<ItemSliding>;

  public openSlidingItem($event: Event, item: any) {
    // This is to prevent a call to itemSliding.close() in the template
    $event.stopPropagation();

    // Close all other open items to have behavior similar to the drag method
    this.closeAllItems();

    // In order for the width of the buttons to be calculated the item
    // must be slightly opened
    item._setOpenAmount(1);

    setTimeout(() => {
      const children = Array.from(
        // use _leftOptions if buttons are on the left (could be made to be dynamic)
        item._rightOptions._elementRef.nativeElement.children,
      );
      // Calculate the width of all of the buttons
      const width = children.reduce(
        (acc: number, child: HTMLElement) => acc + child.offsetWidth,
        0,
      );

      // Open to the calculated width
      item.moveSliding(width);
      item._setOpenAmount(width, false);
    }, 0);
  }

  private closeAllItems() {
    this.slidingItems.map(item => item.close());
  }
}

2reactions
ehorodyskicommented, Feb 5, 2018

This is a pretty common UX scenario. Often times users will not know what is a slide-able item and it helps to animate the process the first time the user interacts with the view.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature Request] Programmatically slide an ion-item-sliding
I would like to have a way to slide an item to open programmatically. It is not always intuitive to users the slide...
Read more >
Click to slide open ion-item-sliding instead of swiping - ionic-v3
It looks like, when the slide options are opened, you are not clicking on the ion-item anymore. You are clicking ion-item-options . So...
Read more >
How to programatically open the ion-option-buttons on ion-items
I want to programmatically (e.g click of a button), open up the option menu on all the items. Same effect as if the...
Read more >
Create a Sliding Item Animation with a Directive in Ionic 2 & 3
We use the active-slide and active-options-right classes to make the options behind the sliding item visible, and then (after 2 seconds) we ...
Read more >
Building a slideshow with Ionic Slides API - Mastering Ionic
We then set up some button related properties which we'll use to manage navigation for the Ion Slides component; Our slideConfig object simply ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found