Skip to content

Commit

Permalink
Merge pull request #76 from kenshoo/add_support_to_showSelectedItems_
Browse files Browse the repository at this point in the history
Add support for showSelectedItems - default =  true
  • Loading branch information
liorheber authored Mar 28, 2018
2 parents 95f75c7 + 33fdc5f commit 67540ee
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 16 deletions.
32 changes: 18 additions & 14 deletions src/components/multi_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class MultiSelect extends PureComponent {
onChange: PropTypes.func,
showSearch: PropTypes.bool,
showSelectAll: PropTypes.bool,
showSelectedItems: PropTypes.bool,
searchIcon: PropTypes.string,
deleteIcon: PropTypes.string,
searchRenderer: PropTypes.func,
Expand All @@ -34,6 +35,7 @@ export class MultiSelect extends PureComponent {
messages: {},
showSearch: true,
showSelectAll: true,
showSelectedItems: true,
height: 400,
itemHeight: 40,
loaderRenderer: Loader
Expand All @@ -59,6 +61,7 @@ export class MultiSelect extends PureComponent {
height,
itemHeight,
showSelectAll,
showSelectedItems,
itemRenderer,
selectedItemRenderer,
filteredItems,
Expand Down Expand Up @@ -113,20 +116,21 @@ export class MultiSelect extends PureComponent {
disabled={disabled}
/>
)}
{!loading && (
<DestinationList
selectionStatusRenderer={selectionStatusRenderer}
selectedIds={selectedIds}
clearAll={clearAll}
messages={messages}
selectedItems={selectedItems}
itemHeight={itemHeight}
height={height}
unselectItem={unselectItem}
selectedItemRenderer={selectedItemRenderer}
noItemsRenderer={noItemsRenderer}
/>
)}
{!loading &&
showSelectedItems && (
<DestinationList
selectionStatusRenderer={selectionStatusRenderer}
selectedIds={selectedIds}
clearAll={clearAll}
messages={messages}
selectedItems={selectedItems}
itemHeight={itemHeight}
height={height}
unselectItem={unselectItem}
selectedItemRenderer={selectedItemRenderer}
noItemsRenderer={noItemsRenderer}
/>
)}
</div>
);
}
Expand Down
12 changes: 12 additions & 0 deletions stories/multi-select.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ storiesOf("React Multi Select", module)
/>
);
})
.add("Without Selected Items", () => {
return (
<ReactMultiSelect
items={manyItems}
loading={boolean("Loading", false)}
onChange={action("onChange")}
showSearch={boolean("Show search", true)}
showSelectAll={boolean("Show select all", true)}
showSelectedItems={boolean("Show selected items", false)}
/>
);
})
.add("With custom components", () => {
return (
<ReactMultiSelect
Expand Down
32 changes: 32 additions & 0 deletions tests/components/__snapshots__/multi_select.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,38 @@ exports[`MultiSelect can remove select all 1`] = `
</div>
`;

exports[`MultiSelect can remove selected items 1`] = `
<div
className="wrapper"
style={
Object {
"height": 400,
}
}
>
<SourceList
calculatedHeight={315}
disabled={false}
filterItems={undefined}
filteredItems={Array []}
getList={undefined}
isAllSelected={false}
itemHeight={40}
itemRenderer={[Function]}
messages={Object {}}
noItemsRenderer={[Function]}
searchIcon={undefined}
searchRenderer={[Function]}
selectAllItems={undefined}
selectAllRenderer={[Function]}
selectItem={undefined}
selectedIds={Array []}
showSearch={true}
showSelectAll={true}
/>
</div>
`;

exports[`MultiSelect custom itemRenderer 1`] = `
<div
className="wrapper"
Expand Down
14 changes: 12 additions & 2 deletions tests/components/multi_select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ describe("MultiSelect", () => {

test("passes disabled if maxSelectedItem has passed", () => {
const renderer = new ShallowRenderer();
const tree = renderer.render(<MultiSelect selectedItems={[1, 2]} maxSelectedItems={2}/>);
const tree = renderer.render(
<MultiSelect selectedItems={[1, 2]} maxSelectedItems={2} />
);
expect(tree).toMatchSnapshot();
});

test("does not pass disabled if maxSelectedItem has passed", () => {
const renderer = new ShallowRenderer();
const tree = renderer.render(<MultiSelect selectedItems={[1, 2]} maxSelectedItems={4}/>);
const tree = renderer.render(
<MultiSelect selectedItems={[1, 2]} maxSelectedItems={4} />
);
expect(tree).toMatchSnapshot();
});

Expand Down Expand Up @@ -148,4 +152,10 @@ describe("MultiSelect", () => {
);
expect(tree).toMatchSnapshot();
});

test("can remove selected items", () => {
const renderer = new ShallowRenderer();
const tree = renderer.render(<MultiSelect showSelectedItems={false} />);
expect(tree).toMatchSnapshot();
});
});

0 comments on commit 67540ee

Please sign in to comment.