summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOliver <oliver@mohlin.dev>2025-10-07 06:56:12 +0200
committerTobias Järvelöv <tobias.jarvelov@mullvad.net>2025-10-07 11:35:59 +0200
commitf29ef10f4802c3c8f67c2660a4374035cffcfe57 (patch)
tree82bbb41edcc517f880be11dbbbd1110a18826e24
parentccb2ca36609d235cef494f0ddb1e2570bf90c29e (diff)
downloadmullvadvpn-f29ef10f4802c3c8f67c2660a4374035cffcfe57.tar.xz
mullvadvpn-f29ef10f4802c3c8f67c2660a4374035cffcfe57.zip
Rename option focus hook and move to separate folder
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/components/settings-listbox/components/split-option/SplitOption.tsx4
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/components/listbox/components/listbox-options/ListboxOptions.tsx4
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/index.ts5
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/index.ts1
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/hooks/index.ts2
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/hooks/use-focus-option-by-index.ts (renamed from desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-focus-option-by-index.ts)2
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/hooks/use-get-initial-focus-index.ts (renamed from desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-get-initial-focus-index.ts)2
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/index.ts1
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/use-handle-options-keyboard-navigation.ts (renamed from desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-handle-options-keyboard-navigation.ts)5
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/index.ts1
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/use-roving-focus.ts (renamed from desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-options.ts)13
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-initial-option.ts (renamed from desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-initial-option.ts)0
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-is-option-selected.ts (renamed from desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-is-option-selected.ts)0
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-options.ts (renamed from desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-options.ts)0
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-selected-option-index.ts (renamed from desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-selected-option-index.ts)0
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-selected-option.ts (renamed from desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-selected-option.ts)0
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/index.ts (renamed from desktop/packages/mullvad-vpn/src/renderer/lib/utils/index.ts)3
17 files changed, 21 insertions, 22 deletions
diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/settings-listbox/components/split-option/SplitOption.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/settings-listbox/components/split-option/SplitOption.tsx
index 20f14319eb..7e7b69867e 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/components/settings-listbox/components/split-option/SplitOption.tsx
+++ b/desktop/packages/mullvad-vpn/src/renderer/components/settings-listbox/components/split-option/SplitOption.tsx
@@ -3,7 +3,7 @@ import React from 'react';
import { Flex } from '../../../../lib/components';
import { Listbox } from '../../../../lib/components/listbox';
import { ListboxOptionProps } from '../../../../lib/components/listbox/components';
-import { useOptions } from '../../../../lib/hooks';
+import { useRovingFocus } from '../../../../lib/hooks';
import { SplitOptionItem, SplitOptionNavigateButton } from './components';
export type SplitOptionProps<T> = ListboxOptionProps<T>;
@@ -11,7 +11,7 @@ export type SplitOptionProps<T> = ListboxOptionProps<T>;
function SplitOption<T>({ children, ...props }: SplitOptionProps<T>) {
const optionsRef = React.useRef<HTMLDivElement>(null);
const [focusedIndex, setFocusedIndex] = React.useState<number | undefined>(undefined);
- const { handleKeyboardNavigation, handleBlur, handleFocus } = useOptions({
+ const { handleKeyboardNavigation, handleBlur, handleFocus } = useRovingFocus({
optionsRef,
orientation: 'horizontal',
selector: '[data-split-button="true"]:not([aria-disabled="true"])',
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/components/listbox/components/listbox-options/ListboxOptions.tsx b/desktop/packages/mullvad-vpn/src/renderer/lib/components/listbox/components/listbox-options/ListboxOptions.tsx
index 0a4d36ab40..902cd8d790 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/components/listbox/components/listbox-options/ListboxOptions.tsx
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/components/listbox/components/listbox-options/ListboxOptions.tsx
@@ -1,6 +1,6 @@
import React from 'react';
-import { useOptions } from '../../../../hooks';
+import { useRovingFocus } from '../../../../hooks';
import { useListboxContext } from '../../';
export type ListboxOptionsProps = {
@@ -9,7 +9,7 @@ export type ListboxOptionsProps = {
export function ListboxOptions({ children }: ListboxOptionsProps) {
const { labelId, optionsRef, focusedIndex, setFocusedIndex } = useListboxContext();
- const { handleFocus, handleKeyboardNavigation, handleBlur, tabIndex } = useOptions({
+ const { handleFocus, handleKeyboardNavigation, handleBlur, tabIndex } = useRovingFocus({
focusedIndex,
optionsRef,
setFocusedIndex,
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/index.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/index.ts
index ca824aae46..e75fe95d06 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/index.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/index.ts
@@ -1,5 +1,2 @@
export * from './use-exclusive-task';
-export * from './use-focus-option-by-index';
-export * from './use-get-initial-focus-index';
-export * from './use-handle-options-keyboard-navigation';
-export * from './use-options';
+export * from './use-roving-focus';
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/index.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/index.ts
new file mode 100644
index 0000000000..b5c80ee105
--- /dev/null
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/index.ts
@@ -0,0 +1 @@
+export * from './use-handle-options-keyboard-navigation';
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/hooks/index.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/hooks/index.ts
new file mode 100644
index 0000000000..e0ca5fa2e3
--- /dev/null
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/hooks/index.ts
@@ -0,0 +1,2 @@
+export * from './use-focus-option-by-index';
+export * from './use-get-initial-focus-index';
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-focus-option-by-index.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/hooks/use-focus-option-by-index.ts
index bc60b0bb70..6b68003df9 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-focus-option-by-index.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/hooks/use-focus-option-by-index.ts
@@ -1,6 +1,6 @@
import React from 'react';
-import { getOptions } from '../utils';
+import { getOptions } from '../../../utils';
export const useFocusOptionByIndex = <T extends HTMLElement>({
optionsRef,
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-get-initial-focus-index.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/hooks/use-get-initial-focus-index.ts
index 3744725990..1c0070fba0 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-get-initial-focus-index.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/hooks/use-get-initial-focus-index.ts
@@ -1,6 +1,6 @@
import React from 'react';
-import { getOptions, getSelectedOptionIndex } from '../utils';
+import { getOptions, getSelectedOptionIndex } from '../../../utils';
export const useGetInitialFocusIndex = <T extends HTMLElement>({
focusedIndex,
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/index.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/index.ts
new file mode 100644
index 0000000000..b5c80ee105
--- /dev/null
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/index.ts
@@ -0,0 +1 @@
+export * from './use-handle-options-keyboard-navigation';
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-handle-options-keyboard-navigation.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/use-handle-options-keyboard-navigation.ts
index 46862e8f81..5b39b71434 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-handle-options-keyboard-navigation.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/hooks/use-handle-options-keyboard-navigation/use-handle-options-keyboard-navigation.ts
@@ -1,8 +1,7 @@
import React from 'react';
-import { getOptions } from '../utils';
-import { useFocusOptionByIndex } from './use-focus-option-by-index';
-import { useGetInitialFocusIndex } from './use-get-initial-focus-index';
+import { getOptions } from '../../utils';
+import { useFocusOptionByIndex, useGetInitialFocusIndex } from './hooks';
export type KeyboardNavigationOrientation = 'horizontal' | 'vertical';
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/index.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/index.ts
new file mode 100644
index 0000000000..4fe1d09b41
--- /dev/null
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/index.ts
@@ -0,0 +1 @@
+export * from './use-roving-focus';
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-options.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/use-roving-focus.ts
index 506a7846f9..b7f0b264e0 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-options.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/use-roving-focus.ts
@@ -1,12 +1,9 @@
import React from 'react';
-import { getInitialOption, getOptions } from '../utils';
-import {
- KeyboardNavigationOrientation,
- useHandleOptionsKeyboardNavigation,
-} from './use-handle-options-keyboard-navigation';
+import { type KeyboardNavigationOrientation, useHandleOptionsKeyboardNavigation } from './hooks';
+import { getInitialOption, getOptions } from './utils';
-export type UseOptionsProps<T extends HTMLElement> = {
+export type UseRovingFocusProps<T extends HTMLElement> = {
optionsRef: React.RefObject<T | null>;
focusedIndex?: number;
setFocusedIndex: React.Dispatch<React.SetStateAction<number | undefined>>;
@@ -14,13 +11,13 @@ export type UseOptionsProps<T extends HTMLElement> = {
orientation?: KeyboardNavigationOrientation;
};
-export function useOptions<T extends HTMLElement>({
+export function useRovingFocus<T extends HTMLElement>({
optionsRef,
focusedIndex,
setFocusedIndex,
selector,
orientation = 'vertical',
-}: UseOptionsProps<T>) {
+}: UseRovingFocusProps<T>) {
const [tabIndex, setTabIndex] = React.useState<number>(0);
const handleFocus = React.useCallback(
(event: React.FocusEvent) => {
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-initial-option.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-initial-option.ts
index e2278b5237..e2278b5237 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-initial-option.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-initial-option.ts
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-is-option-selected.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-is-option-selected.ts
index 6433e20232..6433e20232 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-is-option-selected.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-is-option-selected.ts
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-options.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-options.ts
index 0754a72631..0754a72631 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-options.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-options.ts
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-selected-option-index.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-selected-option-index.ts
index 2534ef46d1..2534ef46d1 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-selected-option-index.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-selected-option-index.ts
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-selected-option.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-selected-option.ts
index dfed49aae7..dfed49aae7 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/get-selected-option.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/get-selected-option.ts
diff --git a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/index.ts b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/index.ts
index cbd0929620..fc4f9891f9 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/lib/utils/index.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/lib/hooks/use-roving-focus/utils/index.ts
@@ -1,4 +1,5 @@
-export * from './get-initial-option';
+export * from './get-is-option-selected';
export * from './get-options';
+export * from './get-initial-option';
export * from './get-selected-option-index';
export * from './get-selected-option';