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

Update useInput() to include name in key #674

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

depeele
Copy link

@depeele depeele commented Sep 26, 2024

Some key values (e.g. 'insert', 'home', 'end') were basically lost. In these cases, the input value would be an empty string and the generated key data would contain no additional information about the value.

To resolve this, directly include keypress.name in the generated key data so this information is not lost.

Some key values (e.g. 'insert', 'home', 'end') were basically lost. In
these cases, the `input` value would be an empty string and the
generated `key` data would contain no additional information about the
value.

To resolve this, directly include `keypress.name` in the generated `key`
data so this information is not lost.
@sindresorhus
Copy link
Collaborator

Check if any types / docs needs to be updated.

Update the `Key` type in src/hooks/use-input.ts to include the new
`name` field.

Update `useInput()` documentation for theh `inputHandler()` callback to
include a description of the new `key.name`.
@depeele
Copy link
Author

depeele commented Sep 26, 2024

Check if any types / docs needs to be updated.

OK. I've update:

  • the Key type in src/hooks/use-input.ts to include the new name field;
  • documentation for the inputHandler() callback for useInput() to include a description of the new key.name;

For cases where `parseKeypress()` does not provide `keypress.name` *and*
`input` is not empty, set `keypress.name` to `input`.
@sindresorhus
Copy link
Collaborator

I wonder if it would be better to instead expose a .special property, similar to: https://developer.apple.com/documentation/appkit/nsevent/specialkey

It's kinda weird to mix one letter presses like a with, for example, home.

We could then even strongly type the property with the supported names: special: 'f1' | 'f2';

readme.md Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

2 participants