ember-stargate icon indicating copy to clipboard operation
ember-stargate copied to clipboard

Pick an element for <PortalTarget>

Open gossi opened this issue 3 years ago • 3 comments

As of now a <PortalTarget> is rendered as <div>. In some situations you want to be more specific in expressing proper semantics and a <div> isn't the best solution, or you have to wrap the <div> from <PortalTarget> in a more semantic element, but that clutters the actual output.

I'm using a technic to make this customizable quite well and am proposing for this situation, too in using the (element) helper:

Invocation:

<PortalTarget @element={{element 'nav'}} ... />

And inside of it:

{{#let (or @element (element 'div')) as |Element|}}
  <Element ...>...</Element>
{{/let}}

This way it will keep <div> as a default/fallback but provides a strategy to override this.

WDYT?

gossi avatar Jan 26 '22 13:01 gossi

Yes, that would be nice! PR welcome! 🙂

An alternative would be to expose a modifier, so you can attach the target to any existing element. However while the addon currently does not support FastBoot correctly, it would be possible to do that probably with the existing component API, while a modifier won't ever run in FastBoot, so that's not so good...

simonihmig avatar Feb 04 '22 16:02 simonihmig

@gossi just ran into a case where I'd prefer to have fewer DOM elements as you outlined, did you ever end up tackling this? Not at all urgent but thought I'd ask 😄

acorncom avatar Jan 25 '23 10:01 acorncom

I re-arranged this with:

<nav>
  ...
  <PortalTarget ...>
</nav>

which is fine to take <div>s for me. More elegant is to have control over this for sure. Shouldn't be too hard to write a PR though 👍

gossi avatar Jan 25 '23 19:01 gossi