Skip to content

Commit

Permalink
feat: add focus options in conjunction with shouldFocusDOMNode (#139)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Cohen <Max.Cohen@mlb.com>
  • Loading branch information
cohenmax9 and maxcohenmlb authored Aug 20, 2024
1 parent a708581 commit 4a290ab
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/SpatialNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ class SpatialNavigationService {
*/
private parentsHavingFocusedChild: string[];

/**
* When shouldFocusDOMNode is true, this prop specifies the focus options that should be passed to the element being focused.
*/
private domNodeFocusOptions: FocusOptions;

private enabled: boolean;

/**
Expand Down Expand Up @@ -544,6 +549,7 @@ class SpatialNavigationService {
*/
this.parentsHavingFocusedChild = [];

this.domNodeFocusOptions = {};
this.enabled = false;
this.nativeMode = false;
this.throttle = 0;
Expand Down Expand Up @@ -596,10 +602,12 @@ class SpatialNavigationService {
throttleKeypresses = false,
useGetBoundingClientRect = false,
shouldFocusDOMNode = false,
domNodeFocusOptions = {},
shouldUseNativeEvents = false,
rtl = false
} = {}) {
if (!this.enabled) {
this.domNodeFocusOptions = domNodeFocusOptions;
this.enabled = true;
this.nativeMode = nativeMode;
this.throttleKeypresses = throttleKeypresses;
Expand Down Expand Up @@ -1385,7 +1393,7 @@ class SpatialNavigationService {
const newComponent = this.focusableComponents[this.focusKey];

if (this.shouldFocusDOMNode && newComponent.node) {
newComponent.node.focus();
newComponent.node.focus(this.domNodeFocusOptions);
}

newComponent.onUpdateFocus(true);
Expand Down

0 comments on commit 4a290ab

Please sign in to comment.