@@ -18,6 +18,9 @@ export class UmbSelectionManager<ValueType extends string | null = string | null
1818 #multiple = new UmbBooleanState ( false ) ;
1919 public readonly multiple = this . #multiple. asObservable ( ) ;
2020
21+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22+ #selectionFilter = ( unique : ValueType ) => true ;
23+
2124 constructor ( host : UmbControllerHost ) {
2225 super ( host ) ;
2326 }
@@ -109,6 +112,9 @@ export class UmbSelectionManager<ValueType extends string | null = string | null
109112 public select ( unique : ValueType ) {
110113 if ( this . getSelectable ( ) === false ) return ;
111114 if ( this . isSelected ( unique ) ) return ;
115+ if ( this . #selectionFilter( unique ) === false ) {
116+ throw new Error ( 'The selection filter does not allow this item to be selected.' ) ;
117+ }
112118 const newSelection = this . getMultiple ( ) ? [ ...this . getSelection ( ) , unique ] : [ unique ] ;
113119 this . #selection. setValue ( newSelection ) ;
114120 this . getHostElement ( ) . dispatchEvent ( new UmbSelectedEvent ( unique ) ) ;
@@ -146,4 +152,13 @@ export class UmbSelectionManager<ValueType extends string | null = string | null
146152 if ( this . getSelectable ( ) === false ) return ;
147153 this . #selection. setValue ( [ ] ) ;
148154 }
155+
156+ /**
157+ * Sets the selection filter.
158+ * @param filter The selection filter.
159+ * @memberof UmbSelectionManager
160+ */
161+ public setFilter ( filter : ( unique: ValueType ) => boolean ) : void {
162+ this . #selectionFilter = filter ;
163+ }
149164}
0 commit comments