PolymerElements / paper-input

A Material Design text field
https://www.webcomponents.org/element/PolymerElements/paper-input
130 stars 159 forks source link

paper-input does not work with a datalist in shadow DOM #595

Open KeithHenry opened 6 years ago

KeithHenry commented 6 years ago

Description

When using the HTML5 platform you can specify a datalist to use with an input:

<input list="cities">
<datalist id="cities">
    <option value="Birkenhead"></option>
    <option value="Liverpool"></option>
    <option value="Warrington"></option>
    ...
<datalist>

Although the list attribute is copied across to the internal native input this does not work with paper-input.

Expected outcome

The datalist should appear as autocomplete options for the paper-input.

Actual outcome

The datalist does not appear as autocomplete options for the paper-input.

Steps to reproduce

  1. Init Polymer with proper shadow DOM:

    window.Polymer = { dom: 'shadow' };
  2. Put a paper-input element in the page.

  3. Add a datalist with an id property

  4. Add a list property to the paper-input

  5. It doesn't work.

It does work with the shady DOM polyfill, and can be hacked in the dev tools by moving the datalist into the same shadow root as the input.

Browsers Affected

KeithHenry commented 6 years ago

Looking at fixes for this: the <input> and <datalist> must be in the same shadow root.

So, either:

notwaldorf commented 6 years ago

Yup, that's right. The native input element doesn't know how to traverse shadow roots, so it must be in the same root as the datalist. I'd recommend using a <paper-input-container> and wrapping an iron-input that way, if you need to

KeithHenry commented 6 years ago

Cheers for the response @notwaldorf. Yes, that's my current workaround, and the new <simple-input> element pattern for Polymer 3 doesn't have this problem.

What should we do with this element?

notwaldorf commented 6 years ago

I think....in paper-input we can observe the datalist attribute/property, and when it changes, create a datalist in the shadow dom, next to the input, and link them there. wdyt?

notwaldorf commented 6 years ago

(i think the difference is copying it on datalist changing, vs on attach, but as a low barrier of entry tbh, attach would work too)

Would you be interested in sending a PR for this? I can help anywhere you're stuck

KeithHenry commented 6 years ago

Cheers @notwaldorf, I'll have a go at it when I have a little time.

What should I do with the current list: String property? I'd remove it and just set the <input list$=... when there is a datalist: Array populated, but that may break things for users relying on the shady DOM shim behavior (that currently works). I can also leave it in, and just use it for the id of the generated <datalist>, but then this bug persists for any users that don't set the new property.

KeithHenry commented 6 years ago

@notwaldorf That PR seemed simple enough, but has 6 failing Travis tests due to focus/blur events and aria-* attributes that <datalist> doesn't support. I'm not quite sure what to do to fix those.