-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44685d8
commit 858450c
Showing
7 changed files
with
139 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chialab/loock': minor | ||
--- | ||
|
||
Add focus manager to behaviors. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { findFocusableByOptions } from './findFocusableChildren'; | ||
|
||
export interface FocusManagerOptions { | ||
/** | ||
* The focusable elements. | ||
*/ | ||
elements?: HTMLElement[] | (() => HTMLElement[]); | ||
/** | ||
* The selectors for focusable nodes. | ||
*/ | ||
include?: string[]; | ||
/** | ||
* The selectors for ignored nodes. | ||
*/ | ||
exclude?: string[]; | ||
} | ||
|
||
export function focusManager(node: HTMLElement, options: FocusManagerOptions = {}) { | ||
return { | ||
findFocusable() { | ||
return findFocusableByOptions(node, options); | ||
}, | ||
|
||
/** | ||
* Focus the first focusable child. | ||
*/ | ||
focusFirst() { | ||
this.findFocusable().shift()?.focus(); | ||
}, | ||
|
||
/** | ||
* Focus the last focusable child. | ||
*/ | ||
focusLast() { | ||
this.findFocusable().pop()?.focus(); | ||
}, | ||
}; | ||
} |
Oops, something went wrong.