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

refactor(collapse): use ngAnimate #1444

Merged

Conversation

chrisirhc
Copy link
Contributor

Update: After merging #1675, I realized most of that logic can now be moved into collapse, as AngularJS 1.3 supports style options on animation calls. I've refactored it so that accordion and collapse share the same logic.

This is my attempt at #1274 .

@pkozlowski-opensource
Copy link
Member

@chrisirhc this looks really cool! I'm going to start rebasing the BS3 branch today to get the BS3 release out of the doors before the New Year and then we are going to focus on AngularJS 1.2.x.

@chrisirhc
Copy link
Contributor Author

Sounds good. Looking forward to it. 😄 Do tag any issues / pull requests that may need extra hands so I (and others) know which ones to focus on. I looked through the issues tagged with Bootstrap3 and didn't see any that were still awaiting action.

@pkozlowski-opensource
Copy link
Member

@chrisirhc I'm just going over PRs trying to merge the ones that are ready / worth merging. Then going to rebase the BS3 branch and create a milestone for the next release - items in the milestone will need the immediate attention. Will ping you guys on the mailing list ([email protected]) with more details today.

@chrisirhc
Copy link
Contributor Author

Great stuff thank you!

@chrisirhc
Copy link
Contributor Author

Rebased and updated. Take note that the tests currently don't test the $animate methods. But I'm not sure how to go about testing them or whether they need to be tested.

@mvhecke
Copy link
Contributor

mvhecke commented Jan 19, 2014

@chrisirhc I think testing is still necessary in this case, because you're using a service. Maybe this topic is useful?

@ghost ghost assigned ajoslin Jan 19, 2014
@@ -41,7 +44,7 @@ describe('collapse directive', function () {
scope.isCollapsed = false;
scope.$digest();
//No animation timeout here
expect(element.height()).not.toBe(0);
expect(element.hasClass('in')).toBe(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the expect(element).toHaveClass() helper for better error messages

@chrisirhc
Copy link
Contributor Author

Just an update, I'm working on refactoring this PR at the moment so that hopefully collapse will just consist of an in class that can easily be tested.

@ajoslin
Copy link
Contributor

ajoslin commented Jan 21, 2014

I like it! Perhaps we should even consider adding a console.warn() about collapse directive being deprecated, with a link to how to just use it with ng-class.

Currently, it fails to apply to the latest - once you rebase (again! lol) it and fix conflicts I'll test it out.

@chrisirhc
Copy link
Contributor Author

@ajoslin , rebased!

@bekos
Copy link
Contributor

bekos commented Mar 4, 2014

@chrisirhc Can you check why this is failing? I think you need to replace the $timeout flushes with the $animate ones.

@chrisirhc
Copy link
Contributor Author

@bekos I'll look at this in a bit. Meanwhile #1878 is more critical as that's breaking carousel when animations are enabled. Could you help me take a look at that? If no major issues I'm hoping to merge that soon.

@rjokelai
Copy link

Any progress for this one?

@rjokelai
Copy link

It seems that the $animate:before/after/close events are not fired without the inclusion of angular-animate.js in the test libraries as well as modules ngAnimate and mock.animate in the collapse.spec.js. Consequently, the tests checking the height of the element fail.

Furthermore, after adding the aforementioned modules, the lines having

$timeout.flush();

need to be changed to

$animate.flushNext('addClass'); // or 'removeClass'
$timeout.flush();

Moreover, these need to be called each time the states of the collapsed as well as the ng-hide element change.

Currently, I have a working local copy. The only failing test is 'should be shown on initialization if isCollapsed = false without transition', since the $animate possibly needs to be flushed for the in class to be added. Still, I had to do changes like the following example

it('should expand if isCollapsed = false with animation on subsequent use', function() {
  scope.isCollapsed = false;
  scope.$digest();
  scope.isCollapsed = true;
  scope.$digest();
  scope.isCollapsed = false;
  scope.$digest();
  $timeout.flush();
  expect(element.height()).not.toBe(0);
});

to this:

it('should expand if isCollapsed = true with animation on subsequent uses', function() {
  expand();
  collapse();
  expand();
  collapse();
  expect(element.height()).toBe(0);
});

where the expand and collapse functions behave like this

function expand() {
  scope.isCollapsed = false;
  scope.$digest();
  $animate.flushNext('addClass');
  $timeout.flush();
}

@chrisirhc chrisirhc force-pushed the feature/collapse-nganimate-pr branch from 9d5ff5a to 478f5c0 Compare March 23, 2015 03:11
chrisirhc added a commit to chrisirhc/angular-ui-bootstrap that referenced this pull request Mar 23, 2015
- Animations are now opt-in, include ngAnimate to see collapse
  animations

- ngAnimate handles initial state and doesn't animate if first
  reflow hasn't occurred.
  angular/angular.js@cc58460

- Tests may need more work. Right now they test for 'in' class.

Fixes angular-ui#1774
Fixes angular-ui#2821
Fixes angular-ui#2836
Closes angular-ui#1274
Closes angular-ui#1444
@chrisirhc
Copy link
Contributor Author

Updated this PR to move accordion animation logic into collapse directive. Planning to merge this soon.

@chrisirhc chrisirhc modified the milestones: 0.13.0, ngAnimate Mar 23, 2015
@chrisirhc chrisirhc assigned chrisirhc and unassigned ajoslin Mar 23, 2015
@chrisirhc chrisirhc force-pushed the feature/collapse-nganimate-pr branch from 478f5c0 to c8c0418 Compare March 23, 2015 03:14
chrisirhc added a commit to chrisirhc/angular-ui-bootstrap that referenced this pull request Mar 23, 2015
- Animations are now opt-in, include ngAnimate to see collapse
  animations

- ngAnimate handles initial state and doesn't animate if first
  reflow hasn't occurred.
  angular/angular.js@cc58460

- Tests may need more work. Right now they test for 'in' class.

Fixes angular-ui#1774
Fixes angular-ui#2821
Fixes angular-ui#2836
Closes angular-ui#1274
Closes angular-ui#1444
@wesleycho
Copy link
Contributor

This LGTM.

- Animations are now opt-in, include ngAnimate to see collapse
  animations

- ngAnimate handles initial state and doesn't animate if first
  reflow hasn't occurred.
  angular/angular.js@cc58460

- Tests may need more work. Right now they test for 'in' class.

Fixes angular-ui#1774
Fixes angular-ui#2821
Fixes angular-ui#2836
Closes angular-ui#1274
Closes angular-ui#1444
@chrisirhc chrisirhc force-pushed the feature/collapse-nganimate-pr branch from c8c0418 to 36e6363 Compare March 23, 2015 17:47
@chrisirhc chrisirhc merged commit 36e6363 into angular-ui:master Mar 23, 2015
@chrisirhc chrisirhc deleted the feature/collapse-nganimate-pr branch March 23, 2015 17:49
ayakovlevgh pushed a commit to ayakovlevgh/bootstrap that referenced this pull request Mar 24, 2015
- Animations are now opt-in, include ngAnimate to see collapse
  animations

- ngAnimate handles initial state and doesn't animate if first
  reflow hasn't occurred.
  angular/angular.js@cc58460

- Tests may need more work. Right now they test for 'in' class.

Fixes angular-ui#1774
Fixes angular-ui#2821
Fixes angular-ui#2836
Closes angular-ui#1274
Closes angular-ui#1444
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.

8 participants