Learn how to override the default DOM structure of MUI Base components.
+Learn how to override the default DOM structure of Base UI components.
-MUI Base components are designed to suit the widest possible range of use cases, but you may occasionally need to change how a component's structure is rendered in the DOM.
+Base UI components are designed to suit the widest possible range of use cases, but you may occasionally need to change how a component's structure is rendered in the DOM.
To understand how to do this, it helps to have an accurate mental model of MUI components.
@@ -13,7 +13,7 @@ Slots are most commonly filled by HTML tags, but may also be filled by React com
All components contain a root slot that defines their primary node in the DOM tree; more complex components also contain additional interior slots named after the elements they represent.
-All _non-utility_ MUI Base components accept two props for overriding their rendered HTML structure:
+All _non-utility_ Base UI components accept two props for overriding their rendered HTML structure:
- `component`—to override the root slot
- `slots`—to override any interior slots (when present) as well as the root
From 56a189fa448ad2a687bbe739aa986476e34b13cd Mon Sep 17 00:00:00 2001
From: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com>
Date: Wed, 5 Apr 2023 13:06:49 -0500
Subject: [PATCH 20/25] ci checks
---
.../OverridingInternalSlot.tsx.preview | 15 +++++++++++++++
.../OverridingRootSlot.tsx.preview | 9 ++++++++-
docs/translations/translations.json | 1 +
3 files changed, 24 insertions(+), 1 deletion(-)
create mode 100644 docs/data/joy/guides/overriding-component-structure/OverridingInternalSlot.tsx.preview
diff --git a/docs/data/joy/guides/overriding-component-structure/OverridingInternalSlot.tsx.preview b/docs/data/joy/guides/overriding-component-structure/OverridingInternalSlot.tsx.preview
new file mode 100644
index 00000000000000..a03695efb5e7d1
--- /dev/null
+++ b/docs/data/joy/guides/overriding-component-structure/OverridingInternalSlot.tsx.preview
@@ -0,0 +1,15 @@
+` by default.
+The code snippet below shows how to override this by assigning a `` to the root slot:
+
+```jsx
+
+```
+
+### component
+
+The `component` prop provides a shortcut to `slots.root`.
+This is useful if you are only overriding the root element of the component.
+
+The code snippet below shows how to override the root element of the Unstyled Badge component using the `component` prop:
+
+```jsx
+
+```
+
+:::warning
+If the root slot is customized with both the `component` and `slots` props, then `component` will take precedence.
+:::
+
+### slotProps
+
+The `slotProps` prop is an object that contains the props for all slots within a component.
+You can use it to define additional custom props for a component's interior elements.
+
+For example, the code snippet below shows how to add a custom CSS class to the badge slot of the Unstyled Badge component:
+
+```jsx
+
+```
+
+All additional props placed on the primary component are also propagated into the root slot (just as if they were placed in `slotProps.root`).
+
+These two examples are equivalent:
+
+```jsx
+
+```
+
+```jsx
+
+```
+
+:::warning
+If both `slotProps.root` and additional props have the same keys but different values, the `slotProps.root` props will take precedence.
+This does not apply to classes or the `style` prop—they will be merged instead.
+:::
+
+### Best practices
+
+If you are customizing a component like the [Unstyled Button](/base/react-button/) that only has a root slot, you may prefer to use the more succinct `component` prop instead of `slots`.
+
+Overriding with `component` lets you apply the attributes of that element directly to the root.
+For instance, if you replace the Unstyled Button root with an `` tag, you can add the `` attribute `value` directly to the component.
+If you did the same with `slots.root`, you would need to place this attribute on the `slotProps.root` object in order to avoid a TypeScript error.
+
## Components vs. hooks
MUI Base includes two kinds of building blocks: **components** and **hooks**.
From 1e9ca3fdb128243c6bbe088b94d714e2d6dafde1 Mon Sep 17 00:00:00 2001
From: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com>
Date: Fri, 7 Apr 2023 09:52:48 -0500
Subject: [PATCH 25/25] Update
docs/data/joy/guides/overriding-component-structure/overriding-component-structure.md
Co-authored-by: Siriwat K
Signed-off-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com>
---
.../overriding-component-structure.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/data/joy/guides/overriding-component-structure/overriding-component-structure.md b/docs/data/joy/guides/overriding-component-structure/overriding-component-structure.md
index 2d5392ea0ed053..072bf91c3c58d0 100644
--- a/docs/data/joy/guides/overriding-component-structure/overriding-component-structure.md
+++ b/docs/data/joy/guides/overriding-component-structure/overriding-component-structure.md
@@ -86,7 +86,7 @@ Use `component` or `slotProps.{slot}.component` prop to override the element by
Use `slots` prop to replace the slot's styles and functionality with your custom component.
Overriding with `component` lets you apply the attributes of that element directly to the root.
-For instance, if you replace the Unstyled Button root with an `` tag, you can add the `` attribute `value` directly to the component.
+For instance, if you override the Button's root with an `` tag, you can add the `` attribute `value` directly to the component.
If you did the same with `slots.root`, you would need to place this attribute on the `slotProps.root` object in order to avoid a TypeScript error.
Be mindful of your rendered DOM structure when overriding the slots of more complex components.