Skip to content

Commit

Permalink
fix: SelectMultiple should not throw errors in console
Browse files Browse the repository at this point in the history
  • Loading branch information
okdistribute committed Jul 9, 2020
1 parent 4fc9b8e commit f5a219d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
8 changes: 7 additions & 1 deletion src/ObservationDialog/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ const Field = ({ field, value, onChange }: Props) => {
/>
)
case 'select_multiple':
return <SelectMultiple value={value} label={label} />
return <SelectMultiple
value={value}
label={label}
options={field.options}
placeholder={placeholder}
onChange={handleChange}
/>
case 'number':
return (
<TextField
Expand Down
24 changes: 14 additions & 10 deletions src/ObservationDialog/ObservationDialog.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@ const getPreset = observation => {

const exampleObservations = require('../../fixtures/observations.json')

export const simple = () => (
<ObservationDialog
open
onRequestClose={action('close')}
onSave={action('save')}
observation={exampleObservations[1]}
getMedia={getMedia}
onDeleteObservation={action('delete')}
/>
)
export const simple = () => {
const obs = exampleObservations[1]
return (
<ObservationDialog
open
getPreset={getPreset}
onRequestClose={action('close')}
onSave={action('save')}
observation={obs}
getMedia={getMedia}
onDeleteObservation={action('delete')}
/>
)
}

export const openClose = () => {
const [open, setOpen] = React.useState(false)
Expand Down
2 changes: 1 addition & 1 deletion src/ObservationDialog/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const SelectMultiple = ({
id={id}
multiple
freeSolo
value={value}
value={value || []}
onChange={(e, v) => onChange(v)}
options={options.map(op => (typeof op === 'object' ? op.label : op))}
renderInput={params =>
Expand Down
2 changes: 1 addition & 1 deletion src/ObservationDialog/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { TextField as MuiTextField } from '@material-ui/core'

const TextField = ({ onChange, ...otherProps }) => {
const handleChange = event => onChange(event.target.value)
const handleChange = event => onChange && onChange(event.target.value)
return (
<MuiTextField
fullWidth
Expand Down

0 comments on commit f5a219d

Please sign in to comment.