diff options
| author | Oliver <oliver@mohlin.dev> | 2025-10-02 07:04:51 +0200 |
|---|---|---|
| committer | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-10-03 10:00:12 +0200 |
| commit | 43abc1a78718d25008ac6e5ae47dc196cb3cfddb (patch) | |
| tree | 961a35d8d5a7f2469a7915f26d80ae2180dbdbe2 | |
| parent | ab2f9a8c79d8cce7207a54b84e71566fb6746712 (diff) | |
| download | mullvadvpn-43abc1a78718d25008ac6e5ae47dc196cb3cfddb.tar.xz mullvadvpn-43abc1a78718d25008ac6e5ae47dc196cb3cfddb.zip | |
Use useFocusReferenceBeforePaint in Searchbar component
| -rw-r--r-- | desktop/packages/mullvad-vpn/src/renderer/components/SearchBar.tsx | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/SearchBar.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/SearchBar.tsx index de0c36902e..dcefbdff7e 100644 --- a/desktop/packages/mullvad-vpn/src/renderer/components/SearchBar.tsx +++ b/desktop/packages/mullvad-vpn/src/renderer/components/SearchBar.tsx @@ -1,10 +1,11 @@ -import { useCallback, useEffect } from 'react'; +import { useCallback } from 'react'; import styled from 'styled-components'; import { messages } from '../../shared/gettext'; +import { useFocusReferenceBeforePaint } from '../hooks'; import { Icon, IconButton } from '../lib/components'; import { colors } from '../lib/foundations'; -import { useEffectEvent, useStyledRef } from '../lib/utility-hooks'; +import { useStyledRef } from '../lib/utility-hooks'; import { normalText } from './common-styles'; export const StyledSearchContainer = styled.div({ @@ -76,6 +77,7 @@ export default function SearchBar(props: ISearchBarProps) { const { disabled, onSearch } = props; const inputRef = useStyledRef<HTMLInputElement>(); + useFocusReferenceBeforePaint(inputRef, !props.disableAutoFocus); const onInput = useCallback( (event: React.FormEvent) => { @@ -90,19 +92,6 @@ export default function SearchBar(props: ISearchBarProps) { inputRef.current?.blur(); }, [inputRef, onSearch]); - const focusInput = useEffectEvent(() => { - if (!props.disableAutoFocus) { - inputRef.current?.focus({ preventScroll: true }); - } - }); - - // These lint rules are disabled for now because the react plugin for eslint does - // not understand that useEffectEvent should not be added to the dependency array. - // Enable these rules again when eslint can lint useEffectEvent properly. - // eslint-disable-next-line react-compiler/react-compiler - // eslint-disable-next-line react-hooks/exhaustive-deps - useEffect(() => focusInput(), []); - return ( <StyledSearchContainer className={props.className}> <StyledSearchInput |
