-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat(position): implement auto positioning #4899
Conversation
@RobJacobs, is this for the 1.2 release or were you thinking 1.0? @wesleycho? What would you guys think about having it as a beta feature (if that's even possible). |
This is just the $uibPosition service |
@@ -0,0 +1,180 @@ | |||
The `$uibPosition` service provides a set of DOM utilities used internally to absolute-position an element in relation to another element (tooltips, popovers, typeaheads etc...). | |||
|
|||
#### <strong>getRawNode(element)</strong> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not hugely opinionated, but you can get the <strong>
formatting from *text*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually **text**
Were you able to test this on multiple browsers? |
@wesleycho PR updated per comments, couple of other tweaks worth noting:
I've tested this change on the latest versions of Chrome, Firefox, Edge, IE11, IE10 & 9 using IE11 emulation mode, and on an iPad with iOS9. |
I should say, awesome work @RobJacobs. |
} | ||
|
||
while (scrollParent.parentElement && scrollParent !== documentEl) { | ||
var spStyle = $window.getComputedStyle(scrollParent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the best way to do this? getComputedStyle
is a pretty expensive function, and inside a while loop could be quite pricey. What happens if this never finds an absolutely positioned or position static parent element?
How many times at worst will this loop fire?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wesleycho I was concerned about that as well, but it's the same approach the parentOffsetEl function uses in a while loop when calling the isStaticPositioned function. getComputedStyle is the only way I know of to get the styles applied by CSS and not just inline styles that element.style provides.
I could refactor and call the getStyle function instead of calling getComputedStyle directly as I only need the position style value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a bit of sleuthing, and it looks like we can kill getStyle
- looks like it was necessary for IE8 support (IE8 used currentStyle
instead of having the built-in getComputedStyle
function), but it is now unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wesleycho PR updated with getStyle function removed.
@icfantv Thank you sir! Once/if this PR is accepted, it should be pretty straight forward to implement on the datepicker and typeahead. |
We also want this implemented on the dropdown as well. This is amazing work btw - I took a stab at this before, but positioning turns out to be quite formidable. |
Implementing this on the dropdown will present a different set of challenges as the TWBS dropdown relies more on CSS for positioning as I described in #4762, but I'm confident it is possible. Next thing I want to look at is coming up with a generic 'popup' directive that would encapsulate some of the redundant code I'm seeing:
And switch datepicker, typeahead, popover, and dropdown directives to use that. Then trim down the tooltip directive to serve just that purpose - tooltips. It's getting pretty heavy trying to support all the different use cases. |
For the dropdown, we can restrict it to being positioned up, and maybe auto with only up being applied. |
The `$uibPosition` service provides a set of DOM utilities used internally to absolute-position an element in relation to another element (tooltips, popovers, typeaheads etc...). | ||
|
||
### getRawNode(element) | ||
Takes a jQuery/jQLite element and converts it to a raw DOM element. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should be jqLite
(minor quibble)
This PR LGTM - just a minor doc quibble, but this is good to merge otherwise. |
Awwwww yea. @RobJacobs you should do the honors. |
You can merge it. I will check the docs in another moment and fix them if I feel like I have to. Sorry hadn't time to check it properly. |
Hold tight. If this doesn't have a demo, the documentation won't show up on the page. |
@Foxandxss Added demo page, @wesleycho Fixed jqLite typo. Let me know if you see any other issues. |
_(Type 'element')_ - The closest positioned ancestor. | ||
|
||
### scrollbarWidth() | ||
Caclulates the browser scrollbar width and caches the result for future calls. Concept from the TWBS measureScrollbar() function in [modal.js](https://github.com/twbs/bootstrap/blob/master/js/modal.js). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calculates
About the demo, it is too technical in my opinion. I liked those demos you put to use where you can see tooltips in certain positions. That + all the technical information that you offers now is for me better. Personally I don't like putting all that huge doc on the page, but we don't have a better mechanism for that either. The doc itself has some nitpicks I want to change (Styling) so I would create a PR when this gets merged. |
@Foxandxss Fixed 'calculate' typo, updated tooltip and popover examples to showcase all available positions. Let me know if you see anything else, thanks. |
It is good to me. There are some fixed docs / demo related I want to do but I better do it in another PR so we don't clutter this too much. |
Implementing the ability to auto position elements in the position service - positionElements function. Closes 4899
Apologies for the intrusion. Does this comprehensively address the popover (and tooltip) running over the edge of the page? If so, when will this be released into the wild (we are on 0.14.3 currently) and, if not, can we leverage this to address this current run-over issue once released? |
@megabyzus, while it is comprehensive, there's no way we can test it like releasing it into the wild for you guys to hammer. It is part of |
@icfantv Much appreciated. To address this immediately, do you have any links you can suggest to resolve this meanwhile? |
Not sure I follow, @megabyzus. |
Implementing the ability to auto position elements in the position service - positionElements function. This will allow tooltips and popovers to position where they fit within the closest scrollable ancestor. As part of this PR I also documented the position service functions and refactored some of the code to make it more readable. Partially closes #4762.