dan-lee / timescape

A flexible, headless date and time input library for JavaScript. Provides tools for building fully customizable date and time input fields, with support for libraries like React, Preact, Vue, Svelte and Solid.
https://timescape.daniellehr.de
MIT License
153 stars 2 forks source link

Enter key event not triggering #43

Closed iamrakhmatov closed 1 day ago

iamrakhmatov commented 3 days ago

When pressing Enter key onKeyDown event is not triggering, I need this event because I want to change behavior for Enter key, right now when it's clicked focus just moves to the next segment, but I want to propagate the event to parent component and blur the component

dan-lee commented 2 days ago

So basically you want to have

<input onKeyDown={(e) => { e.target.blur(); }} />

Do I understand that correctly? I guess it has to do with this library calling preventDefault, but not too sure yet. Would need to investigate

dan-lee commented 1 day ago

You should be able to do so now in https://github.com/dan-lee/timescape/releases/tag/timescape@0.6.2, but you need to use onKeyDownCapture for it to work:

<input
  onKeyDownCapture={(e) => {
    if (e.key === 'Enter') {
      e.preventDefault()
    }
  }}
/>