polymer: Prevent duplicate ID's in polyfill
When using id’s in a polymer component and using the new element multiple times, the fallback solution will render the same html multiple times, which leads to multiple id’s inside of the DOM, invalid html and maybe misbehaviour.
For example:
<polymer-element name="sj-checkbox" attributes="size">
<template>
<style>
/* all my styles here */
</style>
<div class="switch {{size}}">
<div class="switch__circle">
<input id="switcher" class="switch__input" type="checkbox" on-change="changeHandler" checked="checked">
<div class="switch__innerCircles"></div>
<label class="switch__label" for="switcher">Switch me!!!</label>
</div>
</div>
</div>
</template>
<script>
Polymer( 'sj-checkbox', {
size: 'medium',
changeHandler: function( event ) {
this.fire(
'change',
{
id: event.target.id
}
);
}
} );
</script>
</polymer-element>
will become:
<sj-checkbox size="big" fallbackid="checkboxBigComponent">
<div class="switch big">
<div class="switch__circle">
<input id="switcher" class="switch__input" type="checkbox" on-change="changeHandler" checked="checked">
<div class="switch__innerCircles"></div>
<label class="switch__label" for="switcher">Switch me!!!</label>
</div>
</div>
</sj-checkbox>
Unfortunately the component is not reusable in this case.
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 21 (11 by maintainers)
I landed here after snooping around wondering if using “id” in a component was a good idea. The FAQ is only there for 0.5 which is now rather obsolete.
This only creates a problem when doing DOM-level ID referencing. Before now, it was discussed that the only tag with the problem was
<label for="...">which I assume is obsoleted in favour of iron-label. But now… aria-labelledby seems to be yet another example of DOM-level ID referencing with a problem. Is it worthwhile creating another issue about these?(I really hope to open this ticket in 5 years time and think “ahhhhhh do you remember the days when we had to use shims and polyfills”?)