Skip to content

Commit

Permalink
flixed hooks order
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorjjb committed Feb 21, 2025
1 parent 0e98230 commit 4cffdf6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import { InputMode } from '../types/InputMode';
import { GamepadState } from '../types/Keys';
import { consolePrefix } from '../core/Constants';
Expand Down Expand Up @@ -194,6 +193,8 @@ export type GamepadNavigationOptions = {
export const useGamepadNavigation = (options: GamepadNavigationOptions) => {
const { targetDocument } = options;
const defaultView = targetDocument?.defaultView;
const windowId = useId('window');

if (
typeof targetDocument === 'undefined' ||
typeof defaultView === 'undefined'
Expand All @@ -208,7 +209,7 @@ export const useGamepadNavigation = (options: GamepadNavigationOptions) => {
if (!shadowDOMAPI) {
shadowDOMAPI = {
gamepadInitialized: false,
windowId: useId('window'),
windowId,
};
}
// Don't try to initialize multiple times
Expand Down Expand Up @@ -294,10 +295,8 @@ export const useGamepadNavigation = (options: GamepadNavigationOptions) => {
onTargetWindowFocus,
};
shadowDOMAPI.eventHandlers = eventHandlers;
const removeEventListeners = React.useCallback(
() => removeGamepadNavigationEventListener(targetDocument, eventHandlers),
[targetDocument]
);
const removeEventListeners = () =>
removeGamepadNavigationEventListener(targetDocument, eventHandlers);
shadowDOMAPI.removeEventListeners = removeEventListeners;
(defaultView as WindowWithFluentGPNShadowDOMAPI).__FluentGPNShadowDOMAPI =
shadowDOMAPI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,29 @@ export const useGamepadNavigationGroup = (
pollingEnabled,
};

const removeGamepadNavEventListeners = useGamepadNavigation(gpnProps);

React.useEffect(() => {
if (focusFirstElement) {
findFirstFocusable(targetDocument?.activeElement as HTMLElement)?.focus();
}
}, []);

const moverAttr = useArrowNavigationGroup({
const groupperDOMAttribute = useFocusableGroup({
tabBehavior,
ignoreDefaultKeydown,
});
const moverDOMAttribute = useArrowNavigationGroup({
axis,
circular,
memorizeCurrent,
tabbable,
ignoreDefaultKeydown,
unstable_hasDefault,
});
const groupperAttr = useFocusableGroup({ tabBehavior, ignoreDefaultKeydown });
const gamepadNavDOMAttributes = useMergedTabsterAttributes_unstable(
moverAttr,
groupperAttr
groupperDOMAttribute,
moverDOMAttribute
);
const removeGamepadNavEventListeners = useGamepadNavigation(gpnProps);

return {
gamepadNavDOMAttributes,
Expand Down

0 comments on commit 4cffdf6

Please sign in to comment.