Skip to content
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

WIP - feat(popover): Add container input, support 'body' selector #853

Closed
wants to merge 10 commits into from
Closed

Conversation

spongessuck
Copy link
Contributor

@spongessuck spongessuck commented Oct 8, 2016

Adds an appendToRoot input to the popover component to allow for placement of the popover in the root element. Addresses #852.

I'm not sure about the cross-platform implications of this solution, but it works in the browser, is analogous to the ui-bootstrap appendToBody option, and makes popover DOM placement more flexible until #339 is implemented.

@spongessuck spongessuck changed the title Fix #852 Add appendToRoot input to popover component Oct 8, 2016
@spongessuck spongessuck changed the title Add appendToRoot input to popover component feat: Add appendToRoot input to popover component Oct 8, 2016
@spongessuck spongessuck changed the title feat: Add appendToRoot input to popover component feat(popover): Add appendToRoot input Oct 8, 2016
@pkozlowski-opensource
Copy link
Member

@spongessuck thnx for the PR, it looks like a first good step. Having said this I had a slightly different plan for this. My intention was to introduce @Input with the name container and type string and default value being undefined. For now this input would only kick in for the value equal to body. In the future we could extend / open up it to support any selector / element reference.

With my proposal we would be not introducing APIs that would be redundant / deprecated in the future.

Would you be willing to do the above changes in your PR?

@spongessuck
Copy link
Contributor Author

Sure, it shouldn't be hard.

@spongessuck
Copy link
Contributor Author

What about container="root", to be consistent? The positioning service measures the offset based on the html element.

@pkozlowski-opensource
Copy link
Member

What about container="root", to be consistent? The positioning service measures the offset based on the html element.

I would prefer '"body"' for now as it will still work when we add support for all selectors.

Sure, it shouldn't be hard.

Awesome!

@spongessuck
Copy link
Contributor Author

I'll do "html" then. I still think it's a bad idea to call it "body" when it's not measuring from the body.

@pkozlowski-opensource
Copy link
Member

I'll do "html" then. I still think it's a bad idea to call it "body" when it's not measuring from the body

Could we please stick to body? I understand your arguments but I want to keep body as default as this is what is shown in BS docs. And as things stand today it doesn't really matter what is measured from but rather where the element is attached.

@spongessuck
Copy link
Contributor Author

If the body has any padding or margin I don't think it will be placed properly if it's in the body.

@spongessuck
Copy link
Contributor Author

I guess it'd have to be positioned relative too... I'll do some tests, but do you see my concern?

@spongessuck
Copy link
Contributor Author

Did some tests and it doesn't seem to matter where the body is- the position service is smarter than I thought :). I'll use "body" as requested.

@spongessuck spongessuck changed the title feat(popover): Add appendToRoot input WIP - feat(popover): Add container input, support 'body' selector Oct 8, 2016
@@ -95,6 +109,7 @@ export class NgbPopover implements OnInit, OnDestroy {
this._windowRef = this._popupService.open(this.ngbPopover);
this._windowRef.instance.placement = this.placement;
this._windowRef.instance.title = this.popoverTitle;
this._windowRef.instance.container = this.container;

Choose a reason for hiding this comment

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

Does popover window need to be aware of the container option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it doesn't.

@@ -34,6 +34,7 @@ import {NgbPopoverConfig} from './popover-config';
export class NgbPopoverWindow {
@Input() placement: 'top' | 'bottom' | 'left' | 'right' = 'top';
@Input() title: string;
@Input() container: string;

Choose a reason for hiding this comment

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

Why do we need this input?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto.

@@ -382,6 +403,7 @@ describe('ngb-popover', () => {
config = c;
config.placement = 'bottom';
config.triggers = 'hover';
config.container = 'body';

Choose a reason for hiding this comment

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

Why do we need to modify this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't this apply to popover and not popoverwindow? Shouldn't it test that it takes custom config properly?

Choose a reason for hiding this comment

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

Oh, right, sorry for the noise.

this.container === 'body');

if (this.container === 'body') {
let windowEl = this._windowRef.location.nativeElement;

Choose a reason for hiding this comment

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

Nit: maybe drop the temporary windowEl variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's carried over from when I was using the native ref in a few more operations- I guess it can be dropped, but I think it makes it more readable.

Choose a reason for hiding this comment

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

Whatever you prefer, I'm good either way.

@@ -191,6 +193,25 @@ describe('ngb-popover', () => {
});
});

describe('placement', () => {

Choose a reason for hiding this comment

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

Nit: 'placement' => 'container'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

@pkozlowski-opensource
Copy link
Member

Thnx for all the updates @spongessuck - it all starts to come together 👍
I've just left some minor comments that we need to sort out before merging.

@pkozlowski-opensource pkozlowski-opensource added this to the alpha.8 milestone Oct 8, 2016
@spongessuck
Copy link
Contributor Author

Not sure if you got notifs from my commits, but I think this is good to go.

@pkozlowski-opensource
Copy link
Member

Thnx @spongessuck - squashed and merged as d1a22c0. Would be awesome if you could send a similar (well, almost identical) PR for tooltips :-)

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

Successfully merging this pull request may close these issues.

None yet

2 participants