Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add treeDefaultExpanedKeys #43

Merged
merged 2 commits into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ online example: http://react-component.github.io/tree-select/
|treeIcon | show tree icon | bool | false |
|treeLine | show tree line | bool | false |
|treeDefaultExpandAll | default expand all treeNode | bool | false |
|treeDefaultExpandedKeys | default expanded treeNode keys | Array<String> | - |
|treeCheckable | whether tree show checkbox (select callback will not fire) | bool | false |
|treeCheckStrictly | check node precisely, parent and children nodes are not associated| bool | false |
|filterTreeNode | whether filter treeNodes by input value. default filter by treeNode's treeNodeFilterProp prop's value | bool/Function(inputValue:string, treeNode:TreeNode) | Function |
Expand Down
3 changes: 2 additions & 1 deletion src/SelectTrigger.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ const SelectTrigger = React.createClass({
showIcon: props.treeIcon,
showLine: props.treeLine,
defaultExpandAll: props.treeDefaultExpandAll,
defaultExpandedKeys: props.treeDefaultExpandedKeys,
filterTreeNode: this.highlightTreeNode,
};

Expand All @@ -196,7 +197,7 @@ const SelectTrigger = React.createClass({
}

// expand keys
if (!trProps.defaultExpandAll && !props.loadData) {
if (!trProps.defaultExpandAll && !trProps.defaultExpandedKeys && !props.loadData) {
trProps.expandedKeys = keys;
}
trProps.autoExpandParent = true;
Expand Down
15 changes: 15 additions & 0 deletions tests/Select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,19 @@ describe('TreeSelect', () => {
treeWrapper.find('.rc-tree-select-tree-checkbox').simulate('click');
expect(wrapper.state().value).toEqual([{ value: '0', label: 'label0' }]);
});

it('expands tree nodes by treeDefaultExpandedKeys', () => {
const wrapper = mount(
<TreeSelect treeDefaultExpandedKeys={['1']}>
<TreeNode key="0" value="0" title="0 label"/>
<TreeNode key="1" value="1" title="1 label">
<TreeNode key="10" value="10" title="10 label"/>
<TreeNode key="11" value="11" title="11 label"/>
</TreeNode>
</TreeSelect>
);
const treeWrapper = mount(wrapper.find('Trigger').node.getComponent());
const node = treeWrapper.find('.rc-tree-select-tree-node-content-wrapper').at(1);
expect(node.hasClass('rc-tree-select-tree-node-content-wrapper-open')).toBe(true);
});
});