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

Always render suggestions – fix #133 #155

Merged

Conversation

thibaudcolas
Copy link
Contributor

@thibaudcolas thibaudcolas commented Apr 26, 2016

Hey hey,

this is a PR to fix #133. It implements a new alwaysRenderSuggestions boolean prop, as we discussed. When alwaysRenderSuggestions={true}, the checks to decide whether to render the suggestions are bypassed. Also comes with some documentation on this new prop, and relevant tests.

I'd be keen to get a review of whether the tests are relevant and thorough enough, and make sure this new prop is used in the right places.

Also two things occurred to me while writing this PR:

  • Having an example for this would only be relevant if it came with the kind of UI this is useful for. Do we want to make one? (another way to see this would be to have a list of "projects react-autosuggest is used on" somewhere).
  • It might or might not be be obvious that in order for this to be useful, you need to have a list of suggestions to display even when the user hasn't typed anything yet (otherwise there's nothing to display, doh). Does this need to be stated in the docs?

@thibaudcolas thibaudcolas changed the title Always render suggestions – #133 Always render suggestions – fix #133 Apr 26, 2016
export const toggleAlwaysRenderSuggestions = sinon.spy((toggle, callback) => {
app.setState({
alwaysRenderSuggestions: toggle,
suggestions: getMatchingLanguages(app.state.value || 'elm')
Copy link
Owner

Choose a reason for hiding this comment

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

👍 for "elm", but why || 'elm' is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For those tests to be useful it is necessary to get suggestions even when there's no value in the input – that's why I use elm here. It's not what would happen in a real-world app but does the same job for the tests' purpose.

I added a comment to make this clearer.

@moroshko
Copy link
Owner

Overall looks great! Just a few minor comments above.

@thibaudcolas thibaudcolas force-pushed the feature/always-render-suggestions branch from 5235f81 to 430f59e Compare May 1, 2016 15:02
@thibaudcolas
Copy link
Contributor Author

As those tweaks were quite minor I just rebased them into my previous commits:

  • Fix spacing in variable declaration list
  • toggleAlwaysRenderSuggestions -> setAlwaysRenderSuggestions
  • Documentation changes
  • Comment to make the test helper's intent clearer.

const { value } = inputProps;

if (isCollapsed && lastAction !== 'click' && lastAction !== 'enter' &&
if (alwaysRenderSuggestions || isCollapsed && lastAction !== 'click' && lastAction !== 'enter' &&
Copy link
Owner

Choose a reason for hiding this comment

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

Do we really need alwaysRenderSuggestions || here?
All tests pass without it, so I wonder if we can just remove it, or are we missing a test here?

@moroshko
Copy link
Owner

moroshko commented May 2, 2016

@ThibWeb Thanks for the tweaks!

I think I found an issue with the implementation.

I just added alwaysRenderSuggestions={true} to the CustomRenderer example (also had to change [] to people here).
Suggestions are initially rendered, as expected.
However, when I hit Down, the first suggestion isn't getting focus. Changing this line to:

if (!alwaysRenderSuggestions && isCollapsed) ...

solves the issue, but it doesn't feel right. isCollapsed is true even though suggestions are shown.

Basically, we have a prop and a state that control the view:

  • alwaysRenderSuggestions - prop
  • isCollapsed - state

I feel that the prop should set the initial state. Then, alwaysRenderSuggestions should be used to make sure that isCollapsed stays true no matter what. This way, isCollapsed will be true if and only if suggestions are shown.

What do you think?

@thibaudcolas
Copy link
Contributor Author

Yes, I've had some trouble understanding how best to interact with isCollapsed – doesn't surprise me that I got it wrong. I'll revisit this and probably create a standalone example, as much as a help when developing as to demonstrate what the prop is for.

@bradbirnbaum
Copy link

Checking in on this pull - do we expect to take it soon?

@moroshko
Copy link
Owner

@ThibWeb Have you had a chance to revisit this PR?

@bradbirnbaum
Copy link

Checking in to see if we expect this to be released soon. Thanks

@thibaudcolas
Copy link
Contributor Author

Hey there – sorry for the delay, I was on holidays for a few weeks.

I still intend to work on this, and will commit to get back with a better PR this weekend. Hopefully this will be releasable.

@thibaudcolas thibaudcolas force-pushed the feature/always-render-suggestions branch from 430f59e to 603d8d1 Compare June 5, 2016 22:12
@jxodwyer
Copy link

@ThibWeb just wondering the status of this PR? I'd be happy to jump in and help out if you're running into issues or strapped for time.

@thibaudcolas
Copy link
Contributor Author

thibaudcolas commented Jun 13, 2016

Hey @jxodwyer, strapped for time indeed. If you want to pick this up by all means go for it! Two weeks ago I did some work on this and a relevant UI example. That makes it easier to see why this is useful, what is going on, and where it fails.

Useful links:

Next things to do IMHO:

  • Look at moroshko's suggestions/hints above.
  • Debug the current implementation with those hints and the examples as visual aids
  • Make sure existing test suite still passes
  • Add more tests for the cases that do not work here
  • Update PR 🚀
  • Figure out if this example needs a Codepen link (under moroshko's account like the others?)

I've added you as a contributor to https://github.com/ThibWeb/react-autosuggest, it's up to you if you prefer to use this as is or start from it in another repo 👌. Please let me know what you decide as I'll likely have more time next weekend.

@shprink
Copy link

shprink commented Jun 14, 2016

This feature is much needed indeed! Thanks for your hard work guys, can't wait to see that merged!

@thibaudcolas thibaudcolas force-pushed the feature/always-render-suggestions branch 2 times, most recently from d456896 to f365921 Compare June 25, 2016 12:51
@thibaudcolas
Copy link
Contributor Author

thibaudcolas commented Jun 25, 2016

@moroshko I have updated the PR, could you have a look?

I followed your suggestions, alwaysRenderSuggestions is now used to set the default value of isCollapsed, and to set shouldRenderSuggestions to always return true. Ideally I would have wanted to completely remove any references to alwaysRenderSuggestions in the Autosuggest component, but there are a few instances where isCollapsed and shouldRenderSuggestions are not the only criteria to determine what is rendered:

Those extra checks are useful, but having them within the Autosuggest component makes the code harder to change – there are too many places in the code at different levels of abstraction that are in charge of determining whether suggestions are shown or not. Ideally I think that a single isOpen/isCollapsed prop should be the one and only source of truth for whether suggestions are shown or not. A way to get towards this would be to change how isCollapsed is set in mapDispatchToProps, but that's outside of the scope of this PR.

Other than that, I added the relevant tests to check for:

  • the unwanted behavior that the previous version of this PR produced.
  • the wanted behavior when selecting a suggestion

And I updated https://rawgit.com/ThibWeb/react-autosuggest/demo/arr/demo/dist/index.html to make reviewing this easier.

The last thing that's missing would be a CodePen link – not too sure how to proceed here, since this isn't something we can collaborate on via PRs?

Edit: this PR is running in production at https://data1850.nz/chart 🚀

@rickhanlonii
Copy link
Contributor

@moroshko just a heads up that merging this will cause some conflicts with #165. After this is merged I'll update #165 and add any tests necessary for both props to be active at once.

@thibaudcolas
Copy link
Contributor Author

Just a heads up that if someone wants to use this sooner rather than later, I have a branch where this work is compiled and npm installable: https://github.com/ThibWeb/react-autosuggest/tree/feature/arr-compiled

I'd advise against relying on someone else's branch in a fork for something serious, but you can easily fork it to your own GitHub account to be more certain that it will stay how it is, and then npm install --save react-autossugest@git://github.com/ThibWeb/react-autosuggest.git#feature/arr-compiled with your own user / repo / branch.

@moroshko
Copy link
Owner

@ThibWeb I'm keen to review and merge this PR. Do you mind resolving the merge conflicts? (sorry, they appeared after I merged #165)

@carloscuatin
Copy link

@ThibWeb resolve conflicts please 😀

@shprink
Copy link

shprink commented Jul 22, 2016

🙇 @ThibWeb I will pay you a beer when you come to France if you resolve the conflicts :)

@thibaudcolas thibaudcolas force-pushed the feature/always-render-suggestions branch from 5baee6c to 04b0c3f Compare July 24, 2016 14:37
@thibaudcolas
Copy link
Contributor Author

Wuhu, conflicts merged! They were quite straightforward, only had to add the alwaysRenderSuggestions vars where they belong.

Regarding focusFirstSuggestion – when both this and alwaysRenderSuggestions are turned on, at the moment it only puts the autosuggest focus on the first suggestion when the user moves focus to the autosuggest field. Focusing one of the suggestions even though the autosuggest does not have focus feels strange to me (happy to be told I'm wrong).

The running example at https://rawgit.com/ThibWeb/react-autosuggest/demo/arr/demo/dist/index.html is up to date. @moroshko this might not pass the linting since your latest config updates – I tried to make it work but eslint-plugin-react@6.0.0-alpha.1 keeps complaining about unfound rule definitions.

@LuckUY
Copy link

LuckUY commented Aug 4, 2016

Hi @moroshko,

Any update on this new feature? When do you think it will be merged?

Thanks

@moroshko moroshko merged commit 6ff95ae into moroshko:master Aug 5, 2016
@carloscuatin
Copy link

nice @moroshko 🎉

@shprink
Copy link

shprink commented Aug 5, 2016

Sending <3 to all of you!

@LuckUY
Copy link

LuckUY commented Aug 5, 2016

@moroshko

I cannot see the new "alwaysRenderSuggestions" prop on Autosuggest.js (v 3.9.0)
Did you publish a new version?

Thanks

@moroshko
Copy link
Owner

moroshko commented Aug 8, 2016

alwaysRenderSuggestions is available in v4.0.0 now.

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.

Always render suggestions
8 participants