Skip to content

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

Merged
merged 4 commits into from
May 5, 2021

Conversation

M-i-k-e-l
Copy link
Collaborator

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)

Comment on lines +276 to +294
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;
}

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@M-i-k-e-l M-i-k-e-l requested a review from ethanshar May 4, 2021 08:05
@@ -80,10 +80,6 @@ const PickerItem = props => {
);
};

if (context.showSearch && shouldFilterOut(context.searchValue, itemLabel)) {
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@M-i-k-e-l M-i-k-e-l requested a review from ethanshar May 4, 2021 12:59
@ethanshar ethanshar merged commit 665a304 into master May 5, 2021
@M-i-k-e-l M-i-k-e-l deleted the feat/picker-filter-children branch October 4, 2021 08:09
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.

Search in Picker component
2 participants