-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add attribute passing for angular and stencil (#1665)
* feat: add attribute passing for angular and stencil * fix: issue with wrong path for builder.test.ts * chore: update snapshots * Update packages/core/src/__tests__/angular.test.ts * Revert "Update packages/core/src/__tests__/angular.test.ts" This reverts commit 983d6b9. --------- Co-authored-by: Sami Jaber <[email protected]> Co-authored-by: Sami Jaber <[email protected]>
- Loading branch information
1 parent
ed0d7fa
commit b63279f
Showing
49 changed files
with
6,441 additions
and
572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<!-- Angular --> | ||
<my-component class="cool" data-nice="true" aria-label="wow"></my-component> | ||
``` | ||
|
||
**Output** | ||
|
||
```html | ||
<!-- DOM --> | ||
<my-component class="cool" data-nice="true" aria-label="wow"> | ||
<button class="my-component">My Component</button> | ||
</my-component> | ||
``` | ||
|
||
In general, we want to pass those attributes down to the rendered child, like this: | ||
|
||
```html | ||
<!-- DOM --> | ||
<my-component> | ||
<button class="my-component cool" data-nice="true" aria-label="wow">My Component</button> | ||
</my-component> | ||
``` | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.