This repository was archived by the owner on Aug 5, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +42
-1
lines changed
Expand file tree Collapse file tree 5 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 1+ 6.0.1
2+ - Fix [#63](https://github.com/mobify/bellows/issues/63): Short circuit open if other items are opening
136.0.0
24 - Publish to NPM
35 - Remove Zepto support in favor of jQuery
Original file line number Diff line number Diff line change 137137 . attr ( 'aria-hidden' , true ) ;
138138 } ,
139139
140+ /*
141+ Checks if other bellows items are currently opening
142+ */
143+ _othersAreOpening : function ( ) {
144+ return this . $bellows . find ( '.' + cssClasses . OPENING ) . length > 0 ;
145+ } ,
146+
140147 toggle : function ( $item ) {
141148 $item = this . _item ( $item ) ;
142149
155162
156163 if ( this . options . singleItemOpen ) {
157164 this . closeAll ( ) ;
165+
166+ // Fix #63
167+ if ( this . _othersAreOpening ( ) ) {
168+ return ;
169+ }
158170 }
159171
160172 this . _trigger ( 'open' , { item : $item } ) ;
Original file line number Diff line number Diff line change 137137 . attr ( 'aria-hidden' , true ) ;
138138 } ,
139139
140+ /*
141+ Checks if other bellows items are currently opening
142+ */
143+ _othersAreOpening : function ( ) {
144+ return this . $bellows . find ( '.' + cssClasses . OPENING ) . length > 0 ;
145+ } ,
146+
140147 toggle : function ( $item ) {
141148 $item = this . _item ( $item ) ;
142149
155162
156163 if ( this . options . singleItemOpen ) {
157164 this . closeAll ( ) ;
165+
166+ // Fix #63
167+ if ( this . _othersAreOpening ( ) ) {
168+ return ;
169+ }
158170 }
159171
160172 this . _trigger ( 'open' , { item : $item } ) ;
Original file line number Diff line number Diff line change @@ -282,5 +282,20 @@ define([
282282 expect ( $openDisabledItem . hasClass ( 'bellows--is-open' ) ) . to . be . true ;
283283 } ) ;
284284 } ) ;
285+
286+ describe ( 'a Bellows instance with singleItemOpen set' , function ( ) {
287+ it ( 'only allows a single item open when opening another item' , function ( ) {
288+ $element . bellows ( {
289+ singleItemOpen : true ,
290+ opened : function ( ) {
291+ $element . bellows ( 'open' , 1 ) ;
292+ $element . find ( '.bellows__item.bellows--is-open' ) . to . have . length ( 1 ) ;
293+ done ( ) ;
294+ }
295+ } ) ;
296+
297+ $element . bellows ( 'open' , 0 ) ;
298+ } ) ;
299+ } ) ;
285300 } ) ;
286301} ) ;
You can’t perform that action at this time.
0 commit comments