Skip to content

Commit

Permalink
Merge pull request #141 from chuksjoe/fix-initial-array-value-bug
Browse files Browse the repository at this point in the history
fix issue #140
  • Loading branch information
tbleckert committed Dec 9, 2020
2 parents a08ca0a + 80845f9 commit bdcef42
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/getDisplayValue.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function getDisplayValue(value) {
if (value && typeof value === 'object') {
if (Array.isArray(value)) {
return value.map((singleOption) => singleOption.name).join(', ');
return value.map((singleOption) => singleOption && singleOption.name).join(', ');
}

return value.name;
Expand Down
30 changes: 30 additions & 0 deletions stories/1-Multiple.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,33 @@ export const StayOnSelect = () => (
]}
/>
);

export const StayOnSelectWithSingleInitialValue = () => (
<SelectSearch
closeOnSelect={false}
printOptions="on-focus"
multiple
placeholder="Select your items"
options={[
{ value: 'hamburger', name: 'Hamburger' },
{ value: 'fries', name: 'Fries' },
{ value: 'milkshake', name: 'Milkshake' },
]}
value={'fries'}
/>
);

export const StayOnSelectWithMultipleInitialValue = () => (
<SelectSearch
closeOnSelect={false}
printOptions="on-focus"
multiple
placeholder="Select your items"
options={[
{ value: 'hamburger', name: 'Hamburger' },
{ value: 'fries', name: 'Fries' },
{ value: 'milkshake', name: 'Milkshake' },
]}
value={['hamburger', 'fries']}
/>
);

1 comment on commit bdcef42

@vercel
Copy link

@vercel vercel bot commented on bdcef42 Dec 9, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.