panel: updatePosition does not work
Actual Behavior:
What is the issue? *
updatePosition()does not set the correct position if your panel is hidden. It is picking the first option to show below an element when it should show above it to avoid being offscreen. NOTE it works fine if you callshow()thenupdatePosition().What is the expected behavior?It should set the correct position.
CodePen (or steps to reproduce the issue): *
CodePen Demo which shows your issue:Details:
Angular Versions: *
Angular Version:1.5.8Angular Material Version:1.1.1
Additional Information:
Browser Type: *chromeBrowser Version: *53OS: *10.11.6Stack Traces:
Shortcut to create a new CodePen Demo.
Note: * indicates required information. Without this information, your issue may be auto-closed.
Do not modify the titles or questions. Simply add your responses to the ends of the questions. Add more lines if needed.
@epelc I believe that I was able to determine your issue and provide a way to handle it without a code change. Please see https://codepen.io/bradrich/pen/WGLdAz. From what I can see, your issue is either that you were not using the ID parameter within the configuration, which keeps the panel API from creating a new panel with each request, or that you were not caching your panel position properly. If none of this makes sense, the codepen above does a good job explaining everything.
If you are satisfied with this approach, please respond so that I can close this issue.
@bradrich - One question: "Is @epelc's issue a typical issue that developers will probably encounter?" If yes, then we should identify a proactive solution for future encounters... or at least provide a console warning.
@ThomasBurleson The only suggestion that I can make, is to provide a demo for updating the position of a panel and outlining the method that I used in my codepen. There isn't really an issue at all when using the methods that I described. Everything functions as expected. Should I create another issue for adding the updatePosition demo?
@bradrich @ThomasBurleson My issue was with updating a panel that was shown/hidden using the show/hide() methods on panelRef.
Updating the position works perfectly fine if you are willing to reopen/close the panel(as in @bradrich 's demo). My issue is that you cannot update hidden panel before calling show() on it.
ie
panelRef.hide() // you hide the panel instead of closing because it is highly likely the user will reopen again soon
// Update then show does not work. The position update becomes a noop
panelRef.updatePosition(newPosition)
panelRef.show()
// Show then update does work
panelRef.show()
panelRef.updatePosition(newPosition)
It's not that big of a deal given the easy work around. But I think some docs or a fix if it is easy would be good.
@epelc I will run with your comments above and see what I can figure out.
@epelc I updated my pen to use show/hide and wasn't able to reproduce the issue. To see this yourself, go to the pen (https://codepen.io/bradrich/pen/WGLdAz), click the menu icon button, click Hide Menu, click Update Panel Position, then click the menu icon button again and you will be able to see that the panel's position has been updated.
Let me know what you think or if I didn't take the proper steps to reproduce your issue.
@bradrich I just realized it is specifically with the auto positioning calculations when resizing vertically. It's also as far as I can tell only failing when it shouldn't show on the bottom.
Example when using
.addPanelPosition($mdPanel.xPosition.ALIGN_START, $mdPanel.yPosition.ALIGN_TOPS)
.addPanelPosition($mdPanel.xPosition.ALIGN_START, $mdPanel.yPosition.ALIGN_BOTTOMS)
Video: https://drive.google.com/file/d/0B3SnjDk4Ny4-X24zS2hCTVdkTVE/view?usp=sharing
Codepen: https://codepen.io/anon/pen/MjMder?editors=1010
If you update the position after calling show() it works
https://codepen.io/anon/pen/MjMdpQ?editors=1010
I also ran into a similar problem (vertical positioning). I am using the master branch with this change applied https://github.com/angular/material/pull/9944 and it improved the behavior...
But there is still an issue with the vertical positioning the very first time I click on the panel. I just wanted to add that this (or a similar) issue is still there in master with the latest fixes to constrain the panel to the viewport. It only seems to occur for the vertical positioning with the panel is at the bottom of the screen.
It seems the issue I described above was mine. I was trying to do a dynamic template by using ng-include. This resulted in the size not being known the first time the panel was initialized... so it was my problem and probably different from apelc's problem.
Still... #9944 may have the fix you need.