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

feat(menu): implement search functionality #57

Merged
merged 1 commit into from
Jun 26, 2021

Conversation

alexlafroscia
Copy link
Collaborator

This implements the currently-missing ability to activate menu items by pressing the first (or first few) characters of the menu item's text.

Pros:

  • Implements a missing feature that the React and Vue versions have

Cons:

  • There is a slight delay when running the tests for this functionality, due to the timeout(350) that clears the search term. This could be resolved by using a different timeout length in a test build, but I don't like to introduce differences in behavior between tests and the "real" implementation unless it's really necessary, and it just doesn't feel that necessary to me in this case.
  • Introduces an additional dependency on ember-concurrency, and I know that @achambers is (rightfully) hesitant to add additional dependencies. I believe this one is justifiable for a handful of reasons, but am happy to re-build this without it if these reasons aren't enough:
    • The host app probably already depends on ember-concurrency due to how common (and useful) it is
    • There's little risk of ember-concurrency going un-maintained in the future due to it's prevalence in the community
    • Getting the logic around cancellation of events and timeouts can be really hard; this is exactly what ember-concurrency is great at! If you look at the logic for the search functionality in the "official" implementations, it is way more complicated than the task-based implementation in this PR.

@GavinJoyce
Copy link
Owner

Thanks for this @alexlafroscia.

👍 on the inclusion of ember-concurrency, I haven't worked on any non-trivial app that didn't use it.

If it hasn't been reviewed by then, I'll give this PR a proper review later today

@GavinJoyce
Copy link
Owner

This is great, thanks!

@GavinJoyce GavinJoyce merged commit 18a3cb2 into GavinJoyce:master Jun 26, 2021
Comment on lines +67 to +80
async function type(selector, value) {
let finalKeyEventProcessing;

for (const char of value) {
finalKeyEventProcessing = triggerKeyEvent(
selector,
'keydown',
char.toUpperCase()
);
}

await finalKeyEventProcessing;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to throw an explanation in here, since this is a little weird:

We need a custom way to trigger a sequence of key events because Ember's fillIn and typeIn helpers reject sending input to an element that isn't an input or contenteditable.

We only want to await the final key event, otherwise we will wait the 350ms after each event for the search term to be cleared, which is not what we want.

I tried to implement the Ember Concurrency task using rawTimeout (which the tests will not wait for) but then ran into a problem where it's quite for the test to wait for the search term to clear when we do want it to, since in some tests we search for multiple items in a row.

TL;DR: I tried to clean this up but the other approaches I could think of didn't actually work in practice!

@alexlafroscia alexlafroscia mentioned this pull request Jun 26, 2021
4 tasks
@achambers
Copy link
Collaborator

👍 on the inclusion of ember-concurrency, I haven't worked on any non-trivial app that didn't use it.

💯 has my support too

@achambers achambers added the enhancement New feature or request label Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants