Skip to content

Commit d77ca7d

Browse files
authored
fix: show selected parent whose children were all disabled (#395)
1 parent b0a5b4e commit d77ca7d

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/utils/strategyUtil.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ export function formatStrategyValues(
2525
if (
2626
entity &&
2727
entity.children &&
28-
entity.children.every(
29-
({ node }) => isCheckDisabled(node) || valueSet.has(node[fieldNames.value]),
30-
)
28+
entity.children.every(({ node }) => valueSet.has(node[fieldNames.value]))
3129
) {
3230
return false;
3331
}

tests/Select.spec.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe('TreeSelect.basic', () => {
173173
{ key: '0', value: '0', title: 'label0' },
174174
{ key: '1', value: '1', title: 'label1' },
175175
];
176-
const createSelect = (props) => <TreeSelect open treeData={treeData} {...props} />;
176+
const createSelect = props => <TreeSelect open treeData={treeData} {...props} />;
177177

178178
it('fires change and select event', () => {
179179
const onChange = jest.fn();
@@ -213,7 +213,7 @@ describe('TreeSelect.basic', () => {
213213
{ key: 'a', value: 'a', title: 'labela' },
214214
{ key: 'b', value: 'b', title: 'labelb' },
215215
];
216-
const createSelect = (props) => <TreeSelect open showSearch treeData={treeData} {...props} />;
216+
const createSelect = props => <TreeSelect open showSearch treeData={treeData} {...props} />;
217217

218218
it('renders search input', () => {
219219
const wrapper = mount(createSelect());
@@ -228,7 +228,7 @@ describe('TreeSelect.basic', () => {
228228
});
229229

230230
it('check tree changed by filter', () => {
231-
const Wrapper = (props) => <div>{createSelect(props)}</div>;
231+
const Wrapper = props => <div>{createSelect(props)}</div>;
232232
const wrapper = mount(<Wrapper searchValue="a" treeDefaultExpandAll open />);
233233
expect(wrapper.render()).toMatchSnapshot();
234234
wrapper.setProps({ searchValue: '' });
@@ -335,7 +335,7 @@ describe('TreeSelect.basic', () => {
335335
inputValue: '0',
336336
};
337337

338-
handleSearch = (inputValue) => {
338+
handleSearch = inputValue => {
339339
this.setState({ inputValue });
340340
};
341341

@@ -359,7 +359,7 @@ describe('TreeSelect.basic', () => {
359359
});
360360

361361
describe('keyCode', () => {
362-
[KeyCode.ENTER, KeyCode.DOWN].forEach((code) => {
362+
[KeyCode.ENTER, KeyCode.DOWN].forEach(code => {
363363
it('open', () => {
364364
const onFocus = jest.fn();
365365

@@ -502,4 +502,21 @@ describe('TreeSelect.basic', () => {
502502
wrapper.update();
503503
expect(wrapper.find('.rc-tree-select-selection-item').text()).toEqual('bamboo');
504504
});
505+
506+
it('should show parent if children were disabled', () => {
507+
const onSelect = jest.fn();
508+
509+
const wrapper = mount(
510+
<TreeSelect open treeDefaultExpandAll onSelect={onSelect}>
511+
<TreeNode value="parent 1-0" title="parent 1-0">
512+
<TreeNode value="leaf1" title="my leaf" disabled />
513+
<TreeNode value="leaf2" title="your leaf" disabled />
514+
</TreeNode>
515+
</TreeSelect>,
516+
);
517+
518+
wrapper.selectNode();
519+
expect(onSelect).toHaveBeenCalledWith('parent 1-0', expect.anything());
520+
expect(wrapper.text()).toBe('parent 1-0parent 1-0my leafyour leaf');
521+
});
505522
});

0 commit comments

Comments
 (0)