Skip to content

Commit

Permalink
Fix issue where the id property did not apply to the top-level Chec…
Browse files Browse the repository at this point in the history
…kboxTree container

Resolves #180.
  • Loading branch information
jakezatecky committed Dec 11, 2019
1 parent 59745da commit bd3e6a6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

* [#127]: Change TypeScript definition of TreeNode's `label` property to `React.ReactNode` to better align with the PropType
* [#145]: Fix alignment of many React properties to TypeScript typings
* [#180]: Fix issue where the `id` property did not apply to the top-level CheckboxTree container

## [v1.5.0](https://github.com/jakezatecky/react-checkbox-tree/compare/v1.4.1...v1.5.0) (2019-01-25)

Expand Down
3 changes: 2 additions & 1 deletion src/js/CheckboxTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class CheckboxTree extends React.Component {
nodes,
nativeCheckboxes,
} = this.props;
const { id } = this.state;
const treeNodes = this.renderTreeNodes(nodes);

const className = classNames({
Expand All @@ -352,7 +353,7 @@ class CheckboxTree extends React.Component {
});

return (
<div className={className}>
<div className={className} id={id}>
{this.renderExpandAll()}
{this.renderHiddenInput()}
{treeNodes}
Expand Down
13 changes: 12 additions & 1 deletion test/CheckboxTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,18 @@ describe('<CheckboxTree />', () => {
});

describe('id', () => {
it('should pass the property directly to tree nodes', () => {
it('should pass the id to the top-level DOM node', () => {
const wrapper = shallow(
<CheckboxTree
id="my-awesome-id"
nodes={[{ value: 'jupiter', label: 'Jupiter' }]}
/>,
);

assert.equal('my-awesome-id', wrapper.prop('id'));
});

it('should pass the id as a property directly to tree nodes', () => {
const wrapper = shallow(
<CheckboxTree
id="my-awesome-id"
Expand Down

0 comments on commit bd3e6a6

Please sign in to comment.