-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
How to use v6 modifiers version to not trigger when textarea is focused? #212
Comments
Hi @st-h, I'm happy to look into this and I appreciate the repro repo. However, I cloned the repo and it seems to be a new empty ember app. Maybe you missed committing something? |
@lukemelia sorry. Yes, that was the case. Should be fine now. I also tried to call stopPropagation etc on the keyup event of the textfield, but that seems to be triggered after ember-keyboard has received the event. Probably that could be worked around with the priorities, but at that point I stopped to look into it further - because having to intercept all events of all input elements would be too error prone and would mean too many changes to our app (having to add event handlers where everything would previous work out of the box). |
Thanks, @st-h. The repo made it a lot easier to consider. My thoughts:
<textarea {{on-key firstResponder=true}}>hello</textarea> The
|
@lukemelia Thanks for the explanation. The things that tripped me were, that in a few places it is mentioned that native input and textarea elements should be used and that the initialiser is no longer needed. It made the impression that we can now replace embers input helpers with native elements and ember-keyboard would continue its previous behaviour. I would really like to see this behaviour work automagically again. Otherwise, each input or Textelement added where one would forget to add the firstResponder would result in odd user behaviour, which is hard to detect in advance. It would be awesome if this could work for elements with contenteditable enabled as well. |
@st-h All makes sense. Would you be up for creating a documentation PR to try to improve the clarity for future people in your situation? I'll give some further thought to how to create an automatic solution that works with native elements. I'm open to ideas from you or others reading this issue, too. |
@lukemelia I was looking into this again today, as I was trying to introduce native inputs to our app and quickly noticed that this would cause issues with v5. I think we can solve this issue by checking the event target - possibly in Now if Additionally we should check for We could put this behind a flag (that is enabled per default), so people can bail out if they need to intercept their input fields or want to add firstResponders manually. What do you think? If you have some time to quickly look at this, I think I can put some more time aside today to try it out and put together a PR. |
@lukemelia I just tested an augmented version of the
Which seems to work quite fine. I just couldn't figure out why there is no Does this look like a viable approach to you? If you so, I'll happily submit a PR. What do you think about making it configurable? Probably we could even add a modifier, which can be applied to an input, which would skip the check if the current element is an input (so, one would have to specify which input should be taking into account instead of having to apply firstResponder to all elements that shouldn't)? |
@st-h I think this approach has potential, but in cases where an |
@lukemelia I think this sounds like the right solution. Do not use events from any input elements, unless there is an |
@st-h sounds good. please make this change opt-in as well, so that we can release it without cutting a major version. |
I think this will cause a lot less confusion if it is opt-out and come with a major release. But is there even a good reason/practical use case to opt out of that behaviour? I can only think of someone wanting to intercept ALL the input fields within their app, which seems quite ridiculous to me (and there are much better ways to achieve something like that). Additionally making it not opt in would be much closer to previous versions, which would handle those things automatically. |
The smoothest upgrade path would be to release it as opt-in with a minor
version, and include a deprecation warning until the user explicitly opts
in or opts out. Then the next major can flip the default and remove the
deprecation warning.
…On Tue, Nov 10, 2020 at 6:54 PM Steve ***@***.***> wrote:
@st-h <https://github.com/st-h> sounds good. please make this change
opt-in as well, so that we can release it without cutting a major version.
I think this will cause a lot less confusion if it is opt-out and come
with a major release. But is there even a good reason/practical use case to
opt out of that behaviour? I can only think of someone wanting to intercept
ALL the input fields within their app, which seems quite ridiculous to me
(and there are much better ways to achieve something like that).
Additionally making it not opt in would be much closer to previous
versions, which would handle those things automatically.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#212 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAACYJHTDRZ4JAT55ANNA3SPELXTANCNFSM4PE7AQKQ>
.
|
@lukemelia sorry, I've been very short on time. Every time I find a bit of time, I find myself looking at the tests trying to figure out a good place where to add a test, so I can implement the missing details (not yet sure how it would be possible to detect if the element has a modifier applied). Could you please suggest which test would be a good one to test that functionality? |
I hate to say it, but the current behaviour also is an issue with scrollable elements. Binding space bar to ember-keyboard and having a scrollable element focused leads to both scrolling and ember-keyboard being triggered simultaneously. |
@lukemelia I've finally revisited this issue. Turns out, my scrolling issue could be easily resolved by adding |
I was also running into this. Looking forward when #557 lands. As a workaround for now I tried as suggested applying Looking at the modifier's code, I also don't see that this alone would prevent any other responders. Also What worked for me is something like this: <input {{on-key "_all" this.ignoreEkEvent}}> // component.js
ignoreEkEvent(_event: Event, ekEvent: Event): void {
ekEvent.stopImmediatePropagation();
} Is this expected? Or do I miss something? |
Until the PR is merged you can use this entry in your package json, which will pull the code from the git branch:
Otherwise, I think stopping propagation on the ekEvent is the right way to do this. |
I am using this addon to allow to use the space bar to stop and start playback of an audio file. When an input/textarea/contenteditable is focused, the event should not be handled by
ember-keyboard
, as every space key would stop or start audio playback.I thought I was able to migrate to the new version without issue, but I just noticed that I am having issues with textareas.
To sum it up shortly:
This is inside the player component to trigger an action when the space key is pressed:
onKey is a simple action:
If I ommit
e.preventDefault()
, every time I hit space both ember-keyboard and the textarea trigger simultaneously.If I make use of
e.preventDefault()
, I can no longer enter spaces into the textarea, but ember-keyboard triggers every time I hit space (no matter where the focus is).From what I read in the docs, textareas should work out of the box? don't they? Am I missing something?
I have quickly add a repo to reproduce here: https://github.com/st-h/ember-keyboard-repro
I also tried to use
e.stopPropagation();
,e.stopImmediatePropagation();
and assigning a priority, but neither worked. Thinking I would need to prevent every input event from being propagated to ember-keyboard, but that sounds like a massive change to larger apps, which also could have additional sideeffects.Isn't it intended that when a textarea is focused,
ember-keyboard
should not handle the event?The text was updated successfully, but these errors were encountered: