New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When setting a focus by default it can never be changed #515
Comments
After some more experiments, it looks as if the component is re-rendered when pressing "tab", so that's why it goes back to the initial focus status, it kind of makes sense, but how to work around this issue? |
Ok, the solution is simply to use the "autoFocus" property. I paste here the code as a reference for others: const Item = ({ label, id }: { label: string; id: string }) => {
const { isFocused } = useFocus({ id, autoFocus: id === "1" });
return (
<Text>
{label} {isFocused && <Text color="green">(focused)</Text>}
</Text>
);
}; |
Going to re-open this one to investigate later. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider this code based on the example code https://github.com/vadimdemedes/ink/tree/master/examples/use-focus-with-id:
When running the app it will show the following:
However, it is not possible to change focus now, neither with "tab" nor with the number keys 1,2,3, the focus is actually changed but jumps back directly to the initial component with id === "1".
I have tried to put the call to focus inside the useEffect hook with the exact same results:
Any ideas, or is this just a bug?
The text was updated successfully, but these errors were encountered: