Skip to main content

useSetFocus

Used to set accessibility focus on a specified element.

Submit feedback
github
import { useSetFocus } from '@uhg-abyss/mobile';

Usage

The hook returns a function that consumes a ref object. Simply call said function to set the screen reader focus.

const setFocus = useSetFocus();
const myRef = useRef(null);
return (
<>
<Button
onPress={() => {
return setFocus(myRef);
}}
>
Focus Link
</Button>
<Link href="google.com" ref={myRef}>
Link to be focused
</Link>
</>
);

Example

In the example below, Android's Talkback can be seen focusing the bottom text when the Focus Text button is pressed.

Table of Contents