feat: allow children region to opt out of the default slot#118
Closed
amanabiy wants to merge 1 commit into
Closed
Conversation
The documenter marks any `children` region as the default slot
(`isDefault: true`). Consumers such as the components website use that
flag to render a "(default)" label and a generic "Default slot: Specify
the content as a child of the component." note in the API docs.
For some components that annotation is misleading: `children` may be one
of several supported ways to provide content rather than the single
canonical default slot. Until now there was no way to express that, since
`isDefault` was hardcoded to `region.name === 'children'`.
This adds an `@isChildrenDefault` JSDoc tag on a region so a component can
opt its `children` slot out of the default-slot treatment, while keeping
the existing behavior for everyone who does not use the tag.
Behavior:
- `children`, no tag -> isDefault: true (unchanged)
- `children` + @isChildrenDefault false -> isDefault: false
- any non-`children` region -> isDefault: false (unchanged)
Usage:
export interface TopNavigationProps {
/**
* Specifies custom navigation content.
* @DisplayName content
* @isChildrenDefault false
*/
children?: React.ReactNode;
}
Adds the `is-children-default-tag` fixture and a test covering the opt-out case.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #118 +/- ##
=======================================
Coverage 95.11% 95.12%
=======================================
Files 11 11
Lines 512 513 +1
Branches 139 140 +1
=======================================
+ Hits 487 488 +1
Misses 25 25 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The documenter marks any
childrenregion as the default slot (isDefault: true). Consumers such as the components website use that flag to render a "(default)" label and a generic "Default slot: Specify the content as a child of the component." note in the API docs.For some components, such as top navigation, that annotation is misleading:
childrenmay be one of several supported ways to provide content rather than the single canonical default slot. Until now there was no way to express that, sinceisDefaultwas hardcoded toregion.name === 'children'.This adds an
@isChildrenDefaultJSDoc tag on a region so a component can opt itschildrenslot out of the default-slot treatment, while keeping the existing behavior for everyone who does not use the tag.Behavior:
children, no tag -> isDefault: true (unchanged)children+ @isChildrenDefault false -> isDefault: falsechildrenregion -> isDefault: false (unchanged)Usage:
Adds the
is-children-default-tagfixture and a test covering the opt-out case.Issue #, if available: 1qZFXQh4o49s (pippin)
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.