UNPKG

3.83 kBTypeScriptView Raw
1import * as React from "react";
2import { AbstractPureComponent, type InputGroupProps } from "@blueprintjs/core";
3import { type ListItemsProps, type SelectPopoverProps } from "../../common";
4export interface SuggestProps<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/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<InputGroupProps, "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 SuggestState<T> {
67 isOpen: boolean;
68 selectedItem: T | null;
69}
70/**
71 * Suggest component.
72 *
73 * @see https://blueprintjs.com/docs/#select/suggest
74 */
75export declare class Suggest<T> extends AbstractPureComponent<SuggestProps<T>, SuggestState<T>> {
76 static displayName: string;
77 static defaultProps: Partial<SuggestProps<any>>;
78 /** @deprecated no longer necessary now that the TypeScript parser supports type arguments on JSX element tags */
79 static ofType<U>(): new (props: SuggestProps<U>) => Suggest<U>;
80 state: SuggestState<T>;
81 inputElement: HTMLInputElement | null;
82 private queryList;
83 private handleInputRef;
84 private handleQueryListRef;
85 private listboxId;
86 render(): React.JSX.Element;
87 componentDidUpdate(prevProps: SuggestProps<T>, prevState: SuggestState<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}