--- name: canvas-slots-for-repeatable-content description: Model repeatable Canvas content with slot-based parent/child component patterns. Use when (1) Building lists/grids of items, (2) Converting array props to slots (Canvas doesn't support array props with objects), (3) Troubleshooting empty slots in Canvas editor. Covers parent/child repeatable item patterns. --- Slots enable components to accept and render child components in designated areas. In this skill, focus on repeatable content patterns (lists, cards, item collections), especially because Canvas does not support array props with complex objects. For broader slot architecture and decomposition guidance, see `canvas-component-composability`. ## Canvas limitation: no array props with objects Canvas will reject components that define array props with nested object items: ```yaml # This will fail to upload props: properties: items: title: Items type: array items: type: object properties: title: type: string description: type: string linkUrl: type: string ``` The upload fails with: > Drupal Canvas does not know of a field type/widget to allow populating the > items prop, with the shape {...}. [props.items.items] 'items' is not a > supported key. [props.items.type] The value you selected is not a valid > choice. **Simple arrays of primitives ARE supported:** ```yaml # OK: Array of simple strings props: properties: tags: title: Tags type: array items: type: string examples: - - tag1 - tag2 ``` ## The pattern: slots + child components Instead of array props, create a separate child component for the repeating item and use a slot in the parent component. ### Step 1: Create the child component Extract the item structure into its own component: ```yaml # src/components/feature-card/component.yml name: Feature Card machineName: feature-card status: true required: - title props: properties: title: title: Title type: string examples: - Feature One description: title: Description type: string examples: - A brief description of this feature and its benefits. linkText: title: Link Text type: string examples: - Learn more linkUrl: title: Link URL type: string format: uri-reference examples: - /features/feature-one slots: [] ``` ### Step 2: Update the parent component to use a slot Replace the array prop with a slot: Follow the `canvas-component-metadata` slot schema: use an object map for defined slots, and use `slots: []` only when the component has no slots. ```yaml # src/components/features-section/component.yml name: Features Section machineName: features-section status: true required: - heading props: properties: heading: title: Heading type: string examples: - Our Features slots: features: title: Features ``` ### Step 3: Update the JSX to render the slot In the parent component's JSX, render the slot as children: ```jsx // src/components/features-section/index.jsx const FeaturesSection = ({ heading, features, className }) => { return (