Skip to content

Commit 036804b

Browse files
committed
Remove UUID generation when id is empty
Addresses #413.
1 parent bd1812b commit 036804b

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
* Hide the pseudo-checkbox from the accessibility tree
1010
* Change the clickable label from `role="link"` to `role="button"`
1111

12-
#### Language
12+
#### Properties
1313

14-
* Replaced `toggle` key in `lang` property with `collapseNode` and `expandNode`
14+
* `id`: No longer generates a random UUID when empty
15+
* `lang`: Replaced `toggle` key with `collapseNode` and `expandNode`
1516

1617
#### Styling
1718

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
"dependencies": {
9090
"classnames": "^2.2.5",
9191
"lodash": "^4.17.10",
92-
"nanoid": "^3.0.0",
9392
"prop-types": "^15.5.8"
9493
}
9594
}

src/js/CheckboxTree.jsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import classNames from 'classnames';
22
import isEqual from 'lodash/isEqual';
33
import memoize from 'lodash/memoize';
4-
import { nanoid } from 'nanoid';
54
import PropTypes from 'prop-types';
65
import React from 'react';
76

@@ -97,7 +96,6 @@ class CheckboxTree extends React.Component {
9796
});
9897

9998
this.state = {
100-
id: props.id || `rct-${nanoid()}`,
10199
model,
102100
prevProps: props,
103101
};
@@ -113,8 +111,8 @@ class CheckboxTree extends React.Component {
113111

114112
static getDerivedStateFromProps(newProps, prevState) {
115113
const { model, prevProps } = prevState;
116-
const { disabled, id, nodes } = newProps;
117-
let newState = { ...prevState, prevProps: newProps };
114+
const { disabled, nodes } = newProps;
115+
const newState = { ...prevState, prevProps: newProps };
118116

119117
// Apply new properties to model
120118
model.setProps(newProps);
@@ -125,10 +123,6 @@ class CheckboxTree extends React.Component {
125123
model.flattenNodes(nodes);
126124
}
127125

128-
if (id !== null) {
129-
newState = { ...newState, id };
130-
}
131-
132126
model.deserializeLists({
133127
checked: newProps.checked,
134128
expanded: newProps.expanded,
@@ -225,14 +219,15 @@ class CheckboxTree extends React.Component {
225219
checkKeys,
226220
expandDisabled,
227221
expandOnClick,
222+
id,
228223
noCascade,
229224
onClick,
230225
onlyLeafCheckboxes,
231226
optimisticToggle,
232227
showNodeTitle,
233228
showNodeIcon,
234229
} = this.props;
235-
const { id, model } = this.state;
230+
const { model } = this.state;
236231

237232
const treeNodes = nodes.map((node) => {
238233
const key = node.value;
@@ -337,11 +332,11 @@ class CheckboxTree extends React.Component {
337332
disabled,
338333
icons,
339334
iconsClass,
335+
id,
340336
lang,
341337
nodes,
342338
nativeCheckboxes,
343339
} = this.props;
344-
const { id } = this.state;
345340
const mergedIcons = this.combineMemorized(defaultIcons, icons);
346341
const treeNodes = this.renderTreeNodes(nodes);
347342

src/js/components/TreeNode.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class TreeNode extends React.PureComponent {
2121
label: PropTypes.node.isRequired,
2222
optimisticToggle: PropTypes.bool.isRequired,
2323
showNodeIcon: PropTypes.bool.isRequired,
24-
treeId: PropTypes.string.isRequired,
2524
value: PropTypes.oneOfType([
2625
PropTypes.string,
2726
PropTypes.number,
@@ -35,6 +34,7 @@ class TreeNode extends React.PureComponent {
3534
icon: PropTypes.node,
3635
showCheckbox: PropTypes.bool,
3736
title: PropTypes.string,
37+
treeId: PropTypes.string,
3838
onClick: PropTypes.func,
3939
};
4040

@@ -45,6 +45,7 @@ class TreeNode extends React.PureComponent {
4545
icon: null,
4646
showCheckbox: true,
4747
title: null,
48+
treeId: null,
4849
onClick: null,
4950
};
5051

@@ -211,7 +212,8 @@ class TreeNode extends React.PureComponent {
211212
onClick,
212213
} = this.props;
213214
const clickable = onClick !== null;
214-
const inputId = `${treeId}-${String(value).split(' ').join('_')}`;
215+
const valueId = String(value).split(' ').join('_');
216+
const inputId = treeId ? `${treeId}-${valueId}` : null;
215217

216218
const render = [(
217219
<label key={0} htmlFor={inputId} title={title}>

0 commit comments

Comments
 (0)