Compound components: throw when subcomponents are not children of their top-level component #66530
Open
2 of 9 tasks
Labels
[Package] Components
/packages/components
[Type] Code Quality
Issues or PRs that relate to code quality
Compound components enable greater flexibility and modularity, at the cost of a slightly added complexity for the consumer.
One of the most frequent mistakes that we witness is when consumers render a subcomponent outside of its compound component's "context" — for example, rendering a
Composite.Item
without nesting it under aComposite
item.While we want to help consumers in several ways, including proving better documentation and examples, one (complementary) approach is to have compound components throw when they are not rendered inside the relative top-level component.
We should, therefore, implement this standard behaviour across all compound components in the
@wordpress/components
library:BaseControl
Composite
CustomSelectControl
(internal implementation)ItemGroup
Menu
SlotFill
Tabs
ToggleGroupControl
Toolbar
The text was updated successfully, but these errors were encountered: