Skip to content

Commit

Permalink
fix(Dropdown): put empty array to filtered items when searchable is f…
Browse files Browse the repository at this point in the history
…alse (#628)
  • Loading branch information
sun-tea authored and Thomas Roux committed Jul 9, 2019
1 parent 9de45f0 commit 2708d77
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit 2708d77

Please sign in to comment.