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.

bug: disabling and sorting not working well with nested ion-reorder-group

See original GitHub issue

Bug Report

Ionic version:

[ ] 4.x [x] 5.x

Current behavior:

Nested ion-reorder-group is not working. I have a list of cards and in the list of cards I have a list of items. Now the user has the option to reorder the cards and the elements.

Naturally I created two reorder groups. One in the for the cards and one inside for the items.

However there now are a few problems:

  1. Reorder elements from the item gets added to the cards reorder group. SO the cards reorder group gets triggered by the items
  2. Disabled cards reorder group still gets its event triggered by the items (items reorder group is enabled)
  3. Disabling item reorder group does not work when cards reorder group is enabled

Expected behavior:

Correctly add the ion-reorder elements only to its closest parent ion-reorder-group

Steps to reproduce:

Related code:

https://stackblitz.com/edit/ionic-5-angular-10-start-template-5jby2n?file=src%2Fapp%2Ftab1%2Ftab1.page.ts

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
digauscommented, Mar 5, 2021

@liamdebeasi

I think the issue lies in this method (at least for the event):

https://github.com/ionic-team/ionic-framework/blob/de58238333d55334621445cdba4b67b8ba4958a1/core/src/components/reorder-group/reorder-group.tsx#L316

We should stop the while when we find a reorder-group which is not this reorder group. This should do the trick:

const findReorderItem = (node: HTMLElement | null, container: HTMLElement): HTMLElement | undefined => {
  let parent: HTMLElement | null;
  while (node) {
    parent = node.parentElement;
    if (parent === container) {
      return node;
    } else if (parent.tagName === 'ION-REORDER-GROUP' ) {
      return undefined;
    }
    node = parent;
  }
  return undefined;
};

Regarding the disabled state. I guess this is a matter of setting correct css attributes. Just need to add this to the ion-reorder css

.reorder-enabled ion-reorder-group:not(.reorder-enabled) ion-reorder {
  display: none;
}

See: https://stackblitz.com/edit/ionic-5-angular-10-start-template-woqd8q?file=src%2Fapp%2Ftab1%2Ftab1.page.scss

1reaction
digauscommented, Mar 5, 2021

@liamdebeasi Yes this kinda works. However, the showcase here is pretty simplified.

In my use case I sort the list by a sort property. This means when the user reorders the elements I update this field after he reordered.

Now since the parent reorder event is also called by the childs reordering my parent sort order is also updated.

I can “fix” this by checking the target element of the reorder event (added an id to the reorder-group) and only call my logic when the ids match.

The problem which still persist is that I cannot just disable the child ion-reorder-group. Since the parent ion-reorder-group is still enabled the ion-reorder handles do not get hidden (as seen in the stackblitz example).

This could also be “fixed” by me with an *ngIf.

Nevertheless I still think this is a bug. ion-reorder elements should only belong to its closest parent ion-reorder-group

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ionic4 - Nested reorder groups problem - Ionic Framework
The nested reorder list shall work correctly, after its 1st level reorder object is reordered. My clunky workaround. By trial and error, I ......
Read more >
ionic5 issue Click is not working inside ion-recoder list
It only works for me if I set disabled="true" . It seems like the ion-reorder-group stops propagation to do the reordering. – HasBert....
Read more >
bug: ion-reorder prevents click event when ion ... - GitHub
Ionic version: [x] 5.x ; Current behavior: If ion-reorder-group is disabled, all elements affected by ion-reorder that also have a click event ...
Read more >
The Dangers of Stopping Event Propagation - CSS-Tricks
This bug happens because the Bootstrap code responsible for closing the dropdown menu is listening for click events on the document. But since ......
Read more >
Flattening nested arrays - Amazon Athena
To flatten a nested array's elements into a single array of values, use the flatten function. This query returns a row for each...
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