ember-headlessui
ember-headlessui copied to clipboard
Use `@as` to customize root element
Some of our component use a @tagName argument to customize the root element, while others use @as
We should use @as across all components for two main reasons:
- Consistency with the React/Vue implementations
- Accepting a component rather than just a string would be nice, like
Menu::ItemElementdoes (to supportLinkTo) https://github.com/GavinJoyce/ember-headlessui/blob/e936dff7d953e293e5b05bf69459d421183ebba5/addon/components/menu/item-element.hbs#L1-L4
Note: this will be a breaking change for the components currently configured to use @tagName
I'm in favor
Might be nice to create a helper named something like component-or-element to remove the need for a backing class in the Menu::ItemElement component:
{{#let (component-or-element @as) as |Tag|}}
Hmm, ^ might not be possible as the element helper is actually an AST transform, not a function that we can invoke:
https://github.com/tildeio/ember-element-helper/blob/main/addon/helpers/element.js
do we have an RFC for an element helper? maybe we need to implement that over in the glimmer-vm?
A quick improvement might be to just create a tag-name-is-component helper, that will allow us to remove the need for a backing class
do we have an RFC for an element helper?
The https://github.com/tildeio/ember-element-helper readme references a couple of RFCs
👋 Interested in contributing to this project and this seems like a good one to pick up (unless someone is already working on this of course).
Couple of questions:
- Should a tag name and a component always be accepted everywhere or are there cases were we only want to allow a tag name and not a component or vice versa?
- Should the current
@ascases be updated to also accept components? - Should
@tagNamebe deprecated first or do we just delete it and release a new minor? - It seems
{{tag-name-is-component}}does not support imported component classes (e.g.@as={{this.SomeGlimmerComponentClass}}) would it be okay to update this? Can be a separate PR of course