Learn how to work with nested components across design systems in Adobe XD.

Building a design system requires the ability to create components at the molecular levels for optimal reusability and flexibility. When creating components, XD lets you nest them within each other and create complex objects such as menus, card-based layouts, and many more. 

Read on to learn how to create and use nested components for a seamless design experience.

Components

New to XD?

Get XD

Learn app basics

Already on Adobe XD?

Update Your App

Check out What's New

Try it yourself

Get Sample UI kit

.xd; 7 MB

Before you proceed

Be familiar with these concepts:

Create a nested component

Using nested components, you can build more robust design systems. When you update a main component, all its instances receive those updates, even if the update is in its nested component.

To create nested components, you can use any of these approaches:

Approach A: Copy-paste a component instance to a group and convert it to a component.

Approach B
  1. Create a main button component.
  2. Copy-paste an instance of the button component within the group.
  3. Select the group and convert it to a component. 

Approach B: Copy-paste a component inside another component.

Paste an instance of the Button Component inside the group
  1. Create a main button component.
  2. Copy-paste a component instance of the button component within another component.

Approach C: Drill down into a part of a component and convert that into a component.

Approach B
  1. Create a main dialog component.
  2. Drill down to a part of the component.
  3. Convert the button into a component.

Example

Let’s use Approach A to create a dialog component.

Create a button component

Create a button Component

Create the button component for the dialog.

Create the dialog container

Dialog container

Create the dialog container with the text and other objects as a group.

Paste the button instance

Paste the instance

Paste an instance of the button component inside the group.

Convert into a component

Make the Component

Select the group and make it a component.

Best practices

Here are some best practices when creating nested components:

  • You can create a component with multiple component instances nested inside. However, when components have multiple states with many objects, performance can take a hit. In such cases, to achieve optimal performance, you can nest components three levels deep at most, and limit the number of states per level, to a maximum of ten states per component.
  • Do not nest a component within itself. This might result in an invalid component since components are self-referencing.
  • If you have a nested component with multiple states in an outer main component, you can switch the state of the nested component. The state change then propagates to all the outer component’s instances.

Nested components syncing

With nested components syncing, changes made to components nested within a main component propagate to all the instances of that main component. 

Let's see how that works. 

Example 1: A button inside a container that receives changes from the main button.

Paste an instance of the Button Component inside the group
  1. Create a button as the first main component.
  2. Nest the button inside a toggle menu.
  3. Nest the toggle menu inside a container.

Any changes made to the main button component propagate to all the buttons nested inside the toggle menu and the container.

Now, create two instances of the main button, two instances of the main toggle menu, and an instance of the main container.

Let's look at some scenarios:

Scenario 1:

Scenario 1

Change the color of the button nested inside the main toggle menu to blue. 

All the buttons nested inside the toggle menu's instances and inside the containers got the color change to blue.

However, the two instances of the main button don't change color. This is because changes to nested components are contextual to their containers. The color change only applies to instances of the button inside the toggle menu. 

Scenario 2:

Scenario 2

Change the color of the button inside the main container to pink. The button inside the container's instance will also turn pink.

Notice that the other buttons don't get the color change. This is because changes to nested components are contextual to their containers. The color change only applies to instances of the button inside the toggle menu within the container. 

Scenario 3:

Scenario 3

Change the color of the button nested inside the container instance to green.

None of the other buttons get the green color change because this change was made on an instance, not a main component, as an override. 

Scenario 4:

Scenario 4

Continuing from scenario 3, change the color of the button nested inside the main container to violet. 

The container instance's nested button does not change color because it already has an override.

Things to watch out for

  • Nested components cannot be main components. So, if you need the change to be on the main component, right-click the nested component and select Edit Main Component
  • If a nested component in an instance of the outer component is swapped, Reset to Main State on the main's nested component will not change the instance with the swapped component. 

Best practices

Here are some best practices when working with overrides in nested component instances:

  • To create a variation of the component for reuse, create a state in the main component rather than an instance with overrides.
  • While overriding instances, ensure that you override the property that does not need updates from the main component. For example, in a button component, overriding the text ensures that the label can be different, but the size and color are still in sync with the main component.

Libraries help you distribute your design system styles and components to be reused consistently across your documents. To build and distribute a design system through libraries, curate your design system assets by adding colors, character styles, and components to the Document Assets panel, and publish them as a library to reuse across all your XD and other Creative Cloud applications. For more information on how to use Creative Cloud Libraries, see Work with Creative Cloud Libraries in XD.

Work with nested components created in earlier versions of XD

In the previous versions of XD, changes made in a nested component do not update across instances of the outer component. To get an improved experience, open your documents in the latest version of XD.

No. When you open an existing document with nested components in the latest version of XD, XD will automatically migrate those components to the new model to get you going as quickly as possible.

When XD opened your document, these specific components did not match their version in the Assets panel. To migrate without data loss, these main components have been converted to instances on canvas. If you want to bring your main component back to the canvas, right-click the outer instance and select Edit Main Component. Then, if you want your main component to look like the instance on canvas, you can transfer any necessary overrides from your instance to the main component. 

To get updates, open the linked documents in the latest version of XD. Any documents linked in the future should also be opened in the latest version of XD to ensure correct behavior. 

Starting with XD 34, XD no longer supports nesting a main component inside another main component. If you do something that would have previously created a nested main component, the inner component is changed to an instance. 

What's next?

We've got you started on how to work with components in XD. Take a step forward and learn how to share your designs with designers or stakeholders for feedback.

Have a question or an idea?

ask the community

Have a question to ask or an idea to share? Come and participate in Adobe XD Community. We would love to hear from you and see your creations!