Skip to content

Commit

Permalink
feat(tappable): auto add tappable attribute for ion-item clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Nov 16, 2016
1 parent 12b8157 commit 5c4838b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/components/item/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,17 @@ export class Item extends Ion {
this._setName(elementRef);
this._shouldHaveReorder = !!reorder;
this.id = form.nextId().toString();

// auto add "tappable" attribute to ion-item components that have a click listener
if (!(<any>renderer).orgListen) {
(<any>renderer).orgListen = renderer.listen;
renderer.listen = function(renderElement: HTMLElement, name: string, callback: Function): Function {
if (name === 'click' && renderElement.setAttribute) {
renderElement.setAttribute('tappable', '');
}
return (<any>renderer).orgListen(renderElement, name, callback);
};
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/components/nav/test/basic/app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class MyCmpTest {
<ion-list-header>
{{title}}
</ion-list-header>
<button ion-item class="e2eFrom1To2" (click)="pushFullPage()">Push to FullPage</button>
<ion-item class="e2eFrom1To2" (click)="pushFullPage()">Push to FullPage</ion-item>
<button ion-item (click)="pushPrimaryHeaderPage()">Push to PrimaryHeaderPage</button>
<button ion-item (click)="pushRedirect()">Push to Redirect</button>
<button ion-item (click)="pushTabsPage()">Push to Tabs Page</button>
Expand Down
7 changes: 3 additions & 4 deletions src/components/tap-click/tap-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,16 @@ export const isActivatable = function (ele: HTMLElement) {
return true;
}

let attributes = ele.attributes;
for (let i = 0, l = attributes.length; i < l; i++) {
if (ACTIVATABLE_ATTRIBUTES.indexOf(attributes[i].name) > -1) {
for (let i = 0, l = ACTIVATABLE_ATTRIBUTES.length; i < l; i++) {
if (ele.hasAttribute(ACTIVATABLE_ATTRIBUTES[i])) {
return true;
}
}
return false;
};

const ACTIVATABLE_ELEMENTS = ['A', 'BUTTON'];
const ACTIVATABLE_ATTRIBUTES = ['tappable', 'button'];
const ACTIVATABLE_ATTRIBUTES = ['tappable', 'ion-button'];
const POINTER_TOLERANCE = 60;
const DISABLE_NATIVE_CLICK_AMOUNT = 2500;

Expand Down

4 comments on commit 5c4838b

@jourdan-jobox
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks guys! So if I have a tappable manually added to an before, am I okay to remove them?

@ggnzlpz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in RC3 is no longer possible to have buttons inside items? I cannot get click event in an ion-button inside an ion-item. In RC2 it worked calling $event.stopPropagation() in the button's handler.
Thanks

@jourdan-jobox
Copy link

@jourdan-jobox jourdan-jobox commented on 5c4838b Nov 23, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexandrzavalii
Copy link

@alexandrzavalii alexandrzavalii commented on 5c4838b Nov 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now when I scroll the list of ion-items it actually taps one of them , and triggers a click event.
How I can set ion-item tappable to false ? I dont want to trigger click event of the ion-item when I am just scrolling the list.

Please sign in to comment.