-
Notifications
You must be signed in to change notification settings - Fork 734
Picker - filter children (for long lists with search) #1254
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
Conversation
getFilteredChildren = memoize((children, searchValue) => { | ||
const {getItemLabel: getItemLabelPicker} = this.props; | ||
return _.filter(children, child => { | ||
const {label, value, getItemLabel} = child.props; | ||
const itemLabel = getItemLabelPresenter(label, value, getItemLabel || getItemLabelPicker); | ||
return !shouldFilterOut(searchValue, itemLabel); | ||
}); | ||
}); | ||
|
||
get children() { | ||
const {searchValue} = this.state; | ||
const {children, showSearch} = this.props; | ||
if (showSearch && !_.isEmpty(searchValue)) { | ||
return this.getFilteredChildren(children, searchValue); | ||
} | ||
|
||
return children; | ||
} | ||
|
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.
Looks good! we should remove the search logic we have in PickerItem code since this one covers it.
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.
Done
@@ -80,10 +80,6 @@ const PickerItem = props => { | |||
); | |||
}; | |||
|
|||
if (context.showSearch && shouldFilterOut(context.searchValue, itemLabel)) { |
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.
You can also stop passing showSearch
and searchValue
in the context provided by the Picker
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.
Done
Description
Picker - filter children (for long lists with search).
I think this solved the issue, but it has some code duplication with the
Picker.Item
, do you think it can be removed from the item?Should resolve #1244
Changelog
Picker - filter children (for long lists with search)