From 5c4838b8136784e82d74aef8b5e6b098cd243ca4 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Wed, 16 Nov 2016 09:10:28 -0600 Subject: [PATCH] feat(tappable): auto add tappable attribute for ion-item clicks --- src/components/item/item.ts | 11 +++++++++++ src/components/nav/test/basic/app-module.ts | 2 +- src/components/tap-click/tap-click.ts | 7 +++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/item/item.ts b/src/components/item/item.ts index cc86c54ce9e..2bb8feeef33 100644 --- a/src/components/item/item.ts +++ b/src/components/item/item.ts @@ -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 (!(renderer).orgListen) { + (renderer).orgListen = renderer.listen; + renderer.listen = function(renderElement: HTMLElement, name: string, callback: Function): Function { + if (name === 'click' && renderElement.setAttribute) { + renderElement.setAttribute('tappable', ''); + } + return (renderer).orgListen(renderElement, name, callback); + }; + } } /** diff --git a/src/components/nav/test/basic/app-module.ts b/src/components/nav/test/basic/app-module.ts index 8e690840f60..5aea111e4ae 100644 --- a/src/components/nav/test/basic/app-module.ts +++ b/src/components/nav/test/basic/app-module.ts @@ -53,7 +53,7 @@ export class MyCmpTest { {{title}} - + Push to FullPage diff --git a/src/components/tap-click/tap-click.ts b/src/components/tap-click/tap-click.ts index a73af6f0abd..e9cdf6b6f06 100644 --- a/src/components/tap-click/tap-click.ts +++ b/src/components/tap-click/tap-click.ts @@ -160,9 +160,8 @@ 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; } } @@ -170,7 +169,7 @@ export const isActivatable = function (ele: HTMLElement) { }; 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;