Skip to content

Commit ff30d04

Browse files
clear tree-view selected options when empty array
1 parent 56d7e01 commit ff30d04

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
@@ -310,7 +310,8 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
310310
canMovePrev: false,
311311
canMoveNext: true,
312312
currentCarouselElement: this.carouselElements[0],
313-
comboBoxListItemPickerListId: '0ffa51d7-4ad1-4f04-8cfe-98209905d6da'
313+
comboBoxListItemPickerListId: '0ffa51d7-4ad1-4f04-8cfe-98209905d6da',
314+
treeViewSelectedKeys: ['gc1', 'gc3'],
314315
};
315316

316317
this._onIconSizeChange = this._onIconSizeChange.bind(this);
@@ -1347,13 +1348,14 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
13471348
selectionMode={TreeViewSelectionMode.Multiple}
13481349
showCheckboxes={true}
13491350
treeItemActionsDisplayMode={TreeItemActionsDisplayMode.ContextualMenu}
1350-
defaultSelectedKeys={['gc1', 'gc3']}
1351+
defaultSelectedKeys={this.state.treeViewSelectedKeys}
13511352
onExpandCollapse={this.onExpandCollapseTree}
13521353
onSelect={this.onItemSelected}
13531354
defaultExpandedChildren={true}
1354-
//expandToSelected={true}
1355-
// onRenderItem={this.renderCustomTreeItem}
1355+
//expandToSelected={true}
1356+
// onRenderItem={this.renderCustomTreeItem}
13561357
/>
1358+
<PrimaryButton onClick={() => { this.setState({ treeViewSelectedKeys: [] }); }}>Clear selection</PrimaryButton>
13571359

13581360
</div>
13591361

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)