Skip to content

Commit

Permalink
Revise RFC #389 with details about its argument
Browse files Browse the repository at this point in the history
  • Loading branch information
chancancode authored Apr 29, 2020
1 parent 7deb9a7 commit 41b02db
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions text/0389-dynamic-tag-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,29 @@ With the `element` helper proposed in this RFC, this can be accomplished with so

## Detailed design

We propose to add a new `element` helper that takes a tag name and generates a contextual component that, when invoked, renders the selected element.
We propose to add a new `element` helper that takes a single positional argument.

* When passed a non-empty string it will generates a contextual component that, when invoked, renders an element with the same tag name as the passed string, along with the passed attributes (if any) and yields to given block (if any).
* When passed an empty string, it will generates a contextual compoment that, when invoked, yields to the given block without wrapping it an element and ignores any passed attributes.
* When passed `null` or `undefined`, it will return `null`.
* When passed any other values (e.g. a boolean or a number), it will result in a development mode assertion.

Example:

```hbs
{{#let (element @htmlTag) as |Tag|}}
<Tag>...</Tag>
<Tag class="my-element">Hello</Tag>
{{/let}}
{{!-- when @htmlTag="div" --}}
<div class="my-element">Hello</div>
{{!-- when @htmlTag="" --}}
Hello
{{!-- when @htmlTag=null or @htmlTag=undefined, it renders nothing --}}
{{!-- when @htmlTag=true or @htmlTag=1, it throws in development mode --}}
```

Unlike ids, classes or other attributes, the tag name of DOM element cannot be changed in runtime.
Expand Down

0 comments on commit 41b02db

Please sign in to comment.