@smilodon/core 1.0.8 → 1.0.10

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.
package/dist/index.umd.js CHANGED
@@ -2268,24 +2268,33 @@
2268
2268
  });
2269
2269
  this._optionsContainer.appendChild(header);
2270
2270
  group.options.forEach(item => {
2271
- this._renderSingleOption(item, getValue, getLabel);
2271
+ // Find original index for correct ID generation and selection
2272
+ const index = this._state.loadedItems.indexOf(item);
2273
+ if (index !== -1) {
2274
+ this._renderSingleOption(item, index, getValue, getLabel);
2275
+ }
2272
2276
  });
2273
2277
  });
2274
2278
  }
2275
2279
  else {
2276
2280
  // Normal rendering (flat list or filtered)
2277
- const itemsToRender = query
2278
- ? this._state.loadedItems.filter((item) => {
2281
+ let hasRenderedItems = false;
2282
+ this._state.loadedItems.forEach((item, index) => {
2283
+ // Apply filter if query exists
2284
+ if (query) {
2279
2285
  try {
2280
2286
  const label = String(getLabel(item)).toLowerCase();
2281
- return label.includes(query);
2287
+ if (!label.includes(query))
2288
+ return;
2282
2289
  }
2283
2290
  catch (e) {
2284
- return false;
2291
+ return;
2285
2292
  }
2286
- })
2287
- : this._state.loadedItems;
2288
- if (itemsToRender.length === 0 && !this._state.isBusy) {
2293
+ }
2294
+ hasRenderedItems = true;
2295
+ this._renderSingleOption(item, index, getValue, getLabel);
2296
+ });
2297
+ if (!hasRenderedItems && !this._state.isBusy) {
2289
2298
  const empty = document.createElement('div');
2290
2299
  empty.className = 'empty-state';
2291
2300
  if (query) {
@@ -2296,11 +2305,6 @@
2296
2305
  }
2297
2306
  this._optionsContainer.appendChild(empty);
2298
2307
  }
2299
- else {
2300
- itemsToRender.forEach((item) => {
2301
- this._renderSingleOption(item, getValue, getLabel);
2302
- });
2303
- }
2304
2308
  }
2305
2309
  // Append Busy Indicator if busy
2306
2310
  if (this._state.isBusy && this._config.busyBucket.enabled) {
@@ -2323,26 +2327,26 @@
2323
2327
  this._addLoadMoreTrigger();
2324
2328
  }
2325
2329
  }
2326
- _renderSingleOption(item, getValue, getLabel) {
2330
+ _renderSingleOption(item, index, getValue, getLabel) {
2327
2331
  const option = document.createElement('div');
2328
2332
  option.className = 'option';
2333
+ option.id = `${this._uniqueId}-option-${index}`;
2329
2334
  const value = getValue(item);
2330
2335
  const label = getLabel(item);
2331
2336
  option.textContent = label;
2332
2337
  option.dataset.value = String(value);
2338
+ option.dataset.index = String(index); // Also useful for debugging/selectors
2333
2339
  // Check if selected using selectedItems map
2334
- const isSelected = Array.from(this._state.selectedItems.values()).some(selectedItem => {
2335
- const selectedValue = getValue(selectedItem);
2336
- return selectedValue === value;
2337
- });
2340
+ const isSelected = this._state.selectedIndices.has(index);
2338
2341
  if (isSelected) {
2339
2342
  option.classList.add('selected');
2343
+ option.setAttribute('aria-selected', 'true');
2344
+ }
2345
+ else {
2346
+ option.setAttribute('aria-selected', 'false');
2340
2347
  }
2341
2348
  option.addEventListener('click', () => {
2342
- const index = this._state.loadedItems.indexOf(item);
2343
- if (index !== -1) {
2344
- this._selectOption(index);
2345
- }
2349
+ this._selectOption(index);
2346
2350
  });
2347
2351
  this._optionsContainer.appendChild(option);
2348
2352
  }