-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(positioning): correctly consider the viewport #1899
Conversation
@burnedram thnx! |
@burnedram I was not able to follow the main issue you are targeting. I have tested your PR and it does not seems to be resolving the issue you demonstrated in plunker. Or is it that I misunderstood something? |
The issue I am trying to solve is how "auto" placement is resolved. As seen in the plunkr, the button labelled "auto" (which has the attribute "placement='auto'") is placed above the button, even though there is not enough (horizontal) space for the popover. Another bug can be seen in the plunkr as well. The "left" button has a proper popover, because there is enough horizontal and vertical space. "top" and "bottom" however gets squished by the browser as it is too close to the edge of the viewport. It seems because the popover gets squished, the calculations done in order to horizontally center the popover is no longer correct. It is not my intent to fix this bug, as I don't really know how one should react to there not being enough space in a position strictly chosen by the user. Edit: Clarification: When the popover is squished both horizontal and vertical alignment is incorrect in the case of "top", exaggerating the problem. However, one can mitigate the centering bug by using "auto", but as I've described here, the "auto" algorithm is broken. |
Here is an example of what my pull requests fixes. Current ng-bootstrap, popover is (almost) always positioned above. Edit: position is "auto" in both GIFs |
@pkozlowski-opensource @mschoudry Sorry for bumping, just wondering if there is anything else I should change or clarify 😃 |
@burnedram : thnx for the updates wouldn't it be better to resolve only those, rather than refactoring everything? Regards, |
@mschoudry If you meant "when the popup width is bigger than the viewport width", then yes, that is the issue I'm trying to solve. (By "width" I mean both horizontal position and width) The reasoning behind refactoring the code was to improve readability. I have essentially moved all conditions inside if-statements and given them a name. This also has a bonus in that if-statements that share conditions doesn't need code repetition, which reduces the chance of missing to implement a change in all if-statements. Now each placement's reasoning can be understood by reading the code, instead of having to think about what all the expressions means. I also opted to remove/rewrite/relocate the Ofcourse, the bug could probably be solved by just changing the code around those two lines, but I can't help to think that the bug occured due to the code being difficult to follow. |
I realise that refactoring isn't always the best option in open-source projects, as it might break other pull requests and general code history, and it is of course up to you if you believe it is acceptable in this case. |
@burnedram seems like some of the issues referenced in this PR are already fixed:
Could you please:
Thnx! |
What's the status on this? Still waiting for this to make it in to fix #1898. This is crucial for my app. |
Anyone still working on this? This is still very much a bug. |
bbae7ac
to
8a6285e
Compare
@pkozlowski-opensource I also changed "auto" to include all secondary placements, as there are situations where no primary placement is available. I also think that "auto" should consider all possible placements. New plnkr that shows how broken "auto" is |
Note on the failed CI build: master is failing I've run the tests locally, and they passed (except for two relating to "ngbFocusTrap" and "ngb-typeahead", which also fails on master) |
8a6285e
to
6cea662
Compare
@pkozlowski-opensource |
@pkozlowski-opensource Any chance this can be added to the next release? Seems like it's been fixed for a while now... |
Merged. Thnx @burnedram for the PR and rebasing it, much appreciated! |
Fixes #1898, fixes #1876.
I'm not sure about #1896, as I have not tested this specific use case.