Skip to content

Commit 4eae674

Browse files
authoredMar 22, 2022
fix(SearchTree): 修复禁用失效问题 (#699)
1 parent c3f50bb commit 4eae674

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed
 

‎packages/react-search-tree/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,42 @@ const onChangeSinge=(selectd, selectedAll, isChecked)=>{
139139
ReactDOM.render(<Demo />, _mount_);
140140
```
141141

142+
### 禁用
143+
144+
<!--rehype:bgWhite=true&codeSandbox=true&codePen=true-->
145+
```jsx
146+
import React, { useState, useEffect, useRef } from 'react';
147+
import ReactDOM from 'react-dom';
148+
import { SearchTree } from 'uiw';
149+
150+
const data = [
151+
{ label: '上海市', key: 0 },
152+
{
153+
label: '北京市', key: 1,
154+
children:[
155+
{ label: '东城区', key: 10 },
156+
]
157+
},
158+
{ label: '成都市', key: 2 },
159+
]
160+
161+
const Demo = () => {
162+
163+
return(
164+
<SearchTree
165+
disabled={true}
166+
style={{ width:300 }}
167+
allowClear={true}
168+
value={[{ label: '东城区', key: 10 },{ label: '成都市', key: 2 }]}
169+
options={data}
170+
placeholder="请输入选择"
171+
/>
172+
)
173+
}
174+
175+
ReactDOM.render(<Demo />, _mount_);
176+
```
177+
142178
## 自定义空选项
143179

144180
<!--rehype:bgWhite=true&codeSandbox=true&codePen=true-->

‎packages/react-search-tree/src/SearchTagInput.tsx

+14-6
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function SearchTagInput<V extends SearchTagInputOption>(props: SearchTagInputPro
136136
setInnerIsOpen(isOpen);
137137
if (!isOpen) searchValueChange('');
138138
}}
139+
disabled={disabled}
139140
isOpen={innerIsOpen}
140141
menu={<Card bodyStyle={emptyOption === true ? { padding: 0 } : undefined}>{newContent}</Card>}
141142
>
@@ -154,6 +155,7 @@ function SearchTagInput<V extends SearchTagInputOption>(props: SearchTagInputPro
154155
className={`${prefixCls}-tag`}
155156
key={index}
156157
closable
158+
disabled={disabled}
157159
color="#393E48"
158160
onClose={(e) => {
159161
e.stopPropagation();
@@ -166,7 +168,7 @@ function SearchTagInput<V extends SearchTagInputOption>(props: SearchTagInputPro
166168
})}
167169
<Input
168170
ref={inputRef}
169-
style={{ flex: 1, minWidth: 30 }}
171+
style={{}}
170172
className={`${prefixCls}-input-contents`}
171173
size={size}
172174
disabled={disabled}
@@ -176,11 +178,17 @@ function SearchTagInput<V extends SearchTagInputOption>(props: SearchTagInputPro
176178
placeholder={selectedOption.length ? '' : placeholder}
177179
/>
178180
</div>
179-
<span style={{ height: 25, width: 14 }} className={`${prefixCls}-close-tag-contents`}>
180-
{(selectIconType === 'close' || (selectIconType === 'loading' && loading)) && (
181-
<Icon type={selectIconType} spin={loading && selectIconType === 'loading'} onClick={resetSelectedValue} />
182-
)}
183-
</span>
181+
{!disabled && (
182+
<span style={{ height: 25, width: 14 }} className={`${prefixCls}-close-tag-contents`}>
183+
{(selectIconType === 'close' || (selectIconType === 'loading' && loading)) && (
184+
<Icon
185+
type={selectIconType}
186+
spin={loading && selectIconType === 'loading'}
187+
onClick={resetSelectedValue}
188+
/>
189+
)}
190+
</span>
191+
)}
184192
</div>
185193
</div>
186194
</Dropdown>

‎packages/react-search-tree/src/style/index.less

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
.@{w-search-tree} {
44
&-input-contents {
5+
flex: 1;
6+
min-width: 30px;
7+
top: 1px;
8+
59
input {
610
box-shadow: none;
711
padding: 0px;

0 commit comments

Comments
 (0)
Please sign in to comment.