@fuentis/phoenix-ui 0.0.9-alpha.359 → 0.0.9-alpha.360

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.
@@ -2225,25 +2225,31 @@ class TableCaptionComponent {
2225
2225
  this.filtersForm = this.fb.group({});
2226
2226
  if (this.filters && Array.isArray(this.filters)) {
2227
2227
  for (const filter of this.filters) {
2228
- let defaultValue = null;
2228
+ const hasSelected = filter.selected !== undefined &&
2229
+ filter.selected !== null &&
2230
+ (!Array.isArray(filter.selected) || filter.selected.length > 0);
2231
+ let defaultValue;
2229
2232
  if (filter.type === 'multiselect') {
2230
- // Convert any {label, key} entries in `selected` to primitives (key)
2231
- if (Array.isArray(filter.selected) && filter.selected.length > 0) {
2232
- defaultValue = filter.selected.map((s) => s && typeof s === 'object' && 'key' in s ? s.key : s);
2233
+ if (hasSelected) {
2234
+ defaultValue = (Array.isArray(filter.selected) ? filter.selected : [filter.selected])
2235
+ .map((s) => (s && typeof s === 'object' && 'key' in s ? s.key : s));
2233
2236
  }
2234
2237
  else {
2235
- defaultValue = []; // multiselects default to empty arrays
2238
+ defaultValue = [];
2236
2239
  }
2237
2240
  }
2238
2241
  else {
2239
- defaultValue = null; // other control types can stay null
2242
+ defaultValue = hasSelected
2243
+ ? (filter.selected && typeof filter.selected === 'object' && 'key' in filter.selected
2244
+ ? filter.selected.key
2245
+ : filter.selected)
2246
+ : null;
2240
2247
  }
2241
2248
  this.filtersForm.addControl(filter.key, this.fb.control(defaultValue));
2242
2249
  }
2243
- // Emit initial state so parent can apply defaults (e.g., active: [false])
2250
+ // Emit initial state
2244
2251
  const initial = this.filtersForm.getRawValue();
2245
2252
  this.applyFiltersEvent.emit(initial);
2246
- // Re-emit on any change; parent will filter accordingly
2247
2253
  this.filtersForm.valueChanges
2248
2254
  .pipe(takeUntilDestroyed(this.dr))
2249
2255
  .subscribe((val) => this.applyFiltersEvent.emit(val));