ngx-com 0.1.7 → 0.1.9

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { viewChild, input, output, computed, ChangeDetectionStrategy, Component, inject, DestroyRef, signal, TemplateRef, Directive, ElementRef, ViewContainerRef, contentChild, model, linkedSignal, effect, forwardRef } from '@angular/core';
2
+ import { viewChild, input, output, computed, ChangeDetectionStrategy, Component, inject, DestroyRef, signal, TemplateRef, Directive, ElementRef, Injector, ViewContainerRef, contentChild, model, linkedSignal, effect, afterNextRender, forwardRef } from '@angular/core';
3
3
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
4
4
  import { NgTemplateOutlet } from '@angular/common';
5
5
  import { NgForm, FormGroupDirective, NgControl } from '@angular/forms';
@@ -1423,6 +1423,7 @@ const VIRTUAL_SCROLL_THRESHOLD = 50;
1423
1423
  class ComDropdown {
1424
1424
  elementRef = inject(ElementRef);
1425
1425
  destroyRef = inject(DestroyRef);
1426
+ injector = inject(Injector);
1426
1427
  overlay = inject(Overlay);
1427
1428
  viewContainerRef = inject(ViewContainerRef);
1428
1429
  liveAnnouncer = inject(LiveAnnouncer);
@@ -1498,8 +1499,19 @@ class ComDropdown {
1498
1499
  searchDebounceMs = input(300, ...(ngDevMode ? [{ debugName: "searchDebounceMs" }] : []));
1499
1500
  /** Virtual scroll threshold. */
1500
1501
  virtualScrollThreshold = input(VIRTUAL_SCROLL_THRESHOLD, ...(ngDevMode ? [{ debugName: "virtualScrollThreshold" }] : []));
1501
- /** Item size in pixels for virtual scrolling. */
1502
- virtualScrollItemSize = input(40, ...(ngDevMode ? [{ debugName: "virtualScrollItemSize" }] : []));
1502
+ /** Item size in pixels for virtual scrolling. When not set, auto-calculated from the size variant. */
1503
+ virtualScrollItemSize = input(undefined, ...(ngDevMode ? [{ debugName: "virtualScrollItemSize" }] : []));
1504
+ /** Effective item size for virtual scroll, computed from size variant when not explicitly set. */
1505
+ effectiveItemSize = computed(() => {
1506
+ const explicit = this.virtualScrollItemSize();
1507
+ if (explicit !== undefined)
1508
+ return explicit;
1509
+ switch (this.size()) {
1510
+ case 'sm': return 28;
1511
+ case 'lg': return 48;
1512
+ default: return 36;
1513
+ }
1514
+ }, ...(ngDevMode ? [{ debugName: "effectiveItemSize" }] : []));
1503
1515
  /** Maximum number of tags to display in multi-select mode. Set to null for no limit. */
1504
1516
  maxVisibleTags = input(2, ...(ngDevMode ? [{ debugName: "maxVisibleTags" }] : []));
1505
1517
  /** Custom error state matcher for determining when to show errors. */
@@ -1705,7 +1717,7 @@ class ComDropdown {
1705
1717
  }, ...(ngDevMode ? [{ debugName: "triggerClasses" }] : []));
1706
1718
  /** Computed panel classes. */
1707
1719
  panelClasses = computed(() => {
1708
- return mergeClasses('w-full z-50 overflow-hidden rounded-overlay border border-border-subtle bg-popover text-popover-foreground shadow-overlay outline-none', this.panelClass());
1720
+ return mergeClasses('w-full z-50 h-fit overflow-hidden rounded-overlay border border-border-subtle bg-popover text-popover-foreground shadow-overlay outline-none', this.panelClass());
1709
1721
  }, ...(ngDevMode ? [{ debugName: "panelClasses" }] : []));
1710
1722
  /** Computed chevron classes. */
1711
1723
  chevronClasses = computed(() => {
@@ -1986,6 +1998,7 @@ class ComDropdown {
1986
1998
  const newValues = current.filter((v) => !compare(v, value));
1987
1999
  this.updateValue(newValues.length > 0 ? newValues : []);
1988
2000
  this.announce(`${this.displayWith()(value)} removed`);
2001
+ this.repositionOverlay();
1989
2002
  }
1990
2003
  trackByValue(item, _index) {
1991
2004
  return item;
@@ -2039,6 +2052,13 @@ class ComDropdown {
2039
2052
  .pipe(takeUntilDestroyed(this.destroyRef))
2040
2053
  .subscribe(() => this.close());
2041
2054
  }
2055
+ /** Re-positions the overlay after the trigger height changes (e.g. tags added/removed). */
2056
+ repositionOverlay() {
2057
+ if (!this.overlayRef)
2058
+ return;
2059
+ // Wait for Angular to render the updated trigger before recalculating position
2060
+ afterNextRender(() => this.overlayRef?.updatePosition(), { injector: this.injector });
2061
+ }
2042
2062
  destroyOverlay() {
2043
2063
  if (this.overlayRef) {
2044
2064
  this.overlayRef.dispose();
@@ -2083,6 +2103,7 @@ class ComDropdown {
2083
2103
  this.announce(`${this.displayWith()(value)} selected`);
2084
2104
  }
2085
2105
  this.updateValue(newValues.length > 0 ? newValues : []);
2106
+ this.repositionOverlay();
2086
2107
  }
2087
2108
  navigateOptions(direction) {
2088
2109
  const options = this.groupBy() ? this.flattenGroupedOptions() : this.filteredOptions();
@@ -2364,7 +2385,7 @@ class ComDropdown {
2364
2385
  @if (virtualScrollEnabled() && groupedOptions().length === 0 && filteredOptions().length > 0) {
2365
2386
  <!-- Virtual scrolling for large ungrouped lists -->
2366
2387
  <cdk-virtual-scroll-viewport
2367
- [itemSize]="virtualScrollItemSize()"
2388
+ [itemSize]="effectiveItemSize()"
2368
2389
  [maxBufferPx]="400"
2369
2390
  [minBufferPx]="200"
2370
2391
  [style.height]="maxHeight()"
@@ -2619,7 +2640,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.0", ngImpor
2619
2640
  @if (virtualScrollEnabled() && groupedOptions().length === 0 && filteredOptions().length > 0) {
2620
2641
  <!-- Virtual scrolling for large ungrouped lists -->
2621
2642
  <cdk-virtual-scroll-viewport
2622
- [itemSize]="virtualScrollItemSize()"
2643
+ [itemSize]="effectiveItemSize()"
2623
2644
  [maxBufferPx]="400"
2624
2645
  [minBufferPx]="200"
2625
2646
  [style.height]="maxHeight()"