feat(runtime): add slotchange
event and assignedNodes
/ assignedElements
methods for scoped: true
slots
#6151
+453
−134
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the current behavior?
Stencil's polyfilled - 'Pretend slots' - don't act like their native counterparts:
assignedNodes()
/assignedElements()
)slotchange
event)At present, on a
scoped: true
component devs have to resort to clunky mutation observers (for text, comment and element nodes on a default slot), saving node references to internal state to track when they change.This is frustrating as Stencil, internally, knows what is slotted.
Making this knowledge available to users will enable them to remove substantial LOC and mirroring the the native APIs makes swapping between native & proprietary behaviour much simpler.
GitHub Issue Number: #3782
What is the new behavior?
Fixes #3782
assignedNodes
andassignedElements
methods have been added to the mock<slot />
nodes (which in reality is an an empty text node (or a comment node in debug mode) or a<slot-fb />
if there is fallback nodes).Documentation
Does this introduce a breaking change?
No - although, there is a change in behaviour .. Previously when doing something like
<slot ref={s => this.slot} />
... theref
would resolve to a slotted node. I think this behaviour is 1) unintuitive & 2) not documented.Testing
New WDIO tests
Other information