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

fix(Dropdown): put empty array to filtered items when searchable is false #628

Merged
merged 1 commit into from
Jul 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ class Dropdown extends PureComponent {
// Filter items based on search key word
// TODO: when need to refactor this later, children may have some children
// we need to filter recursively. - @Thomas -
const FiltredItem = Children.toArray(children).filter(({ props: { children } }) =>
children.toLowerCase().includes(searchKeyword.toLowerCase()),
);
const FilteredItems = searchable
? Children.toArray(children).filter(({ props: { children } }) =>
children.toLowerCase().includes(searchKeyword.toLowerCase()),
)
: [];

return (
<div className={className} data-testid="dropdown">
Expand Down Expand Up @@ -196,8 +198,8 @@ class Dropdown extends PureComponent {
)}

{searchable &&
(FiltredItem.length !== 0
? FiltredItem.map(child => (
(FilteredItems.length !== 0
? FilteredItems.map(child => (
<MenuItem key={child.key} searchable={searchable} role="menuitem">
{child}
</MenuItem>
Expand Down