Skip to content

Commit 36af33e

Browse files
Merge pull request #1379 from garygong/tree-fixes
Tree bug fixes introduced by keyboard navigation
2 parents b9a0b71 + 915401c commit 36af33e

File tree

9 files changed

+205
-138
lines changed

9 files changed

+205
-138
lines changed

components/component-docs.json

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6741,29 +6741,8 @@
67416741
},
67426742
"iconCategory": {
67436743
"type": {
6744-
"name": "enum",
6745-
"value": [
6746-
{
6747-
"value": "'action'",
6748-
"computed": false
6749-
},
6750-
{
6751-
"value": "'custom'",
6752-
"computed": false
6753-
},
6754-
{
6755-
"value": "'doctype'",
6756-
"computed": false
6757-
},
6758-
{
6759-
"value": "'standard'",
6760-
"computed": false
6761-
},
6762-
{
6763-
"value": "'utility'",
6764-
"computed": false
6765-
}
6766-
]
6744+
"name": "custom",
6745+
"raw": "requiredIf(\n PropTypes.oneOf(['action', 'custom', 'doctype', 'standard', 'utility']),\n (props) => !!props.iconName\n)"
67676746
},
67686747
"required": false,
67696748
"description": "Name of the icon category. Visit <a href=\"http://www.lightningdesignsystem.com/resources/icons\">Lightning Design System Icons</a> to reference icon categories."
@@ -7438,6 +7417,23 @@
74387417
"computed": false
74397418
}
74407419
},
7420+
"assistiveText": {
7421+
"type": {
7422+
"name": "shape",
7423+
"value": {
7424+
"dialogLabel": {
7425+
"name": "string",
7426+
"required": false
7427+
}
7428+
}
7429+
},
7430+
"required": false,
7431+
"description": "Assistive text for the modal.",
7432+
"defaultValue": {
7433+
"value": "{}",
7434+
"computed": false
7435+
}
7436+
},
74417437
"children": {
74427438
"type": {
74437439
"name": "node"
@@ -11103,7 +11099,51 @@
1110311099
},
1110411100
"tree": {
1110511101
"description": "A tree is visualization of a structure hierarchy. A branch can be expanded or collapsed. This is a controlled component, since visual state is present in the `nodes` data.",
11106-
"methods": [],
11102+
"methods": [
11103+
{
11104+
"name": "handleSelect",
11105+
"docblock": null,
11106+
"modifiers": [],
11107+
"params": [
11108+
{
11109+
"name": "event",
11110+
"type": null
11111+
},
11112+
{
11113+
"name": "data",
11114+
"type": null
11115+
},
11116+
{
11117+
"name": "clearSelectedNodes",
11118+
"type": null
11119+
}
11120+
],
11121+
"returns": null
11122+
},
11123+
{
11124+
"name": "handleNodeBlur",
11125+
"docblock": null,
11126+
"modifiers": [],
11127+
"params": [],
11128+
"returns": null
11129+
},
11130+
{
11131+
"name": "handleExpand",
11132+
"docblock": null,
11133+
"modifiers": [],
11134+
"params": [
11135+
{
11136+
"name": "event",
11137+
"type": null
11138+
},
11139+
{
11140+
"name": "data",
11141+
"type": null
11142+
}
11143+
],
11144+
"returns": null
11145+
}
11146+
],
1110711147
"props": {
1110811148
"assistiveText": {
1110911149
"type": {
@@ -11178,21 +11218,21 @@
1117811218
"name": "array"
1117911219
},
1118011220
"required": false,
11181-
"description": "Array of items starting at the top of the tree. The required shape is: `{expanded: string, id: string, label: string, selected: string, type: string, nodes: array}`, but only `id` and `label` are required. Use `type: 'branch'` for folder and categories."
11221+
"description": "Array of items starting at the top of the tree. The shape each node in the array is:\n```\n{\n expanded: string,\n id: string,\n label: string or node,\n selected: string,\n type: string,\n nodes: array\n}\n```\n`assistiveText: string` is optional and helpful if the label is not a string. Only `id` and `label` are required. Use `type: 'branch'` for folder and categories."
1118211222
},
1118311223
"onClick": {
1118411224
"type": {
1118511225
"name": "func"
1118611226
},
1118711227
"required": true,
11188-
"description": "Function that will run whenever an item or branch is clicked."
11228+
"description": "Function that will run whenever an item or branch is selected due to click or keyboard navigation."
1118911229
},
1119011230
"onExpandClick": {
1119111231
"type": {
1119211232
"name": "func"
1119311233
},
1119411234
"required": true,
11195-
"description": "This function triggers when the expand or collapse icon is clicked."
11235+
"description": "This function triggers when the expand or collapse icon is clicked or due to keyboard navigation."
1119611236
},
1119711237
"onScroll": {
1119811238
"type": {

components/tree/__docs__/storybook-stories.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import createReactClass from 'create-react-class';
33
import PropTypes from 'prop-types';
44
import { storiesOf, action } from '@storybook/react';
5+
import cloneDeep from 'lodash.clonedeep';
56
import IconSettings from '../../icon-settings';
67

78
import { TREE } from '../../../utilities/constants';
@@ -38,7 +39,7 @@ const DemoTree = createReactClass({
3839
? sampleNodes[this.props.exampleNodesIndex]
3940
: sampleNodes.sampleNodesDefault;
4041
return {
41-
nodes: initalNodes,
42+
nodes: cloneDeep(initalNodes),
4243
selectedNode: undefined,
4344
searchTerm: this.props.searchable ? 'fruit' : undefined,
4445
};
@@ -74,15 +75,15 @@ const DemoTree = createReactClass({
7475

7576
return { selectedNode: data.node };
7677
});
77-
itemClicked('Node Clicked')(event, data);
78+
itemClicked('Node Selected')(event, data);
7879
} else if (
7980
!this.props.noBranchSelection ||
8081
(this.props.noBranchSelection && data.node.type !== 'branch')
8182
) {
8283
data.node.selected = data.select;
8384
// trigger render
8485
this.setState((prevState) => ({ ...prevState }));
85-
itemClicked('Node Clicked')(event, data);
86+
itemClicked('Node Selected')(event, data);
8687
}
8788
},
8889

components/tree/__examples__/default.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const sampleNodes = {
1919
expanded: true,
2020
nodes: [
2121
{
22-
label: 'Ground Fruits',
22+
assistiveText: 'Ground Fruits',
23+
label: <span>Ground Fruits</span>,
2324
type: 'branch',
2425
id: 4,
2526
nodes: [

components/tree/__tests__/tree.browser-test.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import createReactClass from 'create-react-class';
88
import PropTypes from 'prop-types';
99

1010
import isFunction from 'lodash.isfunction';
11+
import cloneDeep from 'lodash.clonedeep';
1112

1213
import chai, { expect } from 'chai';
1314
import chaiEnzyme from 'chai-enzyme';
@@ -60,7 +61,7 @@ const DemoTree = createReactClass({
6061
? sampleNodes[this.props.exampleNodesIndex]
6162
: sampleNodes.sampleNodesDefault;
6263
return {
63-
nodes: initalNodes,
64+
nodes: cloneDeep(initalNodes),
6465
searchTerm: this.props.searchable ? 'fruit' : undefined,
6566
};
6667
},
@@ -312,9 +313,10 @@ describe('Tree: ', () => {
312313

313314
it('has initial selection', function () {
314315
let selectedNode = this.wrapper
315-
.find('#example-tree-1')
316+
.find('#example-tree-2')
316317
.find('.slds-is-selected');
317-
expect(selectedNode).to.have.length(1);
318+
// Fruits, Watermelon, Tree Fruits
319+
expect(selectedNode).to.have.length(3);
318320
selectedNode = this.wrapper
319321
.find('#example-tree-5')
320322
.find('.slds-is-selected');

0 commit comments

Comments
 (0)