Skip to content

Commit 4df3b60

Browse files
committed
Add support for className at the node level
Resolves #32.
1 parent aa95bf4 commit 4df3b60

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New Features
66

7+
* [#32]: Allow customization of `className` at the node level
78
* [#30]: Add `showNodeIcon` property to optionally remove node icons
89

910
## [v0.5.2](https://github.com/jakezatecky/react-checkbox-tree/compare/v0.5.1...v0.5.2) (2017-05-03)

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ class Widget extends React.Component {
103103

104104
Individual nodes within the `nodes` property can have the following structure:
105105

106-
| Property | Type | Description |
107-
| ---------- | ------ | ------------------------------- |
108-
| `label` | string | **Required**. The node's label. |
109-
| `value` | mixed | **Required**. The node's value. |
110-
| `children` | array | An array of child nodes. |
111-
| `icon` | mixed | A custom icon for the node. |
106+
| Property | Type | Description |
107+
| ----------- | ------ | ------------------------------- |
108+
| `label` | string | **Required**. The node's label. |
109+
| `value` | mixed | **Required**. The node's value. |
110+
| `children` | array | An array of child nodes. |
111+
| `className` | string | A className to add to the node. |
112+
| `icon` | mixed | A custom icon for the node. |

src/js/CheckboxTree.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class CheckboxTree extends React.Component {
143143
<TreeNode
144144
key={key}
145145
checked={checked}
146+
className={node.className}
146147
expanded={node.expanded}
147148
icon={node.icon}
148149
label={node.label}

src/js/TreeNode.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ class TreeNode extends React.Component {
1717
onExpand: PropTypes.func.isRequired,
1818

1919
children: PropTypes.node,
20+
className: PropTypes.string,
2021
icon: PropTypes.node,
2122
rawChildren: PropTypes.arrayOf(nodeShape),
2223
};
2324

2425
static defaultProps = {
2526
children: null,
27+
className: null,
2628
icon: null,
2729
rawChildren: null,
2830
};
@@ -132,13 +134,13 @@ class TreeNode extends React.Component {
132134
}
133135

134136
render() {
135-
const { checked, treeId, label, showNodeIcon, value } = this.props;
137+
const { checked, className, treeId, label, showNodeIcon, value } = this.props;
136138
const inputId = `${treeId}-${value}`;
137139
const nodeClass = classNames({
138140
'rct-node': true,
139141
'rct-node-parent': this.hasChildren(),
140142
'rct-node-leaf': !this.hasChildren(),
141-
});
143+
}, className);
142144

143145
return (
144146
<li className={nodeClass}>

test/TreeNode.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ describe('<TreeNode />', () => {
7474
});
7575
});
7676

77+
describe('className', () => {
78+
it('should append the supplied className to <li> of the node', () => {
79+
const wrapper = shallow(
80+
<TreeNode {...baseProps} className="my-test-class" />,
81+
);
82+
83+
assert.isTrue(wrapper.find('.my-test-class').exists());
84+
});
85+
});
86+
7787
describe('expanded', () => {
7888
it('should render children when set to true', () => {
7989
const wrapper = shallow(

0 commit comments

Comments
 (0)