[POC] Configure setting ownerState on slots #35655
Closed
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.
DO NOT MERGE
This is a playground that illustrates an alternative way of accessing
ownerState
in slot components.A SwitchUnstyled is used for this example.
Related issue: #32882
This is one of the possible solutions. The other one is described in #35654.
A new prop was added to SwitchUnstyled -
provideOwnerStateToSlots
. It controls whetherownerState
is passed as a prop to slot components. Developers can set this prop when they intend to make rendering of a slot dependent on the state of the owner component (as shown in this PR and on the linked codesandbox). The prop would be set tofalse
(or not set) when slot components don't expectownerState
in props. This will be especially useful when using 3rd party components as slots (for example React Router's Link as a root slot of a Button).Advantages over the existing API:
ownerState
from props.Disadvantages:
Playgrounds
New API: https://codesandbox.io/s/recursing-turing-8m5yvj?file=/src/App.tsx
Existing API: https://codesandbox.io/s/confident-hermann-q1kiwf?file=/src/App.tsx