@@ -110,6 +110,13 @@ export class PerfectSelectComponent implements ControlValueAccessor, OnInit, OnC
110110 @Input ( ) emptyStateText = 'No options available' ;
111111 @Input ( ) emptySearchText = 'No results found' ;
112112
113+ // v1.0.1 Features
114+ @Input ( ) maxSelectedOptions : number | null = null ;
115+ @Input ( ) maxSelectedMessage : string = 'Maximum selections reached' ;
116+ @Input ( ) debounceTime : number = 300 ;
117+ @Input ( ) minSearchLength : number = 0 ;
118+ @Input ( ) minSearchMessage : string = 'Type to search...' ;
119+
113120 // Behavior
114121 @Input ( ) name = 'angular-perfect-select' ;
115122 @Input ( ) id = 'angular-perfect-select' ;
@@ -147,6 +154,7 @@ export class PerfectSelectComponent implements ControlValueAccessor, OnInit, OnC
147154 internalOptions = signal < SelectOption [ ] > ( [ ] ) ;
148155 isLoadingAsync = signal ( false ) ;
149156 private optionsCache = new Map < string , SelectOption [ ] > ( ) ;
157+ private debounceTimeout : any = null ;
150158
151159 // Computed signals
152160 currentTheme = computed ( ( ) => THEMES [ this . theme ] || THEMES . blue ) ;
@@ -155,6 +163,11 @@ export class PerfectSelectComponent implements ControlValueAccessor, OnInit, OnC
155163 const term = this . searchTerm ( ) ;
156164 const opts = this . internalOptions ( ) ;
157165
166+ // Check min search length
167+ if ( this . minSearchLength > 0 && term . length < this . minSearchLength ) {
168+ return [ ] ;
169+ }
170+
158171 if ( ! term ) return opts ;
159172
160173 return opts . filter ( option => {
@@ -265,6 +278,19 @@ export class PerfectSelectComponent implements ControlValueAccessor, OnInit, OnC
265278 return selectedCount > 0 && selectedCount < opts . length ;
266279 } ) ;
267280
281+ // v1.0.1 Computed signals
282+ isMaxSelectionReached = computed ( ( ) => {
283+ if ( ! this . isMulti || this . maxSelectedOptions === null ) return false ;
284+ const selected = this . selectedOptions ( ) ;
285+ return selected . length >= this . maxSelectedOptions ;
286+ } ) ;
287+
288+ showMinSearchMessage = computed ( ( ) => {
289+ if ( this . minSearchLength === 0 ) return false ;
290+ const term = this . searchTerm ( ) ;
291+ return this . isOpen ( ) && term . length > 0 && term . length < this . minSearchLength ;
292+ } ) ;
293+
268294 // Helper method for template
269295 getEnabledOptionsCount ( ) : number {
270296 return this . filteredOptions ( ) . filter ( opt => ! this . isOptionDisabled ( opt ) ) . length ;
@@ -331,7 +357,10 @@ export class PerfectSelectComponent implements ControlValueAccessor, OnInit, OnC
331357 }
332358
333359 ngOnDestroy ( ) : void {
334- // Cleanup handled by DestroyRef
360+ // Clear debounce timeout
361+ if ( this . debounceTimeout ) {
362+ clearTimeout ( this . debounceTimeout ) ;
363+ }
335364 }
336365
337366 // Keyboard Navigation
@@ -461,6 +490,10 @@ export class PerfectSelectComponent implements ControlValueAccessor, OnInit, OnC
461490 if ( exists ) {
462491 newValue = currentValue . filter ( ( v : any ) => v !== optionValue ) ;
463492 } else {
493+ // Check max selection limit
494+ if ( this . maxSelectedOptions !== null && currentValue . length >= this . maxSelectedOptions ) {
495+ return ; // Don't allow selection beyond max
496+ }
464497 newValue = [ ...currentValue , optionValue ] ;
465498 }
466499
@@ -521,7 +554,13 @@ export class PerfectSelectComponent implements ControlValueAccessor, OnInit, OnC
521554
522555 // Select All / Deselect All
523556 selectAll ( ) : void {
524- const opts = this . filteredOptions ( ) . filter ( opt => ! this . isOptionDisabled ( opt ) ) ;
557+ let opts = this . filteredOptions ( ) . filter ( opt => ! this . isOptionDisabled ( opt ) ) ;
558+
559+ // Respect max selection limit
560+ if ( this . maxSelectedOptions !== null && opts . length > this . maxSelectedOptions ) {
561+ opts = opts . slice ( 0 , this . maxSelectedOptions ) ;
562+ }
563+
525564 const values = opts . map ( opt => this . getOptionValue ( opt ) ) ;
526565 this . internalValue . set ( values ) ;
527566 this . onChange ( values ) ;
@@ -550,9 +589,17 @@ export class PerfectSelectComponent implements ControlValueAccessor, OnInit, OnC
550589 action : 'input-change'
551590 } ) ;
552591
553- // Trigger async loading if configured
592+ // Trigger async loading if configured with debounce
554593 if ( this . loadOptions ) {
555- this . handleLoadOptions ( term ) ;
594+ // Clear existing timeout
595+ if ( this . debounceTimeout ) {
596+ clearTimeout ( this . debounceTimeout ) ;
597+ }
598+
599+ // Set new timeout for debounced loading
600+ this . debounceTimeout = setTimeout ( ( ) => {
601+ this . handleLoadOptions ( term ) ;
602+ } , this . debounceTime ) ;
556603 }
557604 }
558605
0 commit comments