Skip to content

Commit 7a89a6e

Browse files
author
Graham Butler
committed
update datalist logic
1 parent a750dad commit 7a89a6e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@author.io/element-control",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "author-control custom element (web component).",
55
"main": "dist/author-control.min.js",
66
"scripts": {

src/element.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class AuthorFormControlElement extends AuthorBaseElement(HTMLElement) {
6767
this.type = 'select'
6868

6969
if (!customElements.get('author-datalist')) {
70-
console.dir(input);
7170
input.id = this.PRIVATE.guid
7271
datalist.id = `${input.id}_datalist`
7372
input.setAttribute('list', datalist.id)
@@ -103,7 +102,12 @@ class AuthorFormControlElement extends AuthorBaseElement(HTMLElement) {
103102
this.removeChild(datalist)
104103
this.removeChild(input)
105104

106-
surrogate.inject(input, datalist, this.PRIVATE.guid)
105+
// Use a select as sourceElement to preserve option indexes, since
106+
// datalist doesn't assign indexes to child options
107+
let select = document.createElement('select')
108+
Array.from(datalist.children).forEach(option => select.add(option))
109+
110+
surrogate.inject(input, select, this.PRIVATE.guid)
107111
this.appendChild(surrogate)
108112
this.PRIVATE.input = surrogate
109113
},

0 commit comments

Comments
 (0)