UNPKG

3.85 kBTypeScriptView Raw
1import * as React from "react";
2import { AbstractPureComponent2, InputGroupProps2 } from "@blueprintjs/core";
3import { ListItemsProps, SelectPopoverProps } from "../../common";
4export interface Suggest2Props<T> extends ListItemsProps<T>, Omit<SelectPopoverProps, "popoverTargetProps"> {
5 /**
6 * Whether the popover should close after selecting an item.
7 *
8 * @default true
9 */
10 closeOnSelect?: boolean;
11 /** Whether the input field should be disabled. */
12 disabled?: boolean;
13 /**
14 * Whether the component should take up the full width of its container.
15 */
16 fill?: boolean;
17 /**
18 * Props to pass to the query [InputGroup component](#core/components/text-inputs.input-group).
19 *
20 * Some properties are unavailable:
21 * - `inputProps.value`: use `query` instead
22 * - `inputProps.onChange`: use `onQueryChange` instead
23 * - `inputProps.disabled`: use `disabled` instead
24 * - `inputProps.fill`: use `fill` instead
25 *
26 * Other notes:
27 * - `inputProps.tagName` will override `popoverProps.targetTagName`
28 * - `inputProps.className` will work as expected, but this is redundant with the simpler `className` prop
29 */
30 inputProps?: Partial<Omit<InputGroupProps2, "disabled" | "fill" | "value" | "onChange">>;
31 /** Custom renderer to transform an item into a string for the input value. */
32 inputValueRenderer: (item: T) => string;
33 /**
34 * The uncontrolled default selected item.
35 * This prop is ignored if `selectedItem` is used to control the state.
36 */
37 defaultSelectedItem?: T;
38 /**
39 * The currently selected item, or `null` to indicate that no item is selected.
40 * If omitted or `undefined`, this prop will be uncontrolled (managed by the component's state).
41 * Use `onItemSelect` to listen for updates.
42 */
43 selectedItem?: T | null;
44 /**
45 * HTML attributes to add to the `Menu` listbox containing the selectable options.
46 */
47 menuProps?: React.HTMLAttributes<HTMLUListElement>;
48 /**
49 * If true, the component waits until a keydown event in the TagInput
50 * before opening its popover.
51 *
52 * If false, the popover opens immediately after a mouse click or TAB key
53 * interaction focuses the component's TagInput.
54 *
55 * @default false
56 */
57 openOnKeyDown?: boolean;
58 /**
59 * Whether the active item should be reset to the first matching item _when
60 * the popover closes_. The query will also be reset to the empty string.
61 *
62 * @default false
63 */
64 resetOnClose?: boolean;
65}
66export interface Suggest2State<T> {
67 isOpen: boolean;
68 selectedItem: T | null;
69}
70/**
71 * Suggest (v2) component.
72 *
73 * @see https://blueprintjs.com/docs/#select/suggest2
74 */
75export declare class Suggest2<T> extends AbstractPureComponent2<Suggest2Props<T>, Suggest2State<T>> {
76 static displayName: string;
77 static defaultProps: Partial<Suggest2Props<any>>;
78 /** @deprecated no longer necessary now that the TypeScript parser supports type arguments on JSX element tags */
79 static ofType<U>(): new (props: Suggest2Props<U>) => Suggest2<U>;
80 state: Suggest2State<T>;
81 inputElement: HTMLInputElement | null;
82 private queryList;
83 private handleInputRef;
84 private handleQueryListRef;
85 private listboxId;
86 render(): JSX.Element;
87 componentDidUpdate(prevProps: Suggest2Props<T>, prevState: Suggest2State<T>): void;
88 private renderQueryList;
89 private getPopoverTargetRenderer;
90 private selectText;
91 private handleInputFocus;
92 private handleItemSelect;
93 private getInitialSelectedItem;
94 private handlePopoverInteraction;
95 private handlePopoverOpening;
96 private handlePopoverOpened;
97 private getTargetKeyDownHandler;
98 private getTargetKeyUpHandler;
99 private maybeResetActiveItemToSelectedItem;
100}