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

fix(framework): component children that are slots now invalidate parent upon slotchange #1649

Merged
merged 2 commits into from
May 20, 2020

Conversation

vladitasev
Copy link
Contributor

@vladitasev vladitasev commented May 19, 2020

There are composition scenarios where a component, say ui5-upload-collection creates a ui5-list in its shadow root and slots all its children to the list transitively by just rendering a slot in the list.

Example:

<ui5-list
	mode="{{mode}}"
	@ui5-selectionChange="{{_onSelectionChange}}"
	@ui5-itemDelete="{{_onItemDelete}}"
>
	<slot></slot>
</ui5-list>

The problem with this is that the framework will only invalidate the ui5-list whenever its children are added/removed, but in this case the only child is the slot and it is completely static. Yet, when the user adds items to the ui5-upload-collection, they will be rendered transitively by the list, but the list will not be updated. Therefore some of the children may not be displayed properly.

The reported issue is that when you add items to the upload collection in "Delete" mode, the new items don't get a "Delete" button until the list is invalidated by something else.

Therefore, this change adds some extra capabilities for components with managedSlots: true. If they have <slot> children, these will have slotchange attached/detached automatically by the framework, and the parent component, in this example ui5-list will be invalidated whenever the slotchange event is fired, which is upon adding/removing elements to the slot.

In the future, this may be easily enhanced to work recursively by doing the same for slots inside slots, but for the time being this might not be necessary.

Additionally, a new isSlot utility is added to check if a Node is slot.
Additionally, ui5-input was changed to use the getSlottedNodes function, already provided by UI5Element.js instead of re-implementing it, to easily get the list of all slotted children in the valueStateMessage slot.

This change will affect several components: ui5-upload-collection, ui5-tree, ui5-datepicker, etc... mostly components that transitively slot content to the input or list.

fixes: #1647

@vladitasev vladitasev merged commit 3ca4ae1 into master May 20, 2020
@vladitasev vladitasev deleted the slotchange-listen branch May 20, 2020 06:45
@ilhan007 ilhan007 added this to 1.0.0-rc.8 (released) in UI5 Web Components - Roadmap Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

upload collection dynamic update issues
2 participants