@@ -18,6 +18,9 @@ export class UmbSelectionManager<ValueType extends string | null = string | null
18
18
#multiple = new UmbBooleanState ( false ) ;
19
19
public readonly multiple = this . #multiple. asObservable ( ) ;
20
20
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
+ #selectionFilter = ( unique : ValueType ) => true ;
23
+
21
24
constructor ( host : UmbControllerHost ) {
22
25
super ( host ) ;
23
26
}
@@ -109,6 +112,9 @@ export class UmbSelectionManager<ValueType extends string | null = string | null
109
112
public select ( unique : ValueType ) {
110
113
if ( this . getSelectable ( ) === false ) return ;
111
114
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
+ }
112
118
const newSelection = this . getMultiple ( ) ? [ ...this . getSelection ( ) , unique ] : [ unique ] ;
113
119
this . #selection. setValue ( newSelection ) ;
114
120
this . getHostElement ( ) . dispatchEvent ( new UmbSelectedEvent ( unique ) ) ;
@@ -146,4 +152,13 @@ export class UmbSelectionManager<ValueType extends string | null = string | null
146
152
if ( this . getSelectable ( ) === false ) return ;
147
153
this . #selection. setValue ( [ ] ) ;
148
154
}
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
+ }
149
164
}
0 commit comments