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

Enable creation of datalist element inside same shadow root as input #599

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion paper-input-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,25 @@
},

/**
* The datalist of the input (if any). This should match the id of an existing `<datalist>`.
* The id of a datalist for the input (if any).
* If not using Shadow DOM this can match the id of an existing `<datalist>`, otherwise the datalist property must also be set
* If you're using PaperInputBehavior to implement your own paper-input-like
* element, bind this to the `<input is="iron-input">`'s `list` property.
*/
list: {
type: String
},

/**
* Optional values for a datalist for the input.
* If the list property is also set that will be used as the id.
* If you're using PaperInputBehavior to implement your own paper-input-like
* element, use this to generate `<datalist>` in the same shadow root as the `<input>`.
*/
datalist: {
type: Array
},

/**
* A pattern to validate the `input` with. If you're using PaperInputBehavior to
* implement your own paper-input-like element, bind this to
Expand Down Expand Up @@ -554,6 +565,15 @@
this._focusableElement.focus();
}
}
},

/** Get the ID of any <datalist> and the <input list=""> attribute. */
_listId: function (override, values) {
if (override)
return override;

if (values && Array.isArray(values) && values.length > 0)
return 'values';
}
};

Expand Down
13 changes: 10 additions & 3 deletions paper-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@
<slot name="prefix" slot="prefix"></slot>

<label hidden$="[[!label]]" aria-hidden="true" for="input" slot="label">[[label]]</label>


<template is="dom-if" if="[[datalist]]">
<datalist id="[[_listId(list, datalist)]]">
<template is="dom-repeat" items=[[datalist]] as="listitem">
<option value$=[[listitem]]></option>
</template>
</datalist>
</template>
<span id="template-placeholder"></span>

<slot name="suffix" slot="suffix"></slot>
Expand Down Expand Up @@ -207,7 +214,7 @@
name$="[[name]]"
placeholder$="[[placeholder]]"
readonly$="[[readonly]]"
list$="[[list]]"
list$="[[_listId(list, datalist)]]"
size$="[[size]]"
autocapitalize$="[[autocapitalize]]"
autocorrect$="[[autocorrect]]"
Expand Down Expand Up @@ -245,7 +252,7 @@
name$="[[name]]"
placeholder$="[[placeholder]]"
readonly$="[[readonly]]"
list$="[[list]]"
list$="[[_listId(list, datalist)]]"
size$="[[size]]"
autocapitalize$="[[autocapitalize]]"
autocorrect$="[[autocorrect]]"
Expand Down