Skip to content

Commit

Permalink
support for popperOnUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFrankel committed Jul 16, 2018
1 parent 3524b70 commit 61115e3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ SystemJS
| popperApplyClass | string | undefined | list of comma separated class to apply on ngpx__container |
| popperStyles | Object | undefined | Apply the styles object, aligned with ngStyles |
| popperApplyArrowClass | string | undefined | list of comma separated class to apply on ngpx__arrow |
| popperOnShown | EventEmitter<void>| $event | Event handler when popper is shown |
| popperOnHidden | EventEmitter<void>| $event | Event handler when popper is hidden |
| popperOnShown | EventEmitter<> | $event | Event handler when popper is shown |
| popperOnHidden | EventEmitter<> | $event | Event handler when popper is hidden |
| popperOnUpdate | EventEmitter<> | $event | Event handler when popper is updated |
| popperAriaDescribeBy | string | undefined | Define value for aria-describeby attribute |
| popperAriaRole | string | popper | Define value for aria-role attribute |

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-popper",
"version": "4.0.1",
"version": "4.1.0",
"description": "ngx-popper is an angular wrapper for popper.js",
"directories": {
"test": "test"
Expand Down
21 changes: 12 additions & 9 deletions src/popper-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {Placements, Triggers, PopperContentOptions} from './popper-model';
}
.ngxp__container .ngxp__arrow {
.ngxp__container > .ngxp__arrow {
border-color: grey;
width: 0;
height: 0;
Expand All @@ -72,7 +72,7 @@ import {Placements, Triggers, PopperContentOptions} from './popper-model';
margin-bottom: 5px;
}
.ngxp__container[x-placement^="top"] .ngxp__arrow {
.ngxp__container[x-placement^="top"] > .ngxp__arrow {
border-width: 5px 5px 0 5px;
border-right-color: transparent;
border-bottom-color: transparent;
Expand All @@ -83,7 +83,7 @@ import {Placements, Triggers, PopperContentOptions} from './popper-model';
margin-bottom: 0;
}
.ngxp__container[x-placement^="top"] .ngxp__arrow.__force-arrow {
.ngxp__container[x-placement^="top"] > .ngxp__arrow.__force-arrow {
border-right-color: transparent!important;
border-bottom-color: transparent!important;
border-left-color: transparent!important;
Expand All @@ -93,7 +93,7 @@ import {Placements, Triggers, PopperContentOptions} from './popper-model';
margin-top: 5px;
}
.ngxp__container[x-placement^="bottom"] .ngxp__arrow {
.ngxp__container[x-placement^="bottom"] > .ngxp__arrow {
border-width: 0 5px 5px 5px;
border-top-color: transparent;
border-right-color: transparent;
Expand All @@ -104,7 +104,7 @@ import {Placements, Triggers, PopperContentOptions} from './popper-model';
margin-bottom: 0;
}
.ngxp__container[x-placement^="bottom"] .ngxp__arrow.__force-arrow {
.ngxp__container[x-placement^="bottom"] > .ngxp__arrow.__force-arrow {
border-top-color: transparent!important;
border-right-color: transparent!important;
border-left-color: transparent!important;
Expand All @@ -114,7 +114,7 @@ import {Placements, Triggers, PopperContentOptions} from './popper-model';
margin-left: 5px;
}
.ngxp__container[x-placement^="right"] .ngxp__arrow {
.ngxp__container[x-placement^="right"] > .ngxp__arrow {
border-width: 5px 5px 5px 0;
border-top-color: transparent;
border-bottom-color: transparent;
Expand All @@ -125,7 +125,7 @@ import {Placements, Triggers, PopperContentOptions} from './popper-model';
margin-right: 0;
}
.ngxp__container[x-placement^="right"] .ngxp__arrow.__force-arrow {
.ngxp__container[x-placement^="right"] > .ngxp__arrow.__force-arrow {
border-top-color: transparent!important;
border-bottom-color: transparent!important;
border-left-color: transparent!important;
Expand All @@ -135,7 +135,7 @@ import {Placements, Triggers, PopperContentOptions} from './popper-model';
margin-right: 5px;
}
.ngxp__container[x-placement^="left"] .ngxp__arrow {
.ngxp__container[x-placement^="left"] > .ngxp__arrow {
border-width: 5px 0 5px 5px;
border-top-color: transparent;
border-bottom-color: transparent;
Expand All @@ -146,7 +146,7 @@ import {Placements, Triggers, PopperContentOptions} from './popper-model';
margin-right: 0;
}
.ngxp__container[x-placement^="left"] .ngxp__arrow.__force-arrow {
.ngxp__container[x-placement^="left"] > .ngxp__arrow.__force-arrow {
border-top-color: transparent!important;
border-bottom-color: transparent!important;
border-right-color: transparent!important;
Expand Down Expand Up @@ -217,6 +217,8 @@ export class PopperContent implements OnDestroy {

arrowColor: string | null = null;

onUpdate: Function;

private globalResize: any;

@ViewChild("popperViewRef")
Expand Down Expand Up @@ -260,6 +262,7 @@ export class PopperContent implements OnDestroy {
let popperOptions: Popper.PopperOptions = <Popper.PopperOptions>{
placement: this.popperOptions.placement,
positionFixed: this.popperOptions.positionFixed,
onUpdate: this.onUpdate,
modifiers: {
arrow: {
element: this.popperViewRef.nativeElement.querySelector('.ngxp__arrow')
Expand Down
20 changes: 14 additions & 6 deletions src/popper-directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,13 @@ export class PopperController implements OnInit, OnChanges {
styles: Object | undefined;

@Output()
popperOnShown = new EventEmitter<PopperController>();
popperOnShown: EventEmitter<PopperController> = new EventEmitter<PopperController>();

@Output()
popperOnHidden = new EventEmitter<PopperController>();
popperOnHidden: EventEmitter<PopperController> = new EventEmitter<PopperController>();

@Output()
popperOnUpdate: EventEmitter<any> = new EventEmitter<any>();

hideOnClickOutsideHandler($event: MouseEvent): void {
if (this.disabled || !this.hideOnClickOutside) {
Expand Down Expand Up @@ -157,7 +160,7 @@ export class PopperController implements OnInit, OnChanges {
this.eventListeners.push(this.renderer.listen(this.elementRef.nativeElement, 'mouseleave', this.scheduledHide.bind(this, null, this.hideTimeout)));
break;
}
if(this.showTrigger !== Triggers.HOVER && this.hideOnMouseLeave){
if (this.showTrigger !== Triggers.HOVER && this.hideOnMouseLeave) {
this.eventListeners.push(this.renderer.listen(this.elementRef.nativeElement, 'touchend', this.scheduledHide.bind(this, null, this.hideTimeout)));
this.eventListeners.push(this.renderer.listen(this.elementRef.nativeElement, 'touchcancel', this.scheduledHide.bind(this, null, this.hideTimeout)));
this.eventListeners.push(this.renderer.listen(this.elementRef.nativeElement, 'mouseleave', this.scheduledHide.bind(this, null, this.hideTimeout)));
Expand Down Expand Up @@ -259,7 +262,7 @@ export class PopperController implements OnInit, OnChanges {
}

hide() {
if(this.disabled){
if (this.disabled) {
return;
}
if (!this.shown) {
Expand All @@ -279,7 +282,7 @@ export class PopperController implements OnInit, OnChanges {
}

scheduledShow(delay: number | undefined = this.showDelay) {
if(this.disabled){
if (this.disabled) {
return;
}
this.overrideHideTimeout();
Expand All @@ -290,7 +293,7 @@ export class PopperController implements OnInit, OnChanges {
}

scheduledHide($event: any = null, delay: number = this.hideTimeout) {
if(this.disabled){
if (this.disabled) {
return;
}
this.overrideShowTimeout();
Expand Down Expand Up @@ -378,6 +381,7 @@ export class PopperController implements OnInit, OnChanges {
hideOnMouseLeave: this.hideOnMouseLeave,
styles: this.styles
});
popperRef.onUpdate = this.onPopperUpdate.bind(this);
this.subscriptions.push(popperRef.onHidden.subscribe(this.hide.bind(this)));
}

Expand All @@ -395,4 +399,8 @@ export class PopperController implements OnInit, OnChanges {
return this.getScrollParent(node.parentNode) || document;
}

private onPopperUpdate(event) {
this.popperOnUpdate.emit(event);
}

}

0 comments on commit 61115e3

Please sign in to comment.