This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ angular.module('ui.bootstrap.dropdown', [])
2929 } ;
3030
3131 var closeDropdown = function ( evt ) {
32+ // This method may still be called during the same mouse event that
33+ // unbound this event handler. So check openScope before proceeding.
34+ if ( ! openScope ) { return ; }
35+
3236 var toggleElement = openScope . getToggleElement ( ) ;
3337 if ( evt && toggleElement && toggleElement [ 0 ] . contains ( evt . target ) ) {
3438 return ;
Original file line number Diff line number Diff line change @@ -168,6 +168,33 @@ describe('dropdownToggle', function() {
168168 } ) ;
169169 } ) ;
170170
171+ describe ( 'integration with $location URL rewriting' , function ( ) {
172+ function dropdown ( ) {
173+
174+ // Simulate URL rewriting behavior
175+ $document . on ( 'click' , 'a[href="#something"]' , function ( ) {
176+ $rootScope . $broadcast ( '$locationChangeSuccess' ) ;
177+ $rootScope . $apply ( ) ;
178+ } ) ;
179+
180+ return $compile ( '<li dropdown><a href dropdown-toggle></a>' +
181+ '<ul><li><a href="#something">Hello</a></li></ul></li>' ) ( $rootScope ) ;
182+ }
183+
184+ beforeEach ( function ( ) {
185+ element = dropdown ( ) ;
186+ } ) ;
187+
188+ it ( 'should close without errors on $location change' , function ( ) {
189+ $document . find ( 'body' ) . append ( element ) ;
190+ clickDropdownToggle ( ) ;
191+ expect ( element . hasClass ( 'open' ) ) . toBe ( true ) ;
192+ var optionEl = element . find ( 'ul > li' ) . eq ( 0 ) . find ( 'a' ) . eq ( 0 ) ;
193+ optionEl . click ( ) ;
194+ expect ( element . hasClass ( 'open' ) ) . toBe ( false ) ;
195+ } ) ;
196+ } ) ;
197+
171198 describe ( 'without trigger' , function ( ) {
172199 beforeEach ( function ( ) {
173200 $rootScope . isopen = true ;
You can’t perform that action at this time.
0 commit comments