@@ -39,12 +39,12 @@ import { Cross } from "@blueprintjs/icons";
3939import { Classes , type ListItemsProps , type SelectPopoverProps } from "../../common" ;
4040import { QueryList , type QueryListRendererProps } from "../query-list/queryList" ;
4141
42- export interface MultiSelectProps < T > extends ListItemsProps < T > , SelectPopoverProps {
42+ export interface MultiSelectProps < T , A extends readonly T [ ] = T [ ] > extends ListItemsProps < T , A > , SelectPopoverProps {
4343 /**
4444 * Element which triggers the multiselect popover. Providing this prop will replace the default TagInput
4545 * target thats rendered and move the search functionality to within the Popover.
4646 */
47- customTarget ?: ( selectedItems : T [ ] , isOpen : boolean ) => React . ReactNode ;
47+ customTarget ?: ( selectedItems : A , isOpen : boolean ) => React . ReactNode ;
4848
4949 /**
5050 * Whether the component is non-interactive.
@@ -104,7 +104,7 @@ export interface MultiSelectProps<T> extends ListItemsProps<T>, SelectPopoverPro
104104 placeholder ?: string ;
105105
106106 /** Controlled selected values. */
107- selectedItems : T [ ] ;
107+ selectedItems : A ;
108108
109109 /**
110110 * Props to pass to the [TagInput component](##core/components/tag-input).
@@ -142,7 +142,10 @@ export interface MultiSelectState {
142142 *
143143 * @see https://blueprintjs.com/docs/#select/multi-select
144144 */
145- export class MultiSelect < T > extends AbstractPureComponent < MultiSelectProps < T > , MultiSelectState > {
145+ export class MultiSelect < T , A extends readonly T [ ] = T [ ] > extends AbstractPureComponent <
146+ MultiSelectProps < T , A > ,
147+ MultiSelectState
148+ > {
146149 public static displayName = `${ DISPLAYNAME_PREFIX } .MultiSelect` ;
147150
148151 private listboxId = Utils . uniqueId ( "listbox" ) ;
@@ -164,19 +167,19 @@ export class MultiSelect<T> extends AbstractPureComponent<MultiSelectProps<T>, M
164167
165168 public input : HTMLInputElement | null = null ;
166169
167- public queryList : QueryList < T > | null = null ;
170+ public queryList : QueryList < T , A > | null = null ;
168171
169172 private refHandlers : {
170173 input : React . RefCallback < HTMLInputElement > ;
171174 popover : React . RefObject < Popover > ;
172- queryList : React . RefCallback < QueryList < T > > ;
175+ queryList : React . RefCallback < QueryList < T , A > > ;
173176 } = {
174177 input : refHandler ( this , "input" , this . props . tagInputProps ?. inputRef ) ,
175178 popover : React . createRef ( ) ,
176- queryList : ( ref : QueryList < T > | null ) => ( this . queryList = ref ) ,
179+ queryList : ( ref : QueryList < T , A > | null ) => ( this . queryList = ref ) ,
177180 } ;
178181
179- public componentDidUpdate ( prevProps : MultiSelectProps < T > ) {
182+ public componentDidUpdate ( prevProps : MultiSelectProps < T , A > ) {
180183 if ( prevProps . tagInputProps ?. inputRef !== this . props . tagInputProps ?. inputRef ) {
181184 setRef ( prevProps . tagInputProps ?. inputRef , null ) ;
182185 this . refHandlers . input = refHandler ( this , "input" , this . props . tagInputProps ?. inputRef ) ;
@@ -195,7 +198,7 @@ export class MultiSelect<T> extends AbstractPureComponent<MultiSelectProps<T>, M
195198 const { menuProps, openOnKeyDown, popoverProps, tagInputProps, customTarget, ...restProps } = this . props ;
196199
197200 return (
198- < QueryList < T >
201+ < QueryList < T , A >
199202 { ...restProps }
200203 menuProps = { {
201204 "aria-label" : "selectable options" ,
@@ -211,7 +214,7 @@ export class MultiSelect<T> extends AbstractPureComponent<MultiSelectProps<T>, M
211214 ) ;
212215 }
213216
214- private renderQueryList = ( listProps : QueryListRendererProps < T > ) => {
217+ private renderQueryList = ( listProps : QueryListRendererProps < T , A > ) => {
215218 const { disabled, popoverContentProps = { } , popoverProps = { } } = this . props ;
216219 const { handleKeyDown, handleKeyUp } = listProps ;
217220
@@ -267,7 +270,7 @@ export class MultiSelect<T> extends AbstractPureComponent<MultiSelectProps<T>, M
267270 // the "fill" prop. Note that we must take `isOpen` as an argument to force this render function to be called
268271 // again after that state changes.
269272 private getPopoverTargetRenderer =
270- ( listProps : QueryListRendererProps < T > , isOpen : boolean ) =>
273+ ( listProps : QueryListRendererProps < T , A > , isOpen : boolean ) =>
271274 // N.B. pull out `isOpen` so that it's not forwarded to the DOM, but remember not to use it directly
272275 // since it may be stale (`renderTarget` is not re-invoked on this.state changes).
273276 // eslint-disable-next-line react/display-name
@@ -304,7 +307,7 @@ export class MultiSelect<T> extends AbstractPureComponent<MultiSelectProps<T>, M
304307 ) ;
305308 } ;
306309
307- private getTagInput = ( listProps : QueryListRendererProps < T > , className ?: string ) => {
310+ private getTagInput = ( listProps : QueryListRendererProps < T , A > , className ?: string ) => {
308311 const { disabled, fill, onClear, placeholder, selectedItems, tagInputProps = { } } = this . props ;
309312
310313 const maybeClearButton =
@@ -408,7 +411,7 @@ export class MultiSelect<T> extends AbstractPureComponent<MultiSelectProps<T>, M
408411 } ;
409412
410413 private getTagInputAddHandler =
411- ( listProps : QueryListRendererProps < T > ) => ( values : any [ ] , method : TagInputAddMethod ) => {
414+ ( listProps : QueryListRendererProps < T , A > ) => ( values : any [ ] , method : TagInputAddMethod ) => {
412415 if ( method === "paste" ) {
413416 listProps . handlePaste ( values ) ;
414417 }
0 commit comments