1 | import * as React from "react";
|
2 | import { AbstractPureComponent, type TagInputProps } from "@blueprintjs/core";
|
3 | import { type ListItemsProps, type SelectPopoverProps } from "../../common";
|
4 | import { QueryList } from "../query-list/queryList";
|
5 | export interface MultiSelectProps<T> extends ListItemsProps<T>, SelectPopoverProps {
|
6 | /**
|
7 | * Element which triggers the multiselect popover. Providing this prop will replace the default TagInput
|
8 | * target thats rendered and move the search functionality to within the Popover.
|
9 | */
|
10 | customTarget?: (selectedItems: T[], isOpen: boolean) => React.ReactNode;
|
11 | /**
|
12 | * Whether the component is non-interactive.
|
13 | * If true, the list's item renderer will not be called.
|
14 | *
|
15 | * @default false
|
16 | */
|
17 | disabled?: boolean;
|
18 | /**
|
19 | * Whether the component should take up the full width of its container.
|
20 | */
|
21 | fill?: boolean;
|
22 | /**
|
23 | * Props to spread to the `Menu` listbox containing the selectable options.
|
24 | */
|
25 | menuProps?: React.HTMLAttributes<HTMLUListElement>;
|
26 | /**
|
27 | * If provided, this component will render a "clear" button inside its TagInput.
|
28 | * Clicking that button will invoke this callback to clear all items from the current selection.
|
29 | */
|
30 | onClear?: () => void;
|
31 | /**
|
32 | * Callback invoked when an item is removed from the selection by
|
33 | * removing its tag in the TagInput. This is generally more useful than
|
34 | * `tagInputProps.onRemove` because it receives the removed value instead of
|
35 | * the value's rendered `ReactNode` tag.
|
36 | *
|
37 | * It is not recommended to supply _both_ this prop and `tagInputProps.onRemove`.
|
38 | */
|
39 | onRemove?: (value: T, index: number) => void;
|
40 | /**
|
41 | * If true, the component waits until a keydown event in the TagInput
|
42 | * before opening its popover.
|
43 | *
|
44 | * If false, the popover opens immediately after a mouse click focuses
|
45 | * the component's TagInput.
|
46 | *
|
47 | * N.B. the behavior of this prop differs slightly from the same one
|
48 | * in the Suggest component; see https://github.com/palantir/blueprint/issues/4152.
|
49 | *
|
50 | * Ignored is customTarget prop is supplied.
|
51 | *
|
52 | * @default false
|
53 | */
|
54 | openOnKeyDown?: boolean;
|
55 | /**
|
56 | * Input placeholder text. Shorthand for `tagInputProps.placeholder`.
|
57 | *
|
58 | * @default "Search..."
|
59 | */
|
60 | placeholder?: string;
|
61 | /** Controlled selected values. */
|
62 | selectedItems: T[];
|
63 | /**
|
64 | * Props to pass to the [TagInput component](##core/components/tag-input).
|
65 | *
|
66 | * Some properties are unavailable:
|
67 | * - `tagInputProps.inputValue`: use `query` instead
|
68 | * - `tagInputProps.onInputChange`: use `onQueryChange` instead
|
69 | *
|
70 | * Some properties are available, but discouraged. If you find yourself using these due to a bug in MultiSelect
|
71 | * or some edge case which is not handled by `onItemSelect`, `onItemsPaste`, `onRemove`, and `onClear`, please
|
72 | * file a bug in the Blueprint repo:
|
73 | * - `tagInputProps.onChange`
|
74 | *
|
75 | * Notes for `tagInputProps.rightElement`:
|
76 | * - you are responsible for disabling any elements you may render here when the overall `MultiSelect` is disabled
|
77 | * - if the `onClear` prop is defined, this element will override/replace the default rightElement,
|
78 | * which is a "clear" button that removes all items from the current selection.
|
79 | *
|
80 | * This prop is passed to either the default `TagInput` or the `TagInput` rendered within the Popover
|
81 | * depending on whether `customTarget` is supplied.
|
82 | */
|
83 | tagInputProps?: Partial<Omit<TagInputProps, "inputValue" | "onInputChange">>;
|
84 | /** Custom renderer to transform an item into tag content. */
|
85 | tagRenderer: (item: T) => React.ReactNode;
|
86 | }
|
87 | /** Exported for testing, not part of public API */
|
88 | export interface MultiSelectState {
|
89 | isOpen: boolean;
|
90 | }
|
91 | /**
|
92 | * Multi select component.
|
93 | *
|
94 | * @see https://blueprintjs.com/docs/#select/multi-select
|
95 | */
|
96 | export declare class MultiSelect<T> extends AbstractPureComponent<MultiSelectProps<T>, MultiSelectState> {
|
97 | static displayName: string;
|
98 | private listboxId;
|
99 | static defaultProps: {
|
100 | disabled: boolean;
|
101 | fill: boolean;
|
102 | placeholder: string;
|
103 | };
|
104 | /** @deprecated no longer necessary now that the TypeScript parser supports type arguments on JSX element tags */
|
105 | static ofType<U>(): new (props: MultiSelectProps<U>) => MultiSelect<U>;
|
106 | state: MultiSelectState;
|
107 | input: HTMLInputElement | null;
|
108 | queryList: QueryList<T> | null;
|
109 | private refHandlers;
|
110 | componentDidUpdate(prevProps: MultiSelectProps<T>): void;
|
111 | render(): React.JSX.Element;
|
112 | private renderQueryList;
|
113 | private getPopoverTargetRenderer;
|
114 | private getTagInput;
|
115 | private handleItemSelect;
|
116 | private handleQueryChange;
|
117 | private handlePopoverInteraction;
|
118 | private handlePopoverOpened;
|
119 | private handleTagRemove;
|
120 | private getTagInputAddHandler;
|
121 | private getTagInputKeyDownHandler;
|
122 | private getTagInputKeyUpHandler;
|
123 | private handleClearButtonClick;
|
124 | }
|