@rogieking/figui3 1.0.86 → 1.0.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/fig.js +22 -9
  2. package/package.json +1 -1
package/fig.js CHANGED
@@ -100,6 +100,14 @@ if (window.customElements && !window.customElements.get("fig-dropdown")) {
100
100
  this.attachShadow({ mode: "open" });
101
101
  }
102
102
 
103
+ #addEventListeners() {
104
+ this.select.addEventListener("input", this.#handleSelectInput.bind(this));
105
+ this.select.addEventListener(
106
+ "change",
107
+ this.#handleSelectChange.bind(this)
108
+ );
109
+ }
110
+
103
111
  connectedCallback() {
104
112
  this.type = this.getAttribute("type") || "select";
105
113
 
@@ -111,17 +119,14 @@ if (window.customElements && !window.customElements.get("fig-dropdown")) {
111
119
  this.slotChange.bind(this)
112
120
  );
113
121
 
114
- this.select.addEventListener("input", this.#handleSelectInput.bind(this));
115
- this.select.addEventListener(
116
- "change",
117
- this.#handleSelectChange.bind(this)
118
- );
122
+ this.#addEventListeners();
119
123
  }
120
124
 
121
125
  slotChange() {
122
126
  while (this.select.firstChild) {
123
127
  this.select.firstChild.remove();
124
128
  }
129
+
125
130
  if (this.type === "dropdown") {
126
131
  const hiddenOption = document.createElement("option");
127
132
  hiddenOption.setAttribute("hidden", "true");
@@ -133,6 +138,7 @@ if (window.customElements && !window.customElements.get("fig-dropdown")) {
133
138
  this.select.appendChild(option.cloneNode(true));
134
139
  }
135
140
  });
141
+ this.#syncSelectedValue(this.value);
136
142
  if (this.type === "dropdown") {
137
143
  this.select.selectedIndex = -1;
138
144
  }
@@ -159,16 +165,23 @@ if (window.customElements && !window.customElements.get("fig-dropdown")) {
159
165
  }
160
166
  set value(value) {
161
167
  this.setAttribute("value", value);
162
- this.select.value = value;
163
- this.select.setAttribute("value", value);
164
168
  }
165
169
  static get observedAttributes() {
166
170
  return ["value", "type"];
167
171
  }
172
+ #syncSelectedValue(value) {
173
+ if (this.select) {
174
+ this.select.querySelectorAll("option").forEach((o, i) => {
175
+ if (o.value === this.getAttribute("value")) {
176
+ this.select.selectedIndex = i;
177
+ }
178
+ });
179
+ }
180
+ }
168
181
  attributeChangedCallback(name, oldValue, newValue) {
169
182
  if (name === "value") {
170
- this.select.value = newValue;
171
- this.select.setAttribute("value", newValue);
183
+ this.#syncSelectedValue(newValue);
184
+ console.log("val:", this.value);
172
185
  }
173
186
  if (name === "type") {
174
187
  this.type = newValue;
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.86"
3
+ "version": "1.0.87"
4
4
  }