File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 11# CHANGELOG
22
3+ ## v.1.4.0 (TBA)
4+
5+ ### New Features
6+
7+ * [ #114 ] : Add ` rct-node-expanded ` and ` rct-node-collapsed ` classes to expanded and collapsed parent nodes
8+
39## [ v1.3.1] ( https://github.com/jakezatecky/react-checkbox-tree/compare/v1.3.0...v1.3.1 ) (2018-09-06)
410
511### Bug Fixes
Original file line number Diff line number Diff line change @@ -275,11 +275,18 @@ class TreeNode extends React.Component {
275275 }
276276
277277 render ( ) {
278- const { className, disabled, isLeaf } = this . props ;
278+ const {
279+ className,
280+ disabled,
281+ expanded,
282+ isLeaf,
283+ } = this . props ;
279284 const nodeClass = classNames ( {
280285 'rct-node' : true ,
281286 'rct-node-leaf' : isLeaf ,
282287 'rct-node-parent' : ! isLeaf ,
288+ 'rct-node-expanded' : ! isLeaf && expanded ,
289+ 'rct-node-collapsed' : ! isLeaf && ! expanded ,
283290 'rct-disabled' : disabled ,
284291 } , className ) ;
285292
Original file line number Diff line number Diff line change @@ -177,6 +177,31 @@ describe('<TreeNode />', () => {
177177 assert . isTrue ( wrapper . contains ( < span className = "rct-icon rct-icon-expand-close" /> ) ) ;
178178 assert . isTrue ( wrapper . contains ( < span className = "rct-icon rct-icon-parent-close" /> ) ) ;
179179 } ) ;
180+
181+ it ( 'should append the `rct-node-expanded` class to the node when set to true' , ( ) => {
182+ const wrapper = shallow (
183+ < TreeNode { ...baseProps } expanded isLeaf = { false } /> ,
184+ ) ;
185+
186+ assert . isTrue ( wrapper . find ( 'li' ) . hasClass ( 'rct-node-expanded' ) ) ;
187+ } ) ;
188+
189+ it ( 'should append the `rct-node-collapsed` class to the node when set to true' , ( ) => {
190+ const wrapper = shallow (
191+ < TreeNode { ...baseProps } expanded = { false } isLeaf = { false } /> ,
192+ ) ;
193+
194+ assert . isTrue ( wrapper . find ( 'li' ) . hasClass ( 'rct-node-collapsed' ) ) ;
195+ } ) ;
196+
197+ it ( 'should not append any expanded/collapsed classes to the node when a leaf' , ( ) => {
198+ const wrapper = shallow (
199+ < TreeNode { ...baseProps } expanded isLeaf /> ,
200+ ) ;
201+
202+ assert . isFalse ( wrapper . find ( 'li' ) . hasClass ( 'rct-node-expanded' ) ) ;
203+ assert . isFalse ( wrapper . find ( 'li' ) . hasClass ( 'rct-node-collapsed' ) ) ;
204+ } ) ;
180205 } ) ;
181206
182207 describe ( 'icon' , ( ) => {
You can’t perform that action at this time.
0 commit comments