-
-
Notifications
You must be signed in to change notification settings - Fork 619
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
Add useFocus
hook to manage input focus
#242
Comments
possibly related: jdeniau/ink-tab#14 |
As you noted, you'd need to use |
useFocus
hook to manage input focus
I think it's a good approach that ink manage the focus, as does a web browser 👍 |
@vadimdemedes I started working on this here : https://github.com/jdeniau/ink-focus-demo (demo.js) There is still some work to do though, like how to make "inputs" non-responsive to focus-changer key (tab + shift-tab?), managing "tabIndex", and eventually in the future why not attach I think I found bugs whith keypress in the same time (due to the change of keypress paradigm in 2.4.0 I think), I will try to open PRs on that. The external API is a little too complex I think (register a ref and use it after that in As a matter of fact, I do not like the "ref" approach that I used but I did not really think of another viable solution. I think it is a good start to keep a global focus state. I will try to work on this more and make a PR whenever possible. |
@vadimdemedes I have a working version on https://github.com/jdeniau/ink-focus-demo now. The API is the following : import TextInputWithoutFocus from "ink-text-input";
import { withFocus } from "ink";
const TextInput = withFocus(TextInputWithoutFocus); The wrapped component will receive a Ink should then manage focus between every focusable elements. App.js You can switch between focusable elements by pressing "tab" or "shift+tab" There is one "problem" I still see before making a PR : |
I have had only rough ideas for |
I checked out your repo and it's really good, very similar to what I had in mind. The only difference would be that I'd prefer users to use
Good point, not sure what's the ideal solution here. One way to solve this would be to let text inputs that expect "Tab" to disable focus switching? It's not perfect, but I don't think majority of text inputs would expects those. |
Thanks!
I think it will do the trick.
I haven't stop thinking about this, and I think the ideal solution would be
to implement the same pattern as the browser do and thus I'm not fully
satisfied withmy implementation.
As I don't want to push code that might imply a breaking change soon, I
preferred keep thinking about it.
Le dim. 16 févr. 2020 à 13:02, Vadim Demedes <[email protected]> a
écrit :
… I checked out your repo and it's really good, very similar to what I had
in mind. The only difference would be that I'd prefer users to use
useFocus hook directly instead of withFocus HOC.
don't see a way to make the wrapped component unresponsive to keyboard
input. That's why we need the focus prop, but there still is a conflict
with the "tab" key
Good point, not sure what's the ideal solution here. One way to solve this
would be to let text inputs that expect "Tab" to disable focus switching?
It's not perfect, but I don't think majority of text inputs would expects
those.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#242?email_source=notifications&email_token=AAKVNRMA5XORBVZCNILUZW3RDETNTA5CNFSM4JNBSNH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL4E47Y#issuecomment-586698367>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKVNRL427GKMECVYDZYSGLRDETNTANCNFSM4JNBSNHQ>
.
|
As I re-read my code about that, I think we might expose both Another way around is to return a ref that you might inject in your component this way: function FooInput() {
const [hasFocus, ref] = useFocus(possibleRef);
} but that seems really really weird 🙃 |
I managed to remove the As soon as I manage to handle the |
This would be really awesome. I feel right now I have to reinvent the wheel here to do this. |
Ink 3 is out with the fix for this issue included! Read the full announcement at https://vadimdemedes.com/posts/ink-3 :) |
Do you have any recommandation for managing focus for multiple input component.
My current use case is to be able to display multiple SelectInput and be able to tab thru them. The component already have a focus prop, but how would I manage the focus when the multiple SelectInput are not within the same react component?
The text was updated successfully, but these errors were encountered: