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 #133
Comments
@ThibWeb +1 Even I was wishing to have that feature. |
@ThibWeb Thanks for the detailed issue! Could you explain a bit more what do you mean by:
I assume when you focus on the field for the first time, you'd like the suggestions to appear. I modified the Basic example to always show suggestions on focus. Is that close to what you are trying to achieve? |
Sure. By "always' I mean when the component renders the suggestions render too. For my project, the UX thinking is that people shouldn't need to type text and filter things in order to pick a suggestion. It is relevant for us to show the full list, so we do just that and leave them the opportunity to either type a search term or scroll through the whole list and click. Autocompletion / filtering is the main means of interaction but in our case it's not the only one. Here is a prototype where it is implemented (click on one of the buttons to display the autocomplete UI): https://springload.github.io/react-search-example/. To compare with the modified basic example: like this, except the list should be displayed regardless of whether the field is focused or not. Thinking about it more, this "always open" seems to make the most sense combined with a modal as in my example. I don't see how this would be useful for fields that are always visible on the page, where picking a value doesn't "close" anything like the modal does. |
@ThibWeb I can see why in your use case it makes sense to keep the suggestions always visible to the user. However, the input field in your case feels more like a filter than a traditional autosuggest. As you pointed out, it makes sense to keep the suggestions always visible only when selecting a suggestion takes you somewhere else (in your case, it's closing the modal, but it could just be a normal link to another page like here). From the options you listed above, I like the second suggestion (passing From implementation point of view, it will probably be easiest to just add a new prop, say What would you do if you were the maintainer of |
This is a very legitimate, and tough question :) I've been thinking about it but am still undecided – will get back to you on the issue. It's hard to accommodate both more control over how things work and sane defaults for the things that 90% of the users wouldn't want to deal with. Thinking about it! |
We also need this feature for a modal overlay on mobile. I'm not sure about how to implement this either. Our goal would be to basically set |
I'm needing this too. What if you just always render This would make it so that the simplest use case ( And if the typical usage is to implement
|
Sorry, |
Ok – my project has evolved a bit and I took some time to think about this. I still think there is a valid but probably uncommon use case for "always render suggestions". I tried to make this work on my project with With this in mind, I have two propositions. They are both based on the premise that because of
The only issue I see with this second proposition is that counter-intuitively I don't find it as future-proof. If other use cases come up, it will be quite simple to add extra parameters to Of those two propositions, I think I like the second one better – it supports the uncommon use case we're discussing, without impacting the most common ones. It requires more implementation & documentation, but does not increase the API surface as much as another config flag. It improves the semantics of the If we decide not to support this altogether, or go for the first proposition, the documentation of -By default, suggestions are rendered when input field isn't blank. Feel free to override this behaviour.
+When the field is focused, controls if suggestions are rendered. By default, suggestions are rendered when input field isn't blank. Feel free to override this behaviour. |
@ThibWeb Thanks a lot for your feedback and suggestions! I think the first option makes the common use case of With the second option, I find it very strange that I'm starting to lean towards introducing a new prop, say What do you think? @selaux Your feedback would also be appreciated! |
@moroshko: Here are my two cents for the suggestions
|
How about I think
Any volunteers to implement this? |
I volunteer! |
Thanks @ThibWeb 👍 |
This use case should now be tackled with the work done in #155. I'd love to get more eyes onto this PR to make sure it does the right thing and is tested enough. |
Hey hey,
I have a specific use case where I need the list of suggestions to always be rendered. I expected this to be the case if
shouldRenderSuggestions
always returned true, but things are a bit more complicated.In reality, for suggestions to be rendered the criteria are:
isFocused
, and!isCollapsed
, andsuggestions.length > 0
, andshouldRenderSuggestions
(see https://github.com/moroshko/react-autosuggest/blob/master/src/Autosuggest.js#L177)
I think it makes perfect sense to check for "are there suggestions" and I don't know what
isCollapsed
is about. ForisFocused
however, this seems like a sensible default but not necessarily something that this component should have opinions about.react-autosuggest
strikes me as rather unopinionated in other parts of its API.I can see at least three ways to tackle this:
isFocused
(andisCollapsed
?) should be checked. This seems like the simplest choice because it's fully backward compatible, but not the best IMHO becauseshouldRenderSuggestions
's name suggests that it should be responsible for this.isFocused
toshouldRenderSuggestions
, and let the component's user decide whether they want to take it into account or not. Seems like the option that aligns best with the existing API. It's just an extra parameter, and its logic is somewhat similar to that of giving areason
foronSuggestionsUpdateRequested
and leaving it up to the user to decide what they want to do. However this isn't backwards compatible.shouldRenderSuggestions
's documentation to make it clear that suggestions are only rendered when input field is focused.In those three cases I'm happy to contribute a PR, but I think this is worth discussing in advance :)
The text was updated successfully, but these errors were encountered: