Skip to content

Commit

Permalink
Merge pull request #291 from theKashey/correct-typescript-for-hooks
Browse files Browse the repository at this point in the history
fix: correct typescript definitions for focus helpers
  • Loading branch information
theKashey committed Feb 28, 2024
2 parents ba96b00 + 02adc7b commit e7cc578
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 5 additions & 5 deletions UI/UI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ export type FocusControl = {
* focuses the next element in the scope.
* If active element is not in the scope, autofocus will be triggered first
*/
focusNext(options:FocusOptions):Promise<void>;
focusNext(options?:FocusOptions):Promise<void>;
/**
* focuses the prev element in the scope.
* If active element is not in the scope, autofocus will be triggered first
*/
focusPrev():Promise<void>;
focusPrev(options?:FocusOptions):Promise<void>;
/**
* focused the first element in the scope
*/
focusFirst(options: Pick<FocusOptions,'onlyTabbable'>):Promise<void>;
focusFirst(options?: Pick<FocusOptions,'onlyTabbable'>):Promise<void>;
/**
* focused the last element in the scope
*/
focusLast(options: Pick<FocusOptions,'onlyTabbable'>):Promise<void>;
focusLast(options?: Pick<FocusOptions,'onlyTabbable'>):Promise<void>;
}


Expand All @@ -81,7 +81,7 @@ export type FocusControl = {
* - can be used outside of FocusLock
* @see {@link useFocusScope} for use cases inside of FocusLock
*/
export function useFocusController(...shards: HTMLElement[]):FocusControl;
export function useFocusController<Elements extends HTMLElement=HTMLElement>(...shards: ReadonlyArray<HTMLElement | {current:HTMLElement | null}>):FocusControl;

/**
* returns FocusControl over the current FocusLock
Expand Down
11 changes: 6 additions & 5 deletions react-focus-lock.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,30 @@ export type FocusControl = {
* focuses the next element in the scope.
* If active element is not in the scope, autofocus will be triggered first
*/
focusNext(options:FocusOptions):Promise<void>;
focusNext(options?:FocusOptions):Promise<void>;
/**
* focuses the prev element in the scope.
* If active element is not in the scope, autofocus will be triggered first
*/
focusPrev():Promise<void>;
focusPrev(options?:FocusOptions):Promise<void>;
/**
* focused the first element in the scope
*/
focusFirst(options: Pick<FocusOptions,'onlyTabbable'>):Promise<void>;
focusFirst(options?: Pick<FocusOptions,'onlyTabbable'>):Promise<void>;
/**
* focused the last element in the scope
*/
focusLast(options: Pick<FocusOptions,'onlyTabbable'>):Promise<void>;
focusLast(options?: Pick<FocusOptions,'onlyTabbable'>):Promise<void>;
}


/**
* returns FocusControl over the union given elements, one or many
* - can be used outside of FocusLock
* - can accept HTML elements or React Refs
* @see {@link useFocusScope} for use cases inside of FocusLock
*/
export function useFocusController(...shards: HTMLElement[]):FocusControl;
export function useFocusController<Elements extends HTMLElement=HTMLElement>(...shards: ReadonlyArray<HTMLElement | {current:HTMLElement | null}>):FocusControl;

/**
* returns FocusControl over the current FocusLock
Expand Down

0 comments on commit e7cc578

Please sign in to comment.