diff --git a/src/components/Select/Select.js b/src/components/Select/Select.js index 6155551a..8ee8c2c7 100644 --- a/src/components/Select/Select.js +++ b/src/components/Select/Select.js @@ -8,9 +8,9 @@ import { PALETTE, Z_INDEX } from '../../theme'; type SelectProps = {| options: Array<{ label: mixed, value: string }>, - onChange: (selectedValue: mixed, event?: SyntheticInputEvent) => void, + onChange: (value: mixed, event?: SyntheticInputEvent) => void, placeholder?: string, - value?: Object | Object[], + value?: any | any[], loading?: boolean, disabled?: boolean, multiple?: boolean, @@ -19,6 +19,7 @@ type SelectProps = {| zIndex?: string | number, valueComponent?: React$Node, components?: Object, + className?: string, |}; const customStyles = ({ hasError, zIndex = Z_INDEX.DROPDOWN }) => ({ @@ -77,40 +78,63 @@ const customStyles = ({ hasError, zIndex = Z_INDEX.DROPDOWN }) => ({ }), }); -const Select = ({ - value, - loading, - clearable, - disabled, - multiple, - options, - onChange, - placeholder, - valueComponent, - components, - ...props - }: SelectProps) => { - return ( - - - - ); -}; +class Select extends React.Component { + onChange = (option: Object) => { + let value = null; + if (Array.isArray(option)) { + value = option.map(({ value }) => value); + } else if (option) { + ({ value } = option); + } + + this.props.onChange(value); + }; + + render() { + const { + value, + loading, + clearable, + disabled, + multiple, + options, + placeholder, + valueComponent, + components, + onChange, + ...rest + } = this.props; + + const selectValue = ( + Array.isArray(value) + ? options.filter((option) => value.indexOf(option.value) !== -1) + : options.find((option) => option.value === value) + ) || null; + + return ( + + + + ); + } +} + +// $FlowFixMe Select.components = components; export { Select }; diff --git a/src/components/Select/Select.stories.js b/src/components/Select/Select.stories.js index 2cdc2bb5..b6b4db34 100644 --- a/src/components/Select/Select.stories.js +++ b/src/components/Select/Select.stories.js @@ -30,16 +30,16 @@ export default (asStory) => { - + - + , ); const { children, ...passedStyledProps } = wrapper.find(SelectTag).props(); - const { styles, menuPortalTarget, ...passedSelectProps } = wrapper.find(ReactSelect).props(); + const { styles, menuPortalTarget, onChange, valueComponent, ...passedSelectProps } = wrapper.find(ReactSelect).props(); expect(passedSelectProps).toEqual({ isClearable: clearable, isMulti: multiple, + isDisabled: disabled, placeholder, - onChange, options, value: options[0], defaultInputValue: '', @@ -43,6 +46,7 @@ describe('