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

feat(position): implement auto positioning #4899

Merged
merged 1 commit into from
Nov 23, 2015
Merged

feat(position): implement auto positioning #4899

merged 1 commit into from
Nov 23, 2015

Conversation

RobJacobs
Copy link
Contributor

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.

@icfantv
Copy link
Contributor

icfantv commented Nov 13, 2015

@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).

@wesleycho
Copy link
Contributor

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>
Copy link
Contributor

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*

Copy link
Contributor

Choose a reason for hiding this comment

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

actually **text**

@wesleycho
Copy link
Contributor

Were you able to test this on multiple browsers?

@RobJacobs
Copy link
Contributor Author

@wesleycho PR updated per comments, couple of other tweaks worth noting:

  • Added placementClassPrefix option to tooltip config.
  • Formatted readme.md to resemble dateParser doc.
  • Removed the 'auto' option as the default tooltip behavior so this will be an opt-in feature.

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.

@RobJacobs RobJacobs self-assigned this Nov 16, 2015
@icfantv
Copy link
Contributor

icfantv commented Nov 16, 2015

I should say, awesome work @RobJacobs.

}

while (scrollParent.parentElement && scrollParent !== documentEl) {
var spStyle = $window.getComputedStyle(scrollParent);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@RobJacobs
Copy link
Contributor Author

@icfantv Thank you sir! Once/if this PR is accepted, it should be pretty straight forward to implement on the datepicker and typeahead.

@wesleycho
Copy link
Contributor

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.

@RobJacobs
Copy link
Contributor Author

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:

  • Adding triggers
  • placement attribute
  • is-open attribute
  • append-to-body attribute
  • open/close delay

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.

@wesleycho
Copy link
Contributor

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.
Copy link
Contributor

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)

@wesleycho
Copy link
Contributor

This PR LGTM - just a minor doc quibble, but this is good to merge otherwise.

@icfantv
Copy link
Contributor

icfantv commented Nov 18, 2015

Awwwww yea. @RobJacobs you should do the honors.

@Foxandxss
Copy link
Contributor

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.

@Foxandxss
Copy link
Contributor

Hold tight. If this doesn't have a demo, the documentation won't show up on the page.

@RobJacobs
Copy link
Contributor Author

@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).
Copy link
Contributor

Choose a reason for hiding this comment

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

Calculates

@Foxandxss
Copy link
Contributor

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.

@RobJacobs
Copy link
Contributor Author

@Foxandxss Fixed 'calculate' typo, updated tooltip and popover examples to showcase all available positions. Let me know if you see anything else, thanks.

@Foxandxss
Copy link
Contributor

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.

@wesleycho wesleycho added this to the 1.0.0 milestone Nov 23, 2015
Implementing the ability to auto position elements
in the position service - positionElements function.

Closes 4899
@RobJacobs RobJacobs merged commit d265113 into angular-ui:master Nov 23, 2015
@RobJacobs RobJacobs deleted the feat-auto-position branch November 23, 2015 19:49
@momoadeli
Copy link

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?

@icfantv
Copy link
Contributor

icfantv commented Nov 23, 2015

@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 master and will be in the official 1.0 release. This release is on our radar and we really want to release it by the end of the year, but as of right now we don't have a target date. If you want to start using it, feel free to pull master and run npm install followed by grunt to build your own SNAPSHOT copy. The built/generated files will be in the dist directory.

@momoadeli
Copy link

@icfantv Much appreciated. To address this immediately, do you have any links you can suggest to resolve this meanwhile?

@icfantv
Copy link
Contributor

icfantv commented Nov 24, 2015

Not sure I follow, @megabyzus.

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.

Add smart/fixed positioning option for components with dropdowns/popups and for tooltips/popovers
5 participants