Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification on use of template repeat for <tr> & <select> #318

Closed
beriberikix opened this issue Oct 15, 2013 · 8 comments
Closed

Clarification on use of template repeat for <tr> & <select> #318

beriberikix opened this issue Oct 15, 2013 · 8 comments

Comments

@beriberikix
Copy link

I'm putting together a simple data table and was directed to this FAQ on using <tr> elements. Could someone expound on why these elements are different and the importance of the different setup?

Thanks!

@dfreedm
Copy link
Member

dfreedm commented Oct 15, 2013

Until the addition of the <template> element, <select> and <table> had special parser rules that prevent anything other than <option> and <tr> from being children respectively.

Trying to use other elements would result in them becoming unexpected siblings!

Therefore, the HTMLTemplateElement polyfill in the TemplateBinding library has the ability to use an <option> or <tr> as a template in these situations.

@ebidel It should probably be noted that browsers with native <template> support will allow for <template> to be a child element of <select> and <table>.

@beriberikix
Copy link
Author

So I should change

<thead>
  <tr>
    <template repeat="{{ header in thead }}">
      <th>{{header}}</th>
    </template>
  </tr>
</thead>

to

<thead>
  <tr>
    <th  template repeat="{{ header in thead }}">{{header}}</th>
  </tr>
</thead>

@ebidel
Copy link
Contributor

ebidel commented Oct 15, 2013

For best compatibility, we should recommend the second (polyfill) case? Does the first work in a non supported browser (Safari). Genuinely asking. I'm on my mobile.

@beriberikix
Copy link
Author

No workie on Safari
screen shot 2013-10-15 at 1 50 20 pm

@beriberikix
Copy link
Author

The correct syntax that works in Safari:

<table>
  <template if="{{ thead }}" >
    <thead>
      <tr>
        <th template repeat="{{ header in thead }}">{{header}}</th>
      </tr>
    </thead>
  </template>
  <tbody>
    <tr template repeat="{{ tr in tbody }}">
      <td template repeat="{{ td in tr }}">{{ td }}</td>
    </tr>
  </tbody>
</table>

@dfreedm
Copy link
Member

dfreedm commented Oct 15, 2013

@ebidel I'll defer to @rafaelw on the docs question :)

@beriberikix 👍

@rafaelw
Copy link
Contributor

rafaelw commented Oct 15, 2013

You guys sorted it out correctly. Browsers which don't support <template> will lift any unexpected elements (including <template>) out of certain contexts. These include children of table, tbody, tr, select, etc...

TemplateBinding supports 'semantic templates' for all of theses elements: https://github.com/Polymer/TemplateBinding/blob/master/src/TemplateBinding.js#L117

The docs should be clear that using templates in these locations should prefer the "semantic" version, unless all target browsers implement native template.

@ebidel
Copy link
Contributor

ebidel commented Oct 16, 2013

Beefed up the section on this in the FAQ: Polymer/old-docs-site@f13b54a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants