diff --git a/.changeset/good-books-move.md b/.changeset/good-books-move.md new file mode 100644 index 0000000000..f390730459 --- /dev/null +++ b/.changeset/good-books-move.md @@ -0,0 +1,61 @@ +--- +'@builder.io/mitosis': patch +--- + +[angular, stencil]: Add `attributePassing` to enable passing attributes like `data-*`, `aria-*` or `class` to correct child. + +There is a wired behaviour for Angular and Stencil (without shadow DOM), where attributes are rendered on parent elements like this: + +**Input** + +```angular2html + + +``` + +**Output** + +```html + + + + +``` + +In general, we want to pass those attributes down to the rendered child, like this: + +```html + + + + +``` + +We provide 2 ways to enable this attribute passing: + +**Metadata** + +```tsx +// my-component.lite.tsx +useMetadata({ + attributePassing: { + enabled: true, + // customRef: "_myRef"; + }, +}); +``` + +**Config** + +```js +// mitosis.config.cjs +module.exports = { + // ... other settings + attributePassing: { + enabled: true, + // customRef: "_myRef"; + }, +}; +``` + +If you enable the ``attributePassing`` we add a new `ref` to the root element named `_root` to interact with the DOM element. If you wish to control the name of the ref, because you already have a `useRef` on your root element, you can use the `customRef` property to select it. diff --git a/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap b/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap index 09c985ebb8..8756b7d8b3 100644 --- a/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap @@ -1692,6 +1692,35 @@ exports[`Alpine.js > jsx > Javascript Test > basicOnUpdateReturn 1`] = ` " `; +exports[`Alpine.js > jsx > Javascript Test > basicRefAttributePassing 1`] = ` +"/** useMetadata: {\\"attributePassing\\":{\\"enabled\\":true}} */ + + + +" +`; + +exports[`Alpine.js > jsx > Javascript Test > basicRefAttributePassingCustomRef 1`] = ` +"/** useMetadata: {\\"attributePassing\\":{\\"enabled\\":true,\\"customRef\\":\\"buttonRef\\"}} +*/ + +
+ +
+ +" +`; + exports[`Alpine.js > jsx > Javascript Test > class + ClassName + css 1`] = ` "