File tree Expand file tree Collapse file tree 5 files changed +51
-4
lines changed Expand file tree Collapse file tree 5 files changed +51
-4
lines changed Original file line number Diff line number Diff line change @@ -9,11 +9,13 @@ const optionLists = [
9
9
value : 'zhejiang' ,
10
10
label : 'Zhejiang' ,
11
11
isLeaf : false ,
12
+ disableCheckbox : true ,
12
13
} ,
13
14
{
14
15
value : 'jiangsu' ,
15
16
label : 'Jiangsu' ,
16
17
isLeaf : false ,
18
+ disableCheckbox : false
17
19
} ,
18
20
] ;
19
21
@@ -35,10 +37,12 @@ const Demo = () => {
35
37
{
36
38
label : `${ targetOption . label } Dynamic 1` ,
37
39
value : 'dynamic1' ,
40
+ disableCheckbox : false ,
38
41
} ,
39
42
{
40
43
label : `${ targetOption . label } Dynamic 2` ,
41
44
value : 'dynamic2' ,
45
+ disableCheckbox : true ,
42
46
} ,
43
47
] ;
44
48
setOptions ( [ ...options ] ) ;
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ export interface DefaultOptionType extends BaseOptionType {
54
54
label : React . ReactNode ;
55
55
value ?: string | number | null ;
56
56
children ?: DefaultOptionType [ ] ;
57
+ disableCheckbox ?: boolean ;
57
58
}
58
59
59
60
interface BaseCascaderProps < OptionType extends BaseOptionType = DefaultOptionType >
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export interface CheckboxProps {
8
8
halfChecked ?: boolean ;
9
9
disabled ?: boolean ;
10
10
onClick ?: React . MouseEventHandler ;
11
+ disableCheckbox : boolean ;
11
12
}
12
13
13
14
export default function Checkbox ( {
@@ -16,6 +17,7 @@ export default function Checkbox({
16
17
halfChecked,
17
18
disabled,
18
19
onClick,
20
+ disableCheckbox,
19
21
} : CheckboxProps ) {
20
22
const { checkable } = React . useContext ( CascaderContext ) ;
21
23
@@ -26,7 +28,7 @@ export default function Checkbox({
26
28
className = { classNames ( `${ prefixCls } ` , {
27
29
[ `${ prefixCls } -checked` ] : checked ,
28
30
[ `${ prefixCls } -indeterminate` ] : ! checked && halfChecked ,
29
- [ `${ prefixCls } -disabled` ] : disabled ,
31
+ [ `${ prefixCls } -disabled` ] : disabled || disableCheckbox ,
30
32
} ) }
31
33
onClick = { onClick }
32
34
>
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ export default function Column({
59
59
const optionInfoList = React . useMemo (
60
60
( ) =>
61
61
options . map ( option => {
62
- const { disabled } = option ;
62
+ const { disabled, disableCheckbox } = option ;
63
63
const searchOptions = option [ SEARCH_MARK ] ;
64
64
const label = option [ FIX_LABEL ] ?? option [ fieldNames . label ] ;
65
65
const value = option [ fieldNames . value ] ;
@@ -89,6 +89,7 @@ export default function Column({
89
89
checked,
90
90
halfChecked,
91
91
option,
92
+ disableCheckbox,
92
93
fullPath,
93
94
fullPathKey,
94
95
} ;
@@ -111,6 +112,7 @@ export default function Column({
111
112
option,
112
113
fullPath,
113
114
fullPathKey,
115
+ disableCheckbox,
114
116
} ) => {
115
117
// >>>>> Open
116
118
const triggerOpenPath = ( ) => {
@@ -182,6 +184,7 @@ export default function Column({
182
184
checked = { checked }
183
185
halfChecked = { halfChecked }
184
186
disabled = { disabled }
187
+ disableCheckbox = { disableCheckbox }
185
188
onClick = { ( e : React . MouseEvent < HTMLSpanElement > ) => {
186
189
e . stopPropagation ( ) ;
187
190
triggerSelect ( ) ;
Original file line number Diff line number Diff line change 1
1
/* eslint-disable react/jsx-no-bind */
2
2
3
3
import React from 'react' ;
4
- import { mount } from './enzyme' ;
5
4
import Cascader from '../src' ;
6
5
import { addressOptions } from './demoOptions' ;
6
+ import { mount } from './enzyme' ;
7
7
8
8
describe ( 'Cascader.Checkable' , ( ) => {
9
9
const options = [
@@ -171,11 +171,48 @@ describe('Cascader.Checkable', () => {
171
171
it ( 'should work with custom checkable' , ( ) => {
172
172
const wrapper = mount (
173
173
< Cascader
174
- checkable = { < span className = "my-custom-checkbox" > 0</ span > }
174
+ checkable = { < span className = "my-custom-checkbox" > 0</ span > }
175
175
open
176
176
options = { addressOptions }
177
177
/> ,
178
178
) ;
179
179
expect ( wrapper . find ( '.my-custom-checkbox' ) ) . toHaveLength ( 3 ) ;
180
180
} ) ;
181
+
182
+ it ( 'should be correct expression with disableCheckbox' , ( ) => {
183
+ const wrapper = mount (
184
+ < Cascader
185
+ checkable = { true }
186
+ open
187
+ options = { [
188
+ {
189
+ label : '台湾' ,
190
+ value : 'tw' ,
191
+
192
+ children : [
193
+ {
194
+ label : '福建' ,
195
+ value : 'fj' ,
196
+ disableCheckbox : true ,
197
+ } ,
198
+ {
199
+ label : '兰州' ,
200
+ value : 'lz' ,
201
+ } ,
202
+ { label : '北京' , value : 'bj' } ,
203
+ ] ,
204
+ } ,
205
+ ] }
206
+ /> ,
207
+ ) ;
208
+
209
+ // disabled className
210
+ wrapper . find ( '.rc-cascader-menu-item' ) . simulate ( 'click' ) ;
211
+ expect ( wrapper . find ( '.rc-cascader-checkbox-disabled' ) ) . toHaveLength ( 1 ) ;
212
+
213
+ // Check all children except disableCheckbox When the parent checkbox is checked
214
+ expect ( wrapper . find ( '.rc-cascader-checkbox' ) ) . toHaveLength ( 4 ) ;
215
+ wrapper . find ( '.rc-cascader-checkbox' ) . first ( ) . simulate ( 'click' ) ;
216
+ expect ( wrapper . find ( '.rc-cascader-checkbox-checked' ) ) . toHaveLength ( 3 ) ;
217
+ } ) ;
181
218
} ) ;
You can’t perform that action at this time.
0 commit comments