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

collapse plugin renders a rising scrollbar on bootstrap navbar #5474

Closed
stevebread opened this issue Feb 14, 2016 · 34 comments
Closed

collapse plugin renders a rising scrollbar on bootstrap navbar #5474

stevebread opened this issue Feb 14, 2016 · 34 comments

Comments

@stevebread
Copy link

Plunker: https://plnkr.co/edit/2H4yZfl6zSM0WmVzaba8?p=preview

Make sure the right panel is wide enough so that the navbar does not collapse and you will see a horizontal scrollbar (on initial load / refresh) that floats upwards starting from the bottom of the navbar.

The scrollbar does not appear if the navbar content is added to the file directly instead of using ng-include.

Removing the navbar-right content makes the scrollbar appear to go away but an element is still floating upward which can be detected as it passes over the 'Left' text.

Found this while upgrading from 0.13.4. It was introduced in 0.14.0.

(Edit: changed plunker URL to go straight to preview)
(Edit: mention that this comment is related to ng-include)

@wesleycho
Copy link
Contributor

ng-include is an anti-pattern - there is no good use case for it.

Not able to reproduce this - what OS/browser are you seeing this on?

@stevebread
Copy link
Author

DIdn't know ng-include was an anti-pattern. That's how the angular-fullstack generator sets up the nav bar component.

I am on Win 7 and am able to repro in FF 44.0.2 and Chrome 48.0.2564.109 m

After expanding the right panel in the plunker to show the uncollapsed nav, the preview must be refreshed using the Refresh button in the plunker

@stevebread
Copy link
Author

I tried it with a directive and the behavior is similar to ng-include. When the directive is in the top-level page, the navbar displays fine but when the navbar directive is in a view, then the issue occurs.

Plunkr with a directive: https://plnkr.co/edit/MnGQHgXW8pod42xexkkp?p=preview

I've reproduced all 3 scenarios in this plunker
v1: The original issue using ng-include
v2: No issue when navbar directive is in index.html
v3: Issue when navbar directive is in a view

@davincho
Copy link

+1 - I have got the same problem with the horizontal scrollbar.

@stevebread stevebread changed the title collapse plugin renders a rising scrollbar when bootstrap navbar is included via ng-include collapse plugin renders a rising scrollbar on bootstrap navbar Feb 20, 2016
@kolkov
Copy link

kolkov commented Mar 9, 2016

+1 - I have got the same problem with the horizontal scrollbar.
https://in-frame.com:8088/angular#/home

@vazh
Copy link

vazh commented Apr 6, 2016

im using ng-include too, i thought it was because of collapse. but when i patch the collapse with earlier version the scroll when changing page / refresh doesnt disappear.
im currently already changing to 3 version.
i forgot the first version. but it start with 0.1_._ -> 1.4.0 -> 1.1.0
both collapse scrollbar and navbar scrollbar doesnt disappear.

@Sheparzo
Copy link

+1 - Encountering this issue as well

@kolkov
Copy link

kolkov commented Jul 6, 2016

The problem is when navbar open and close at the same moment.
If in first plunker change
$scope.isCollapsed = true;
to
$scope.isCollapsed = false;
result: no rising scrollbar.

@kolkov
Copy link

kolkov commented Jul 6, 2016

@MetaEvan
Copy link

Encountering this as well.

Kolkov's suggestion to initialize the isCollapsed = false works, but it means that on small screens, the hamburger dropdown defaults to open. On the hamburger menu itself, you get a vertical errant scroll bar, which I was able to disable by setting its overflow to hidden, but this is obviously not optimal.

@jadir-junior
Copy link

@kolkov in this link the navbar isn't with angular-animate.

@jadir-junior
Copy link

i'm with the same problem, if I add angular-animate the scrollbar appear without angular-animate it desapear.

@jadir-junior
Copy link

woooooowww, I think a solution, if I put the css class in my code, working for me
.navbar-collapse.in {
overflow-y: hidden;
}

@stephenHartzell
Copy link

I've been struggling with this same issue for ages. I can't seem to figure out a working solution.

@Rafi993
Copy link

Rafi993 commented Sep 16, 2016

is there any example of this solution used.

@Rafi993
Copy link

Rafi993 commented Sep 16, 2016

Im still having this problem even after using that css class

@stevebread
Copy link
Author

@wesleycho The plunker still shows the scrollbar issue after changing the angular-ui-bootstrap version to 2.1.3. Using the second link above: https://plnkr.co/edit/MnGQHgXW8pod42xexkkp?p=preview

@Rafi993
Copy link

Rafi993 commented Sep 20, 2016

it would be best if somebody puts up working example of the solution before closing the issue

@stephenHartzell
Copy link

I also still see this issue with the latest version of angular bootstrap ui

@Rafi993
Copy link

Rafi993 commented Sep 22, 2016

Please somebody who has solved this issue put up a an updated Plunker example.

@Rafi993
Copy link

Rafi993 commented Sep 22, 2016

@jadir-junior could you provide example of working example

@stevebread
Copy link
Author

@wesleycho This issue was introduced by commit 533a9f0 which switched to using $animateCss. I did some tracing and found that the watcher is called twice and therefore collapse() is called twice. The second execution of collapse() is what produces the rising scrollbar.

The Angular docs for $watch have this to say

Be prepared for multiple calls to your watchExpression because it will execute multiple times in a single $digest cycle if a change is detected.
...
After a watcher is registered with the scope, the listener fn is called asynchronously (via $evalAsync) to initialize the watcher. In rare cases, this is undesirable because the listener is called when the result of watchExpression didn't change

@Rafi993
Copy link

Rafi993 commented Oct 19, 2016

@stevebread did you solve it?

@stevebread
Copy link
Author

stevebread commented Oct 19, 2016

@Rafi993 I can get it to work by patching collapse.js but I'd rather have an official fix. If you are ok to patch it locally, replace this line in collapse.js (or ui-bootstrap-tpls.js if you are using bower)

scope.$watch(attrs.uibCollapse, function(shouldCollapse) {

with

scope.$watch(attrs.uibCollapse, function(shouldCollapse, shouldCollapseOldValue) {
  if(shouldCollapse === shouldCollapseOldValue) return;

@stevebread
Copy link
Author

stevebread commented Oct 23, 2016

I had to look into this some more because I realized that collapse() is not being called twice, the page I was testing with had a second collapsible component in addition to the menu and that's why I was seeing 2 calls. The above fix still works for the navbar but the second collapsible component displays open even though uib-collapse=true

So what's needed then is that if a component is collapsed by default it should have the correct markup i.e. if uib-collapse attribute is true by default, then the element should have collapse class as well. This is how the bootstrap menu is defined. If you are not already doing this then I recommend doing it because it will avoid unnecessary collapse animations when the page renders and the directive doesn't have to try to handle this case.

@mekhtiari
Copy link

Meanwhile this issue is really fixed, this piece of CSS could be a workaround:

.collapsing.in {
  overflow: hidden;
} 

@Rafi993
Copy link

Rafi993 commented Nov 1, 2016

then please post a working plunker example @MohsenEkhtiari

@mekhtiari
Copy link

Sure,
Plunker: https://plnkr.co/edit/BCLseK8C7MEI2ZQijjcS?p=preview

@Rafi993
Copy link

Rafi993 commented Nov 2, 2016

thanks @MohsenEkhtiari

@jonaszuberbuehler
Copy link

@MohsenEkhtiari Your fix didn't work for me. I had to use .in-remove-active to fix it:

.collapsing.in-remove-active {
    overflow: hidden;
}

@mekhtiari
Copy link

mekhtiari commented Nov 25, 2016

@jonaszuberbuehler I have this scrollbar problem when navbar is opening not when it is collapsing or collapsed. Could you provide a plunker case which needs your fix?

@jonaszuberbuehler
Copy link

@MohsenEkhtiari Yes, https://plnkr.co/edit/6TJ4socmsTRicOVoAJUJ?p=preview. I know, ng-include is considered an anti-pattern and should be replaced. But I suppose the code in the plunkr should work.

@davincho
Copy link

@MohsenEkhtiari Still can see the horizontal scrollbar (latest Chrome on Ubuntu 15.10)

@AlexZeitler
Copy link

.fix.navbar-collapse {
  overflow-x: hidden;
}
<div class="collapse fix navbar-collapse" uib-collapse="navCollapsed">

Did the trick for us.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.