Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Feature/dropdown add to body #3411

Closed

Conversation

rysilva
Copy link
Contributor

@rysilva rysilva commented Mar 19, 2015

Fixes #1030

Look for dropdown-append-to-body attribute on the dropdown directive. If it's there, append the dropdown-menu to the body and show/hide/position it when the dropdown toggles.

@rysilva
Copy link
Contributor Author

rysilva commented Mar 19, 2015

I'm attempting to remove the dropdown menu from the body when the main dropdown element fires the $destroy event. However, on the demo page the $destroy event never gets fired. I've been able to see the event get fired in my own application using this code, though.

In the tests, I do in fact see that the $destroy event gets fired if I call element.remove() and the code successfully calls dropdownMenu.remove(). However, in the test browser window the element never gets removed from the page. The remove call seems to do nothing.

Any ideas why?

@jessicawangdt
Copy link

+1!!!

@wesleycho
Copy link
Contributor

This needs a test to fix the garbage collection.

@rysilva
Copy link
Contributor Author

rysilva commented Mar 25, 2015

@wesleycho do you mean it needs a fix to test the garbage collection?

I had a test that looked like this:

it('removes the menu when the dropdown is removed', function() {
  element.remove();
  $rootScope.$digest();
  //Here, I am able to verify that line 80 (self.dropdownMenu.remove();) is in fact called but it has no effect in the test environment.
});

What I was referring to in my comment was that I was unable to verify the outcome of self.dropdownMenu.remove() because it remained in the DOM in the test runner's browser, even though I could verify that self.dropdownMenu was defined and referred to the correct element. I'll give it another shot, but I was hoping there might be some testing quirk that I didn't know about.

@wesleycho
Copy link
Contributor

@rysilva if you're able to do so, I'm willing to review this again and merge when ready.

Perhaps element.remove() did not properly garbage collection the $scope and emit the $destroy event?

@jessicawangdt
Copy link

@rysilva, @wesleycho : looking forward to this fix, thanks to both of you.

@andyperlitch
Copy link

@rysilva and @wesleycho, I believe I understand what is happening: the element is not being cleaned up after each test. In other words, element.remove() needs to be called at the end of his test. This is what triggers the removal of the dropdown from the body. I would actually recommend calling element.remove() in an afterEach block at the top of this whole spec. A lot of tests are doing it in a one-off way anyway, and I see no reason to keep elements around after each test.

I have issued a pull request to @rysilva that not only fixes all this, but also resolves the conflicts with the current master preventing automatic merge. @wesleycho, assuming @rysilva merges my PR to his branch, please review again.

@rysilva
Copy link
Contributor Author

rysilva commented Apr 1, 2015

Thanks, I'll take a look

@rysilva
Copy link
Contributor Author

rysilva commented Apr 1, 2015

I'm not sure why adding an afterEach would solve the issue, because you're already calling element.remove() in the test anyway. So for that test the afterEach should have no effect, right?

I was going to run locally again but I'm currently getting an error running grunt:

Running "karma:continuous" (karma) task
[2015-04-01 08:07:20.330] [ERROR] config - Invalid config file!
 [ReferenceError: module is not defined]

@wesleycho
Copy link
Contributor

You may need to run npm update.

Also the history needs to be cleaned up - the merge commit should not be there, and all of the commits should be squashed into one.

@rysilva rysilva force-pushed the feature/dropdown-add-to-body branch from 2cbc9ef to 55ba210 Compare April 2, 2015 03:02
@rysilva
Copy link
Contributor Author

rysilva commented Apr 2, 2015

Squashed all the commits.

@ghost
Copy link

ghost commented Apr 2, 2015

Cannot wait for this feature to be merged! It fixes all my problems.

@wesleycho wesleycho modified the milestones: 0.13.0, Backlog Apr 2, 2015
@wesleycho wesleycho closed this in dfe9854 Apr 2, 2015
@wesleycho
Copy link
Contributor

Merged - thanks for the good work @rysilva and @andyperlitch !

@andyperlitch
Copy link

all @rysilva... thanks @wesleycho!

@jessicawangdt
Copy link

@andyperlitch , @rysilva , @wesleycho : thanks a lot!!!!!!!!!!!!!!!!!!!!!

fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 9, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
fernando-sendMail pushed a commit to fernando-sendMail/bootstrap that referenced this pull request Jul 16, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add add-to-body option for dropdown
5 participants