-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[AutoComplete] Add key(text) support for dataSource and more general item componenta support #3662
Conversation
Hi @yongxu - thanks for doing this. Before we review the rewrite of the other PR - what is the purpose of the sort prop? If the data is sorted are the results not also? The example doesn't work as an autocomplete - it shows all results no matter what is typed, and in any case I think this functionality should be in a separate PR.I would have also suggested an issue to discuss the use case before you did the work. 😄 |
@mbrookes I think we should move away from baking in application logic into the core autocomplete component. As a user I want access to a controlled component that isn't held back in any way by a maze of internal logic. Any helpers for searching/sorting data should be plugged in exactly the same way that you would plug in your own logic, imo. |
@@ -178,6 +178,10 @@ const AutoComplete = React.createClass({ | |||
searchText: React.PropTypes.string, | |||
|
|||
/** | |||
* Compare callback used to sort the items. | |||
*/ | |||
sort: React.PropTypes.func, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the signature for this too 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets figure out if this is a useful feature first. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah was thinking the same actually. 😅
I completly agree. |
@mbrookes @nathanmarks @alitaheri @oliviertassinari ,
The result was sorted, but not filtered. I made a mistake for not noticing the fruit list was already sorted. |
We can't disagree here. But that's not what is at stake. Wouldn't it be better if we had a controlled |
I agree:
|
This enhancement is exactly intended for this kind of logic. As far as I know, there isn't anyway to manipulate the data or change the order(sorting) after the filter process. Currently, we have to presort all the data before send it to dataSource if we want sorted result. Although I am not sure if this solution is the best, but there should be at least one way to do it. |
Yes you can, this is how I'm using the component, I can't rely on the internal logic. |
@yongxu As Olivier said, the direction we're moving towards would mean helpers such as this belong in optional utilities to plug into a less opinionated autocomplete. Right now, adding more built-in state logic does not help us move towards that goal. I'd recommend filtering the data yourself and pass it to the component as @oliviertassinari outlined in the last post. |
@oliviertassinari FYI, I think @yongxu is feeling rather confused as he had the same changes accepted 9 days ago by @mbrookes in #3182 I'm sorry for any misunderstanding @yongxu -- this likely would have been raised in the 2nd review before the PR was merged. |
@oliviertassinari @mbrookes @nathanmarks I wasn't confused, but uuuumm... Thanks for all the thought BTW 👍 |
<AutoComplete | ||
floatingLabelText="Same text, different values" | ||
filter={AutoComplete.noFilter} | ||
triggerUpdateOnFocus={true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have deprecated this property. Can you use openOnFocus
instead?
text: item.text, | ||
value: ( | ||
<MenuItem | ||
innerDivStyle={{overflow: 'hidden'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
innerDivStyle={styles.innerDiv}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated :)
@yongxu Can you edit the title and the description to reflect what the PR does now? 👍 And the commit message can match the title |
@yongxu Thanks 👍. |
Thanks @oliviertassinari , I will make sure to get it right next time 👍 |
Rewrite some code to replace my initial PR, improved readability.
Broader item value support.
Clearer code.
Support for case #3137