Skip to content

Commit abba52d

Browse files
authored
fix: Disabled option should also show in checked (#381)
1 parent 7f6c023 commit abba52d

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/OptionList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ const OptionList: React.RefForwardingComponent<
106106
const valueKeys = React.useMemo(
107107
() =>
108108
checkedKeys.map(val => {
109-
const entity = getEntityByValue(val);
109+
// We should keep disabled value entity here
110+
const entity = getEntityByValue(val, undefined, true);
110111
return entity ? entity.key : null;
111112
}),
112113
[checkedKeys, getEntityByValue],

src/generate.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ export default function generate(config: {
326326
}
327327
return [newRawValues, valueHalfCheckedKeys];
328328
}, [value, mergedMultiple, mergedLabelInValue, treeCheckable, treeCheckStrictly]);
329+
329330
const selectValues = useSelectValues(rawValues, {
330331
treeConduction,
331332
value,

tests/Select.checkable.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,4 +684,32 @@ describe('TreeSelect.checkable', () => {
684684
wrapper.selectNode(1);
685685
expect(onChange).toHaveBeenCalledWith([], expect.anything(), expect.anything());
686686
});
687+
688+
it('disabled option should keep check', () => {
689+
const wrapper = mount(
690+
<TreeSelect
691+
open
692+
treeCheckable
693+
showCheckedStrategy={TreeSelect.SHOW_PARENT}
694+
value={['child']}
695+
treeDefaultExpandAll
696+
treeData={[
697+
{
698+
label: 'parent',
699+
value: 'parent',
700+
disabled: true,
701+
children: [
702+
{
703+
label: 'child',
704+
value: 'child',
705+
disabled: true,
706+
},
707+
],
708+
},
709+
]}
710+
/>,
711+
);
712+
713+
expect(wrapper.exists('.rc-tree-select-tree-treenode-checkbox-checked')).toBeTruthy();
714+
});
687715
});

0 commit comments

Comments
 (0)