-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmulti.js
More file actions
34 lines (31 loc) · 1 KB
/
Copy pathmulti.js
File metadata and controls
34 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React from "react";
import { Select } from "antd";
const multiSelectHoc = (SelectComponent) => (props) => {
const { Option } = SelectComponent;
const style = props.invalid ? { borderColor: "#f5222d" } : {};
const { enum: enums, enumNames } = props.schema || {};
const _value = props.value && Array.isArray(props.value) ? props.value : [];
const onChange = (value) => props.onChange(props.name, value);
return (
<SelectComponent
{...props.options}
style={{ width: "100%", ...style }}
mode="multiple"
disabled={props.disabled || props.readonly}
value={_value}
onChange={onChange}
>
{(enums || []).map((val, index) => (
<Option value={val} key={index}>
<span
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: enumNames ? enumNames[index] : val
}}
/>
</Option>
))}
</SelectComponent>
);
};
export default multiSelectHoc(Select);