Skip to content

Commit 0dc70f7

Browse files
committed
fix(tap-click): works inside shadow-dom
adds private ion-activable attribute fixes #15128
1 parent 270ece0 commit 0dc70f7

File tree

10 files changed

+28
-21
lines changed

10 files changed

+28
-21
lines changed

core/src/components/action-sheet/action-sheet.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Component, Element, Event, EventEmitter, Listen, Method, Prop } from '@stencil/core';
22

3-
import { ActionSheetButton, Animation, AnimationBuilder, Color, Config, CssClassMap, Mode, OverlayEventDetail, OverlayInterface } from '../../interface';
3+
import { ActionSheetButton, Animation, AnimationBuilder, Config, CssClassMap, Mode, OverlayEventDetail, OverlayInterface } from '../../interface';
44
import { BACKDROP, dismiss, eventMethod, isCancel, present } from '../../utils/overlays';
5-
import { createColorClasses, getClassMap } from '../../utils/theme';
5+
import { getClassMap } from '../../utils/theme';
66

77
import { iosEnterAnimation } from './animations/ios.enter';
88
import { iosLeaveAnimation } from './animations/ios.leave';
@@ -20,7 +20,6 @@ import { mdLeaveAnimation } from './animations/md.leave';
2020
export class ActionSheet implements OverlayInterface {
2121

2222
mode!: Mode;
23-
color?: Color;
2423

2524
presented = false;
2625
animation?: Animation;
@@ -208,7 +207,6 @@ export class ActionSheet implements OverlayInterface {
208207
zIndex: 20000 + this.overlayId,
209208
},
210209
class: {
211-
...createColorClasses(this.color),
212210
...getClassMap(this.cssClass),
213211
'action-sheet-translucent': this.translucent
214212
}
@@ -237,7 +235,7 @@ export class ActionSheet implements OverlayInterface {
237235
</div>
238236
}
239237
{buttons.map(b =>
240-
<button type="button" class={buttonClass(b)} onClick={() => this.buttonClick(b)}>
238+
<button type="button" ion-activable class={buttonClass(b)} onClick={() => this.buttonClick(b)}>
241239
<span class="action-sheet-button-inner">
242240
{b.icon && <ion-icon icon={b.icon} lazy={false} class="action-sheet-icon" />}
243241
{b.text}
@@ -249,6 +247,7 @@ export class ActionSheet implements OverlayInterface {
249247
{cancelButton &&
250248
<div class="action-sheet-group action-sheet-group-cancel">
251249
<button
250+
ion-activable
252251
type="button"
253252
class={buttonClass(cancelButton)}
254253
onClick={() => this.buttonClick(cancelButton)}

core/src/components/alert/alert.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Component, Element, Event, EventEmitter, Listen, Method, Prop, Watch } from '@stencil/core';
22

3-
import { AlertButton, AlertInput, Animation, AnimationBuilder, Color, Config, CssClassMap, Mode, OverlayEventDetail, OverlayInterface } from '../../interface';
3+
import { AlertButton, AlertInput, Animation, AnimationBuilder, Config, CssClassMap, Mode, OverlayEventDetail, OverlayInterface } from '../../interface';
44
import { BACKDROP, dismiss, eventMethod, isCancel, present } from '../../utils/overlays';
5-
import { createColorClasses, getClassMap } from '../../utils/theme';
5+
import { getClassMap } from '../../utils/theme';
66

77
import { iosEnterAnimation } from './animations/ios.enter';
88
import { iosLeaveAnimation } from './animations/ios.leave';
@@ -27,7 +27,6 @@ export class Alert implements OverlayInterface {
2727
presented = false;
2828
animation?: Animation;
2929

30-
color!: Color;
3130
@Prop() mode!: Mode;
3231

3332
@Element() el!: HTMLStencilElement;
@@ -399,7 +398,6 @@ export class Alert implements OverlayInterface {
399398
zIndex: 20000 + this.overlayId,
400399
},
401400
class: {
402-
...createColorClasses(this.color),
403401
...getClassMap(this.cssClass),
404402
'alert-translucent': this.translucent
405403
}
@@ -415,7 +413,7 @@ export class Alert implements OverlayInterface {
415413
return (
416414
<div class={alertButtonGroupClass}>
417415
{buttons.map(button =>
418-
<button type="button" class={buttonClass(button)} tabIndex={0} onClick={() => this.buttonClick(button)}>
416+
<button type="button" ion-activable class={buttonClass(button)} tabIndex={0} onClick={() => this.buttonClick(button)}>
419417
<span class="alert-button-inner">
420418
{button.text}
421419
</span>

core/src/components/back-button/back-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class BackButton {
6767
'button': true,
6868
'show-back-button': showBackButton
6969
},
70-
'tappable': true,
70+
'ion-activable': true,
7171
};
7272
}
7373

core/src/components/button/button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class Button {
157157
...getColorClassMap(buttonType, color, fill, mode),
158158
'focused': this.keyFocus,
159159
},
160-
'tappable': true,
160+
'ion-activable': true,
161161
};
162162
}
163163

core/src/components/fab-button/fab-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class FabButton {
7777
hostData() {
7878

7979
return {
80-
'tappable': !this.disabled,
80+
'ion-activable': !this.disabled,
8181
class: {
8282
...createColorClasses(this.color),
8383
...this.getFabClassMap(),

core/src/components/item/item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class Item {
126126
});
127127

128128
return {
129-
'tappable': this.isClickable(),
129+
'ion-activable': this.isClickable(),
130130
class: {
131131
...childStyles,
132132
...createColorClasses(this.color),

core/src/components/segment-button/segment-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class SegmentButton {
6262
'segment-button-disabled': disabled,
6363
'segment-checked': checked,
6464
},
65-
'tappable': true,
65+
'ion-activable': true,
6666
};
6767
}
6868

core/src/components/toast/toast.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, Element, Event, EventEmitter, Listen, Method, Prop } from '@stencil/core';
22

3-
import { Animation, AnimationBuilder, Color, Config, Mode, OverlayEventDetail, OverlayInterface } from '../../interface';
3+
import { Animation, AnimationBuilder, Config, Mode, OverlayEventDetail, OverlayInterface } from '../../interface';
44
import { dismiss, eventMethod, present } from '../../utils/overlays';
55
import { createThemedClasses, getClassMap } from '../../utils/theme';
66

@@ -25,7 +25,6 @@ export class Toast implements OverlayInterface {
2525
@Element() el!: HTMLElement;
2626

2727
mode!: Mode;
28-
color?: Color;
2928
animation: Animation | undefined;
3029

3130
@Prop({ connect: 'ion-animation-controller' }) animationCtrl!: HTMLIonAnimationControllerElement;
@@ -203,7 +202,7 @@ export class Toast implements OverlayInterface {
203202
? <div class="toast-message">{this.message}</div>
204203
: null}
205204
{this.showCloseButton
206-
? <ion-button fill="clear" color="light" class="toast-button" onClick={() => this.dismiss()}>
205+
? <ion-button fill="clear" color="light" ion-activable class="toast-button" onClick={() => this.dismiss()}>
207206
{this.closeButtonText || 'Close'}
208207
</ion-button>
209208
: null}

core/src/interface.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ declare global {
5353
// for ion-menu and ion-split-pane
5454
main?: boolean;
5555
tappable?: boolean;
56+
'ion-activable'?: boolean;
5657

5758
padding?: boolean;
5859
['padding-top']?: boolean;

core/src/utils/tap-click.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function startTapClick(doc: Document) {
5757
return;
5858
}
5959
cancelled = false;
60-
setActivatedElement(getActivatableTarget(ev.target), ev);
60+
setActivatedElement(getActivatableTarget(ev), ev);
6161
}
6262

6363
function pointerUp(ev: UIEvent) {
@@ -145,8 +145,18 @@ export function startTapClick(doc: Document) {
145145
doc.addEventListener('mouseup', onMouseUp, true);
146146
}
147147

148-
function getActivatableTarget(el: HTMLElement): any {
149-
return el.closest(':not([tappable]) > a, :not([tappable]) > button, [tappable]');
148+
function getActivatableTarget(ev: any): any {
149+
if (ev.composedPath) {
150+
const path = ev.composedPath() as HTMLElement[];
151+
for (let i = path.length - 3; i >= 0; i--) {
152+
const el = path[i];
153+
if (el.hasAttribute && el.hasAttribute('ion-activable')) {
154+
return el;
155+
}
156+
}
157+
} else {
158+
return ev.target.closest('[ion-activable]');
159+
}
150160
}
151161

152162
const ACTIVATED = 'activated';

0 commit comments

Comments
 (0)