Skip to content

useFocusable

function useFocusable(options?): UseFocusableResult;

Hook to make any element focusable with keyboard support.

ParameterType
optionsUseFocusableOptions

UseFocusableResult

function CustomPicker({ onSelect }) {
const { ref, isFocused, focus } = useFocusable({
onKeyPress: (key) => {
if (key.name === "return") {
onSelect();
return true;
}
return false;
},
});
return (
<Box
ref={ref}
focusable
style={{
border: "round",
borderColor: isFocused ? "cyan" : "gray"
}}
>
<Text>Custom Picker</Text>
</Box>
);
}

PropertyTypeDescription
disabled?booleanWhether the element is currently disabled (skipped in tab order)
onBlur?() => voidCalled when the element loses focus
onFocus?() => voidCalled when the element receives focus
onKeyPress?(key) => boolean | voidKey handler when focused. Return true to consume the key. This runs after priority handlers but before global handlers.

PropertyTypeDescription
blur() => voidProgrammatically blur (unfocus) this element
focus() => voidProgrammatically request focus on this element
focusIdstring | nullThe focus ID (useful for conditional logic)
isFocusedbooleanWhether this element is currently focused
ref(node) => voidRef to attach to your focusable element