Skip to content

Commit 63759d7

Browse files
authored
Merge pull request #787 from joelfmrodrigues/feature/treeview-clear
Feature/treeview clear
2 parents 19676dc + c690734 commit 63759d7

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

scripts/create-changelog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const changelog = require('../CHANGELOG.json');
1+
const changelog = require('../CHANGELOG.JSON');
22
const fs = require('fs');
33

44
if (changelog.versions && changelog.versions.length > 0) {

src/controls/treeView/TreeView.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import styles from './TreeView.module.scss';
3-
import uniqBy from 'lodash/uniqBy';
3+
import uniqBy from 'lodash/uniqBy';
44
import { ITreeViewProps, TreeViewSelectionMode } from './ITreeViewProps';
55
import { ITreeViewState } from './ITreeViewState';
66
import { ITreeItem } from './ITreeItem';
@@ -193,6 +193,20 @@ export class TreeView extends React.Component<ITreeViewProps, ITreeViewState> {
193193
}
194194
}
195195

196+
public componentWillReceiveProps(nextProps: ITreeViewProps): void {
197+
const {
198+
items,
199+
defaultSelectedKeys,
200+
selectChildrenIfParentSelected,
201+
} = nextProps;
202+
if (defaultSelectedKeys) {
203+
const selectedItems = !defaultSelectedKeys ? [] : this.getSelectedItems(items, defaultSelectedKeys, selectChildrenIfParentSelected);
204+
this.setState({
205+
activeItems: selectedItems
206+
});
207+
}
208+
}
209+
196210
/**
197211
* Default React render method
198212
*/

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
408408
canMovePrev: false,
409409
canMoveNext: true,
410410
currentCarouselElement: this.carouselElements[0],
411-
comboBoxListItemPickerListId: '0ffa51d7-4ad1-4f04-8cfe-98209905d6da'
411+
comboBoxListItemPickerListId: '0ffa51d7-4ad1-4f04-8cfe-98209905d6da',
412+
treeViewSelectedKeys: ['gc1', 'gc3'],
412413
};
413414

414415
this._onIconSizeChange = this._onIconSizeChange.bind(this);
@@ -1528,13 +1529,14 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
15281529
selectionMode={TreeViewSelectionMode.Multiple}
15291530
showCheckboxes={true}
15301531
treeItemActionsDisplayMode={TreeItemActionsDisplayMode.ContextualMenu}
1531-
defaultSelectedKeys={['gc1', 'gc3']}
1532+
defaultSelectedKeys={this.state.treeViewSelectedKeys}
15321533
onExpandCollapse={this.onExpandCollapseTree}
15331534
onSelect={this.onItemSelected}
15341535
defaultExpandedChildren={true}
1535-
//expandToSelected={true}
1536-
// onRenderItem={this.renderCustomTreeItem}
1536+
//expandToSelected={true}
1537+
// onRenderItem={this.renderCustomTreeItem}
15371538
/>
1539+
<PrimaryButton onClick={() => { this.setState({ treeViewSelectedKeys: [] }); }}>Clear selection</PrimaryButton>
15381540

15391541
</div>
15401542

src/webparts/controlsTest/components/IControlsTestProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ export interface IControlsTestState {
2929
canMovePrev: boolean;
3030
canMoveNext: boolean;
3131
comboBoxListItemPickerListId: string;
32-
3332
filePickerResult?: IFilePickerResult;
33+
treeViewSelectedKeys?: string[];
3434
}

0 commit comments

Comments
 (0)