adopted-ember-addons/ember-keyboard

Breaks search autofocus in ember-power-select (and likely other global handlers)

dfreeman opened this issue · 4 comments

Without a changelog it's a little difficult to tell what the history is behind this, but it this commit (specifically this line) seems to be impacting other registered global event handlers. In particular, the breakage that led me here was with ember-power-select—when yarn bumped us to ember-keyboard@2.3.0 as part of updating some other dependencies, power-select's search fields stopped focusing on open.

After spending the better part of the afternoon figuring out what was even causing the issue, I put together a simple reproduction here: dfreeman/ember-keyboard-power-select-issue@826053b

I'm aware that I can force the service back to only listening to key events by updating emberKeyboard.listeners in my app config, but that gets hairy quickly as we'd also need to make the same configuration update to the various engines our app uses as well. It's also a little odd to me that an addon that's nominally about keyboard-related things is installing global handlers for mouse and touch events — it certainly didn't make tracking down the source of this issue any easier 😉.

Sorry this took a good chunk of you afternoon, @dfreeman. I appreciate you putting together a demo of the issue though. I'll look into it first thing tomorrow.

As for why ember-keyboard is handling mouse and touch events, that's because this addon isn't simply responding to key events, but managing which components will respond when a key event occurs. There are cases where the dev will want mouse/touch events to respond in lock-step with key events. That is, if a component's key responders are deactivated, so should its touch/mouse events. This isn't functionality that everyone needs, but if you do need it, ember-keyboard allows you to handle those situations in a way that consistent across most forms of user interaction.

Still, I agree it's unexpected to have an addon called ember-keyboard tracking mouse and touch events, and it looks like that's made life harder for at least one dev (and probably more). Considering that, it might be worth removing this functionality from ember-keyboard and forking a new project that's named appropriately.

The issue should be resolved on v3.0.0. Since the issue was happening with a jQuery listener, this seemed like a good time to remove jQuery and use vanilla listeners instead, as part of the broader "make jQuery optional" push. Since this means that the keyboard events will no longer be jQuery events, this could be a breaking change for some devs, ergo the major release.

I also made the mouse/touch events opt-in. While they might still seem like feature bloat to some, they should at least be out of the way now. They should also be compatible with ember-power-select at this point, so please feel free to try them out if you're interested.

Either way, thanks for bringing this to my attention, @dfreeman. Let me know if you experience any further difficulties with 3.0.0.

@patience-tema-baron Thanks so much for the quick turnaround here, and for all your work on this addon! Definitely interested to try out the mouse/touch events in the future 🙂

Of course! And thanks for your own contributions throughout the Ember community.