Skip to content

Commit 63880b9

Browse files
committed
webcomponent: observe value attr, add getter & setter
1 parent 5b4aa0e commit 63880b9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class GEAutocomplete extends HTMLElement {
5757
'debounce',
5858
'lang',
5959
'size',
60+
'value',
6061
'layers',
6162
'sources',
6263
'boundary.country',
@@ -73,6 +74,16 @@ class GEAutocomplete extends HTMLElement {
7374
]
7475
}
7576

77+
// getter & setter for the value attribute as _if_ any attribute is programatically
78+
// changed then it’s this one
79+
get value () {
80+
return this.getAttribute('value')?.trim()
81+
}
82+
83+
set value (text) {
84+
this.setAttribute('value', text)
85+
}
86+
7687
// props returns element attributes converted to props to be passed on
7788
// to the react component
7889
get props () {
@@ -81,6 +92,7 @@ class GEAutocomplete extends HTMLElement {
8192
placeholder: this.getAttribute('placeholder'),
8293
autoFocus: this.getAttribute('autofocus') !== null,
8394
debounce: parseInt(this.getAttribute('debounce')),
95+
value: this.value,
8496
params: compact({
8597
lang: this.getAttribute('lang'),
8698
size: parseInt(this.getAttribute('size')),

0 commit comments

Comments
 (0)