UNPKG

1.57 kBTypeScriptView Raw
1import React from 'react';
2import { TextAccessorFn } from './Accessors';
3declare type FocusListContext = {
4 focusedItem: any | undefined;
5 activeId?: string;
6 map: WeakMap<HTMLElement, any>;
7};
8export declare const FocusListContext: React.Context<FocusListContext | null>;
9export interface FocusProps {
10 children: any;
11 textAccessor: TextAccessorFn;
12}
13export interface FocusList<TDataItem = unknown> {
14 size(): number;
15 focus: (el: HTMLElement | null | undefined) => void;
16 first: () => HTMLElement | undefined;
17 last: () => HTMLElement | undefined;
18 prev(opts?: FocusOptions): HTMLElement | undefined;
19 next(opts?: FocusOptions): HTMLElement | undefined;
20 hasFocused: () => boolean;
21 getFocused: () => TDataItem | undefined;
22 toDataItem: (el: HTMLElement) => TDataItem | undefined;
23 context: FocusListContext;
24 get(): [HTMLElement[], HTMLElement | undefined];
25}
26interface FocusOptions {
27 behavior?: 'clear' | 'stop' | 'loop';
28}
29interface FocusListOptions<TDataItem> {
30 scope: React.MutableRefObject<HTMLElement | null>;
31 anchorItem?: TDataItem;
32 focusFirstItem?: boolean;
33 scopeSelector?: string;
34 activeId?: string;
35}
36export declare function useListOption<TDataItem, T extends HTMLElement>(dataItem: TDataItem): readonly [React.RefObject<T>, boolean, string | undefined];
37export declare const useFocusList: <TDataItem>({ scope: listRef, anchorItem, focusFirstItem, scopeSelector, activeId, }: FocusListOptions<TDataItem>) => FocusList<TDataItem>;
38export {};
39//# sourceMappingURL=FocusListContext.d.ts.map
\No newline at end of file