Skip to content

Commit

Permalink
Add treeDefaultExpanedKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Jan 17, 2017
1 parent 024b394 commit a3451dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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('expand 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);
});
});

0 comments on commit a3451dd

Please sign in to comment.