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(selected): Adding context about original event triggering an autocomplete:selected event #267

Merged
merged 1 commit into from
Nov 13, 2018

Conversation

pixelastic
Copy link
Contributor

@pixelastic pixelastic commented Nov 12, 2018

This adds a third parameter to the autocomplete:selected event, an object that contain information about the context in which it was called. It passed a key named selectionMethod that can take any value out of click, enterKey, tabKey or blur.

Using this, we should now be able to detect if the event is coming from a click or not in userland. If it's coming from an click (and the template is a link), we could "do nothing" and fallback to the browser behavior, while still doing our own thing for all the other events.

@pixelastic pixelastic changed the title Adding tests feat(selected): Adding context about original event triggering an autocomplete:selected event Nov 12, 2018
@pixelastic
Copy link
Contributor Author

@s-pace @Jerska @Haroenv @rayrutjes I added you as reviewer because we either discussed the issue together or you were interested in such a feature. I don't need review from all 4 of you, but the more the merrier :)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 88.959% when pulling b75f4e8 on feat/eventContext into 00479be on master.

@Haroenv
Copy link
Contributor

Haroenv commented Nov 12, 2018

could this be a breaking change?

@pixelastic
Copy link
Contributor Author

I don't think so. It's only adding a third parameter to the triggered event, so no change in userland; old event bindings will still work.

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

has a test + not breaking = LGTM

@Haroenv Haroenv merged commit 36028a6 into master Nov 13, 2018
@Haroenv Haroenv deleted the feat/eventContext branch November 13, 2018 08:12
@rayrutjes
Copy link
Member

This is great @pixelastic 👏
Do you have a concrete example to showcase how we could leverage this?

@s-pace
Copy link

s-pace commented Nov 13, 2018

@rayrutjes A concrete example of how it will help us is that we no longer have an issue to redirect user from the DocSearch UI.

The issue was that we were using handleSelect that was handling both:

  • redirection when a user click on a link
  • redirection when a user press enter on a result selected via the keyboard.
    This was made by a common windows.location=URL

We were missing:

  • the cmd + click opening a new tab
  • link preview from the browser.

We wrap hits element in an tag. This solves the two point raised but the redirection done via the keyboard is not longer working. This is why we need this PR in order to handle the user's interaction in a different way and keep backward compatibility.

@rayrutjes
Copy link
Member

Thanks for your comment @s-pace .

I was more wondering if we could showcase a simple example narrowed down to the open in new tab feature so that users can start implementing it. It can be a bit overwhelming to understand the PR you did in DocSearch for instance because it seems to be covering more than just taking advantage of this new feature.

@s-pace
Copy link

s-pace commented Nov 13, 2018

thanks @rayrutjes

We will need to do a new release of our DocSearch UI to make it works. Might be a good way to promote this but definitely agree that it should be part of a simple "how to"

@francoischalifour
Copy link
Member

@s-pace Let me know when we want to release a new Autocomplete.js version. Then I can update the Autocomplete.js sandbox template so that you can demo the new feature there.

@s-pace
Copy link

s-pace commented Nov 14, 2018

Sure we will

@pixelastic
Copy link
Contributor Author

pixelastic commented Nov 16, 2018

@francoischalifour I tried to release autocomplete but got an error when running npm run release minor. mversion was failing hard. I updated mversion to 1.12 and it is now correctly updating. I still have my push to master rejected though. Can you help me with the release? I created #268 to update mversion.

@rayrutjes I was planning on writing the relevant documentation once the new version is released. Basically, you will now be able to use a <a href> in your suggestion to have default browser behavior on ctrl-click. And when listening to autocomplete:selected, you will have a third parameter passed, named context, where you'll be able to check for context.selectionMethod. If it's click, you return and do nothing (because the browser already did its thing). For all other selection methods (Enter, Tab, etc) you change window.location as usual.

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.

6 participants