Skip to content

Commit

Permalink
fix(reorder): allow click event propagation when reorder group is dis…
Browse files Browse the repository at this point in the history
…abled (#21947)

Allow interactive components (e.g `<ion-checkbox>`) inside of an `<ion-reorder>` tag in a disabled `<ion-reorder-group>` to fire click events / have their state changed. 

fixes #21017
  • Loading branch information
archzaiko committed Sep 24, 2020
1 parent ea0e049 commit baafe08
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
18 changes: 18 additions & 0 deletions core/src/components/reorder-group/test/basic/index.html
Expand Up @@ -115,6 +115,24 @@
</ion-item>
</ion-reorder>

<ion-reorder>
<ion-item>
<ion-label>
Item 11 (the whole item can be dragged)
</ion-label>
<ion-toggle></ion-toggle>
</ion-item>
</ion-reorder>

<ion-reorder>
<ion-item>
<ion-label>
Item 12 (the whole item can be dragged)
</ion-label>
<ion-checkbox></ion-checkbox>
</ion-item>
</ion-reorder>

</ion-reorder-group>
</ion-list>
</ion-content>
Expand Down
12 changes: 10 additions & 2 deletions core/src/components/reorder/reorder.tsx
@@ -1,4 +1,4 @@
import { Component, ComponentInterface, Host, Listen, h } from '@stencil/core';
import { Component, ComponentInterface, Element, Host, Listen, h } from '@stencil/core';

import { getIonMode } from '../../global/ionic-global';

Expand All @@ -14,11 +14,19 @@ import { getIonMode } from '../../global/ionic-global';
shadow: true
})
export class Reorder implements ComponentInterface {
@Element() el!: HTMLIonReorderElement;

@Listen('click', { capture: true })
onClick(ev: Event) {
const reorderGroup = this.el.closest('ion-reorder-group');

ev.preventDefault();
ev.stopImmediatePropagation();

// Only stop event propagation if the reorder is inside of an enabled
// reorder group. This allows interaction with clickable children components.
if (!reorderGroup || !reorderGroup.disabled) {
ev.stopImmediatePropagation();
}
}

render() {
Expand Down

0 comments on commit baafe08

Please sign in to comment.