Skip to content

Commit

Permalink
Fix MultipleDropDown
Browse files Browse the repository at this point in the history
  • Loading branch information
jducro committed Jul 27, 2018
1 parent ddfb298 commit 858603b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"homepage": "https://deskpro.github.io/portal-components",
"dependencies": {
"@deskpro/js-utils": "^1.0.4",
"@deskpro/react-datepicker-hijri": "^1.4.2-beta.1",
"@deskpro/react-datepicker-hijri": "^1.5.0",
"@storybook/addon-knobs": "^3.4.3",
"classnames": "^2.2.5",
"emotion": "^9.2.6",
Expand Down
46 changes: 24 additions & 22 deletions src/Components/Choices/MultipleDropDown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,35 @@ class MultipleDropDown extends Field {
};

renderField = (form) => {
const { name, options, ...props } = this.props;
return (
<ReactSelect
value={getIn(form.values, name)}
name={name}
isClearable={false}
onChange={value => this.handleChange(form, value)}
onBlur={() => form.setFieldTouched(name, true)}
options={options}
removeSelected={false}
menuIsOpen
components={{ Option, SelectContainer }}
optionRenderer={option => this.renderOption(option, form)}
classNamePrefix="react-select"
isMulti
{...props}
/>
);
const { name, dataSource, ...props } = this.props;
if (Array.isArray(dataSource.getOptions)) {
return (
<ReactSelect
value={dataSource.getOptions.filter(o => getIn(form.values, name).includes(o.value))}
name={name}
isClearable={false}
onChange={value => this.handleChange(form, value)}
onBlur={() => form.setFieldTouched(name, true)}
options={dataSource.getOptions}
hideSelectedOptions={false}
menuIsOpen
components={{ Option, SelectContainer }}
optionRenderer={option => this.renderOption(option, form)}
classNamePrefix="react-select"
isMulti
{...props}
/>
);
}
return null;
}
}

MultipleDropDown.propTypes = {
...Field.propTypes,
options: PropTypes.arrayOf(PropTypes.shape({
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
value: PropTypes.any.isRequired
})),
dataSource: PropTypes.shape({
getOptions: PropTypes.oneOfType([PropTypes.func, PropTypes.array]).isRequired,
}).isRequired,
handleChange: PropTypes.func,
};

Expand Down
14 changes: 6 additions & 8 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
}
& input:focus ~ .dp-pc_label,
&:not(.dp-pc_empty) .dp-pc_label,
& .Select.is-focused ~ .dp-pc_label,
& .Select.is-open ~ .dp-pc_label {
& .react-select__is-focused ~ .dp-pc_label {
top: 11px;
left: 10px;
font-size: 10px;
Expand Down Expand Up @@ -335,24 +334,23 @@
& .react-select__multi-value {
line-height: 1.2;
background-color: var(--option-background);
border-color: var(--checkbox-border);
color: var(--text-color);
border-radius: 4px;
border-width: 2px;
border: 2px solid var(--checkbox-border);
margin-top: 15px;
}
}
& .Select-control .Select-value-label {
& .react-select__multi-value__label {
position: static;
font-size: 12px;
}
& .Select-value-icon {
& .react-select__multi-value__remove {
border-right: none;
font-size: 18px;
padding: 0 5px;
}
& .Select-control .Select-input > input {
margin-top: 6px;
& .react-select__input > input {
margin-top: 12px;
}
}
& .react-select__menu {
Expand Down
2 changes: 1 addition & 1 deletion tests/storybook/multiple_dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ storiesOf('Choices', module)
<Form>
<MultipleDropDown
name="filling"
options={options}
dataSource={{ getOptions: options }}
label="Filling"
/>
<Submit>Submit</Submit>
Expand Down

0 comments on commit 858603b

Please sign in to comment.