()
| 241 | } |
| 242 | |
| 243 | private renderDropdown() { |
| 244 | if (!this.dropdownEl) return; |
| 245 | this.dropdownEl.empty(); |
| 246 | |
| 247 | if (this.labels.clearLabel && this.selectedValues.size > 0) { |
| 248 | const clearItem = this.dropdownEl.createDiv({ cls: "custom-dropdown-item custom-dropdown-clear" }); |
| 249 | clearItem.textContent = this.labels.clearLabel; |
| 250 | clearItem.addEventListener("click", (e) => { |
| 251 | e.stopPropagation(); |
| 252 | this.selectedValues.clear(); |
| 253 | this.updateLabel(); |
| 254 | this.renderDropdown(); |
| 255 | this.notifyChange(); |
| 256 | }); |
| 257 | } |
| 258 | |
| 259 | this.options.forEach((label, value) => { |
| 260 | const item = this.dropdownEl!.createDiv({ cls: "custom-dropdown-item" }); |
| 261 | const check = item.createDiv({ cls: "custom-dropdown-check" }); |
| 262 | setIcon(check, "check"); |
| 263 | item.createDiv({ cls: "custom-dropdown-text", text: label }); |
| 264 | item.setAttr("title", label); |
| 265 | const isSelected = this.selectedValues.has(value); |
| 266 | if (isSelected) { |
| 267 | item.addClass("is-selected"); |
| 268 | } |
| 269 | |
| 270 | item.addEventListener("click", (e) => { |
| 271 | e.stopPropagation(); |
| 272 | if (this.selectedValues.has(value)) { |
| 273 | this.selectedValues.delete(value); |
| 274 | } else { |
| 275 | this.selectedValues.add(value); |
| 276 | } |
| 277 | this.updateLabel(); |
| 278 | this.renderDropdown(); |
| 279 | this.notifyChange(); |
| 280 | }); |
| 281 | }); |
| 282 | } |
| 283 | |
| 284 | onChange(callback: (values: string[]) => void) { |
| 285 | this.onChangeCallback = callback; |
no test coverage detected