@@ -34,88 +34,34 @@ const dataList = [
3434];
3535
3636export default function SelectDemo () {
37- const [multiDataList , setDataList ] = useState (dataList);
3837 const handleChange = (value , prevValue ) => {
3938 console .log (' select --- ' + value);
4039 console .log (' prevSelect --- ' + prevValue);
4140 };
4241
4342 return (
4443 < div className= " demo" >
45- < Select
46- defaultValue= {' 3' }
47- onChange= {handleChange}
48- style= {{ width: 120 }}
49- >
50- {dataList .map ((item , index ) => (
51- < Option value= {item .value } disabled= {item .disabled } key= {index}>
52- {item .label }
53- < / Option>
54- ))}
55- < / Select>
56- < Select
57- defaultValue= {' 3' }
58- disabled
59- onChange= {handleChange}
60- style= {{ width: 120 }}
61- >
62- {dataList .map ((item , index ) => (
63- < Option value= {item .value } disabled= {item .disabled } key= {index}>
64- {item .label }
65- < / Option>
66- ))}
67- < / Select>
68- < br/ >
69- < Select
70- placeholder= " 多选有tag"
71- onChange= {values => {
72- if (values .length > 1 ) {
73- setDataList (multiDataList .map ((item , index ) => ({
74- ... item,
75- disabled: ! values .includes (item .value )
76- })))
77- } else {
78- setDataList (multiDataList .map ((item , index ) => ({
79- ... item,
80- disabled: false
81- })))
82- }
83- }}
84- style= {{ width: 220 }}
85- multiple
86- >
87- {multiDataList .map ((item , index ) => (
88- < Option value= {item .value } disabled= {item .disabled } key= {` ${ index} -${ item .disabled } ` }>
89- {item .label }
90- < / Option>
91- ))}
92- < / Select>
93- < Select
94- placeholder= " 多选无tag"
95- style= {{ width: 220 }}
96- multiple
97- showTag= {false }
98- >
99- {multiDataList .map ((item , index ) => (
100- < Option value= {item .value } key= {` ${ index} -${ item .disabled } ` }>
101- {item .label }
102- < / Option>
103- ))}
104- < / Select>
105- < br/ >
106- < Select
107- defaultValue= {' 3' }
108- onChange= {handleChange}
109- style= {{ width: 120 }}
110- allowClear
111- >
112- {dataList .map ((item , index ) => (
113- < Option value= {item .value } disabled= {item .disabled } key= {index}>
114- {item .label }
115- < / Option>
116- ))}
117- < / Select>
118- < Select dataSource= {[]} style= {{ width: 220 }}>< / Select>
44+ < div style= {{ display: ' flex' , gap: 30 }}>
45+ < div>
46+ < h5> 单选< / h5>
47+ < Select
48+ style= {{ width: 328 }}
49+ allowClear
50+ onChange= {handleChange}
51+ dataSource= {dataList}
52+ / >
53+ < / div>
54+ < div>
55+ < h5> 多选< / h5>
56+ < Select
57+ style= {{ width: 328 }}
58+ multiple
59+ allowClear
60+ onChange= {handleChange}
61+ dataSource= {dataList}
62+ / >
63+ < / div>
64+ < / div>
11965 < / div>
12066 );
12167}
0 commit comments