@rogieking/figui3 1.0.85 → 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 -6
  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
  }
@@ -163,9 +169,19 @@ if (window.customElements && !window.customElements.get("fig-dropdown")) {
163
169
  static get observedAttributes() {
164
170
  return ["value", "type"];
165
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
+ }
166
181
  attributeChangedCallback(name, oldValue, newValue) {
167
182
  if (name === "value") {
168
- this.select.value = newValue;
183
+ this.#syncSelectedValue(newValue);
184
+ console.log("val:", this.value);
169
185
  }
170
186
  if (name === "type") {
171
187
  this.type = newValue;
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.85"
3
+ "version": "1.0.87"
4
4
  }