Skip to content
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

expose doUpdate to API #80

Open
dailyraisin opened this issue May 1, 2018 · 5 comments
Open

expose doUpdate to API #80

dailyraisin opened this issue May 1, 2018 · 5 comments

Comments

@dailyraisin
Copy link

In cases where one wants to prevent default key events (e.g. stopping, preventDefault), it would be necessary to call doUpdate('intent') manually from the outside as whatInput listeners will not be reached.

@ten1seven
Copy link
Owner

Interesting! That sounds pretty simple to implement. Do you have a scenario that I could create locally to test against when I add this?

@sophieH29
Copy link

Hi, @dailyraisin @ten1seven I am interested in the same feature.
I use React and here is my scenario:

  • onKeyDown handler is called on a component A
  • inside this handler, there is a quite big logic, which at the end finds a particular child component B and focuses it
  • onFocus handler of component B is called where it is checked if the whatInput.ask() === 'keyboard', we will get here false
  • and only afterward the window.addEventListener('keydown') from what-input lib is called and update a state to keyboard but it's too late for me.

It would be very useful to have access to function like setInput, so I can call on initial onKeyDown handler of component B and update the state accordingly.

@ten1seven let me know what you think

@ten1seven
Copy link
Owner

Hi @sophieH29, I'm digging into this request. Are you push a specific input to what-input and trigger a doUpdate? Something like this?

whatInput.setInput('keyboard');

@sophieH29
Copy link

Hi @ten1seven, I would rather say just to make current function setInput public, so I will be able to call it onKeyDown event and update state, like

onKeyDown = (ev) => {
...
whatInput.setInput(ev)
...
}

@sophieH29
Copy link

@ten1seven do you plan to make this update to the library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants