///
import type { FindMatchIndex } from "./findMatchIndex";
import type { BaseSearchOptions } from "./utils";
/**
* The data that is provided to the `onChange` handler when searching. This will
* be triggered whenever the user types a letter that causes the current search
* result to change.
*/
export interface SearchData {
/**
* The item that was matched from the latest search.
*/
readonly item: D;
/**
* The current list of items that were provided to be searched.
*/
readonly items: readonly D[];
/**
* The index in the `items` array that the found item appears at. This is
* super useful when extending this hook to be used with
* `aria-activedescendant` focus movement or manual focus behavior since the
* `items` array should normally be the same indexes as the DOM nodes.
*/
readonly index: number;
/**
* The search value that was used to find this item and trigger the change
* event.
*/
readonly query: string;
/**
* The current target for the search keydown event.
*/
readonly target: E;
}
export declare type SearchChangeEvent = (data: SearchData) => void;
export interface BaseKeyboardSearchOptions extends BaseSearchOptions {
/**
* The list of items that should be searched whenever the user types a letter.
*/
items: readonly D[];
/**
* A required change event handler that will be called whenever a user types a
* letter and it causes a new item to be "found". This should normally be
* something that either updates the `aria-activedescendant` id to the new
* found item's id or manually focus the item's DOM node.
*/
onChange: SearchChangeEvent;
/**
* An optional `onKeyDown` event handler that should be merged with the search
* functionality.
*
* Note: This will be called **before** the search functionality is triggered.
*/
onKeyDown?: React.KeyboardEventHandler;
/**
* The amount of time that a "search" value should be kept before resetting.
* The default value works for most cases, but it might be nice to configure
* it based on your use case.
*/
resetTime?: number;
/**
* The function used to find a match index within the `items` list. You most
* likely won't want to change this.
*/
findMatchIndex?: FindMatchIndex;
}
export interface KeyboardSearchOptions extends BaseKeyboardSearchOptions {
/**
* The current index that should be "focused" due to a keyboard search. This
* should be updated whenever the `onChange` callback is fired.
*/
searchIndex: number;
}
declare type ReturnValue = React.KeyboardEventHandler;
/**
* Adds the accessibility functionality to search a list of items as the user
* types to trigger `aria-activedescendant` focus or manual DOM focus events.
*/
export declare function useKeyboardSearch({ items, onChange, onKeyDown, resetTime, searchIndex, valueKey, getItemValue, findMatchIndex, }: KeyboardSearchOptions): ReturnValue;
export {};