Skip to content

Commit

Permalink
fix: fix failing test for converting btween non-string values and labels
Browse files Browse the repository at this point in the history
  • Loading branch information
okdistribute committed Jul 13, 2020
1 parent 20f0257 commit 79561db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ObservationDialog/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ type Props = {
function Encoder (options) {
return {
toValue: (v) => {
var opts = options.find((ops) => ops.label === v)
var opts = options.find((ops) => ops.label === v.toString())
return opts && opts.value || v
},
toLabel: (v) => {
var opts = options.find((ops) => ops.value === v)
return opts && opts.label || v
return opts && opts.label || v.toString()
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/ObservationDialog/Select.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const countries = [
{ label: 'Andorra' },
{ label: 'Angola' },
{ label: 'Anguilla' },
{ label: 'Antarctica' },
{ label: 'Antarctica', value: 1 },
{ label: 'Antigua and Barbuda' },
{ label: 'Argentina' },
{ label: 'Armenia' },
Expand Down Expand Up @@ -86,3 +86,16 @@ export const selectMultiple = () => (
)}
</StateContainer>
)

export const selectMultipleNonStringValue= () => (
<StateContainer initialValue={[true, 1]}>
{(value, setValue) => (
<SelectMultiple
label="Select Countries"
options={countries}
value={value}
onChange={setValue}
/>
)}
</StateContainer>
)

0 comments on commit 79561db

Please sign in to comment.