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

Add KeyboardEvent goodness to easily bind to key press events #93

Closed
Zaid-Ajaj opened this issue Nov 2, 2019 · 6 comments
Closed

Add KeyboardEvent goodness to easily bind to key press events #93

Zaid-Ajaj opened this issue Nov 2, 2019 · 6 comments
Labels
Feliz Issues related to Feliz good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Zaid-Ajaj
Copy link
Owner

Zaid-Ajaj commented Nov 2, 2019

I was thinking of adding a nice way to bind to keyboard events, something like the following would be really awesome:

Scenario 1: bind to a single key event (most common use-case)

Html.input [
    prop.onKeyUp(key.enter, fun _ -> dispatch Login)
    prop.onChange (UsernameChanged >> dispatch)
    prop.valueOrDefault state.Username
]

Scenario 2.1: bind to multiple keys

Html.input [
    prop.onKeyUp [ key.enter, fun _ -> dispatch Login ]
    prop.onChange (UsernameChanged >> dispatch)
    prop.valueOrDefault state.Username
]

Scenario 2.2: bind to multiple keys

Html.input [
    prop.onKeyUp(dispatch, [ key.enter, Login; key.esc, Reset ])
    prop.onChange (UsernameChanged >> dispatch)
    prop.valueOrDefault state.Username
]

This is up for grabs! PRs are very much welcome, let me and other contributors know if you want to take a stab at it

@Zaid-Ajaj Zaid-Ajaj added help wanted Extra attention is needed good first issue Good for newcomers Feliz Issues related to Feliz labels Nov 2, 2019
@cmeeren
Copy link
Contributor

cmeeren commented Nov 2, 2019

Ooh, nice, I like how you're thinking!

IMHO Key reads better than Keys, i.e. Key.Enter vs. Keys.Enter.

@Zaid-Ajaj
Copy link
Owner Author

@cmeeren You are right, to keep it consistent, we have been using a singular word for modules prop, style and key (lower-cased) would be a natural addition 👍

@cmeeren
Copy link
Contributor

cmeeren commented Nov 2, 2019

Yep, though I have noticed that we have colors and now fonts... Something to consider changing. :)

@Zaid-Ajaj
Copy link
Owner Author

@cmeeren Made an issue about colors and fonts at #95

Refinement of the proposal

Scenario 2.2 is inconsistent with the rest of the event handlers because it means we should also implement onClick(dispatch, Login) and most likely we won't (feedback and discussion is welcome of course)

As for scenario 1 and scenario 2, the event handlers in there should accept the KeyboardEvent as argument for the lambda (along side the key). i.e. the keyboard events will take the overloads:

KeyboardEvent -> unit // default
IKeyboardKey * (KeyboardEvent -> unit) // scenario 1
(IKeyboardKey * (KeyboardEvent -> unit)) list // scenario 2

@cmeeren
Copy link
Contributor

cmeeren commented Nov 2, 2019

Looks good to me. The proof is in the pudding, though. Let's see how it feels in use. :)

@Zaid-Ajaj Zaid-Ajaj mentioned this issue Mar 12, 2020
8 tasks
@Zaid-Ajaj
Copy link
Owner Author

Keyboard goodness added:

// Enter only
prop.onKeyUp (key.enter, fun _ -> dispatch Login)
// Enter + CTRL
prop.onKeyUp (key.ctrl(key.enter), fun _ -> dispatch Login)
// Enter + SHIFT
prop.onKeyUp (key.shift(key.enter), fun _ -> dispatch Login)
// Enter + CTRL + SHIFT
prop.onKeyUp (key.ctrlAndShift(key.enter), fun _ -> dispatch Login)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feliz Issues related to Feliz good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants