what-input icon indicating copy to clipboard operation
what-input copied to clipboard

expose `doUpdate` to API

Open dailyraisin opened this issue 6 years ago • 5 comments

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.

dailyraisin avatar May 01 '18 13:05 dailyraisin

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

ten1seven avatar May 02 '18 13:05 ten1seven

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

sophieH29 avatar Nov 05 '18 17:11 sophieH29

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');

ten1seven avatar Nov 09 '18 21:11 ten1seven

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 avatar Nov 20 '18 17:11 sophieH29

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

sophieH29 avatar Nov 26 '18 09:11 sophieH29