Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breadcrumb not updated when children are deleted #242

Open
3 of 8 tasks
jtruffot opened this issue Jun 16, 2023 · 0 comments
Open
3 of 8 tasks

Breadcrumb not updated when children are deleted #242

jtruffot opened this issue Jun 16, 2023 · 0 comments

Comments

@jtruffot
Copy link

Describe the bug

When the navigation items are replaced by a subset of the previous items, the breadcrumb trail is not updated. The deleted items have disappeared but not the separators.

How to reproduce

Steps to reproduce the behavior:

  1. Go to this StackBlitz example.
  2. Click on 'Home'. The parent and child pages disappear but the separators remain visible.
  3. Click on "Reset" and activate the workaround. Click on "Home" again. Now the separators also disappear.

Explanation

The breadcrumb wants to display its child items in a list structure (ol/li). It does this by using the generic slot element to react to changes. Then, it adds a slot attribute to each element to insert it into the list via named slot elements.
In doing so, the items come out of the generic slot to be projected into the named slots of the list. The slotchange event is triggered on the generic slot and the breadcrumb is re-rendered.

When changing items, the elements corresponding to the items already present are not rendered again and retain their slot attribute and therefore their projection in the list. The elements corresponding to the deleted items are removed from the DOM. This does not trigger a slotchange event, neither in the generic slot from which the elements have already been removed following the addition of their slot attribute, nor in the corresponding named slots because only the addition and deletion of the slot attribute are event trigger in this case.

Thus the named slots of the deleted items are indeed empty but remain present in the HTML structure of the list, with the separators which remain visible.

Expected behavior

We need the breadcrumb to be updated after modifying its child items.

Versions

Clarity project:

  • Clarity Core
  • Clarity Angular/UI

Clarity version:

  • v5.x
  • v6.x

Framework:

  • Angular
  • React
  • Vue
  • Other:

Framework version:

Angular v15.
Clarity Core v6.4.3.

Workaround

Part of the problem is that Angular won't update an item if the corresponding data hasn't changed. It's a good idea but we can force it by copying the data (for example a clone of the object). Thus a new element is created by Angular, without the slot attribute. The breadcrumb generic slot's slotchange event is fired, resulting in the component being updated (see the StackBlitz example).

Additional notes

A solution might be to use the MutationObserver interface to properly react to changes in the child list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant