Skip to content

Commit

Permalink
[Docs] filter_group_multi: update multi select example to be function…
Browse files Browse the repository at this point in the history
…al (#4178)

* docs(filter_group_multi): update multi select example to be functional

* fix(filter_group_multi): add working multi select example

* add #4178 to changelog

* Remove extra space from cl

Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>
  • Loading branch information
Phizzard and cchaos authored Oct 28, 2020
1 parent b39de92 commit 7524a5c
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src-docs/src/views/filter_group/filter_group_multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default () => {
setIsPopoverOpen(false);
};

const items = [
const [items, setItems] = useState([
{ name: 'Johann Sebastian Bach', checked: 'on' },
{ name: 'Wolfgang Amadeus Mozart', checked: 'on' },
{ name: 'Antonín Dvořák', checked: 'off' },
Expand All @@ -43,16 +43,39 @@ export default () => {
{ name: 'Robert Schumann' },
{ name: 'Sergej S. Prokofiew' },
{ name: 'Wolfgang Amadeus Mozart' },
];
]);

function updateItem(index) {
if (!items[index]) {
return;
}

const newItems = [...items];

switch (newItems[index].checked) {
case 'on':
newItems[index].checked = 'off';
break;

case 'off':
newItems[index].checked = undefined;
break;

default:
newItems[index].checked = 'on';
}

setItems(newItems);
}

const button = (
<EuiFilterButton
iconType="arrowDown"
onClick={onButtonClick}
isSelected={isPopoverOpen}
numFilters={items.length}
hasActiveFilters={true}
numActiveFilters={2}>
hasActiveFilters={!!items.find((item) => item.checked === 'on')}
numActiveFilters={items.filter((item) => item.checked === 'on').length}>
Composers
</EuiFilterButton>
);
Expand All @@ -71,7 +94,10 @@ export default () => {
</EuiPopoverTitle>
<div className="euiFilterSelect__items">
{items.map((item, index) => (
<EuiFilterSelectItem checked={item.checked} key={index}>
<EuiFilterSelectItem
checked={item.checked}
key={index}
onClick={() => updateItem(index)}>
{item.name}
</EuiFilterSelectItem>
))}
Expand Down

0 comments on commit 7524a5c

Please sign in to comment.