Skip to content

Commit

Permalink
fix(popover): Popover position fix with scrollable div when adaptive …
Browse files Browse the repository at this point in the history
…position was enabled (#6423)

Co-authored-by: udayk <uday.appam@wavemaker.com>
  • Loading branch information
UdayAppam and udayk committed Jan 28, 2022
1 parent 58a6e00 commit 3e818fd
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 1 deletion.
5 changes: 5 additions & 0 deletions apps/ngx-bootstrap-docs/src/ng-api-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3318,6 +3318,11 @@ export const ngdoc: any = {
"defaultValue": "click",
"type": "string",
"description": "<p>Specifies events that should trigger. Supports a space separated list of\nevent names.</p>\n"
},
{
"name": "boundariesElement",
"type": "\"viewport\" | \"scrollParent\" | \"window\"",
"description": ""
}
],
"outputs": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.container {
height:100px;
overflow: auto;
}
.btn-padding {
padding: 15px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="container">

<div class="btn-padding">
<button type="button" class="btn btn-default btn-secondary"
popover="Vivamus sagittis lacus vel augue laoreet rutrum faucibus." popoverTitle="Popover on top"
[adaptivePosition]="true" container="body" boundariesElement="viewport" placement="top">
Popover on top
</button>

</div>


<div class="btn-padding">
<button type="button" class="btn btn-default btn-secondary"
popover="Vivamus sagittis lacus vel augue laoreet rutrum faucibus." popoverTitle="Popover on bottom"
[adaptivePosition]="true" container="body" boundariesElement="viewport" placement="bottom">
Popover on bottom
</button>
</div>

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from '@angular/core';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'demo-popover-adaptive-position-overflow-boundary',
templateUrl: './adaptive-position-overflow-boundary.html',
styleUrls: ['./adaptive-position-overflow-boundary.css']

})
export class DemoAdaptivePositionOverflowBoundaryComponent {}
2 changes: 2 additions & 0 deletions libs/doc-pages/popover/src/lib/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import { DemoPopoverStylingLocalComponent } from './styling-local/styling-local'
import { DemoPopoverTriggersCustomComponent } from './triggers-custom/triggers-custom';
import { DemoPopoverTriggersManualComponent } from './triggers-manual/triggers-manual';
import { DemoPopoverCornerPlacementComponent } from './corner-placement/corner-placement';
import { DemoAdaptivePositionOverflowBoundaryComponent } from './adaptive-position-overflow-boundary/adaptive-position-overflow-boundary';

export const DEMO_COMPONENTS = [
DemoPopoverAdaptivePositionComponent,
DemoAdaptivePositionOverflowBoundaryComponent,
DemoPopoverBasicComponent,
DemoPopoverByIsOpenPropComponent,
DemoPopoverClassComponent,
Expand Down
16 changes: 16 additions & 0 deletions libs/doc-pages/popover/src/lib/popover-section.list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
NgApiDocComponent,
NgApiDocConfigComponent
} from '@ngx-bootstrap-doc/docs';
import { DemoAdaptivePositionOverflowBoundaryComponent } from './demos/adaptive-position-overflow-boundary/adaptive-position-overflow-boundary';

export const demoComponentContent: ContentSection[] = [
{
Expand Down Expand Up @@ -73,6 +74,16 @@ export const demoComponentContent: ContentSection[] = [
html: require('!!raw-loader!./demos/adaptive-position/adaptive-position.html'),
outlet: DemoPopoverAdaptivePositionComponent
},
{
title: 'Adaptive position with overflow boundary',
anchor: 'adaptive-position-overflow-boundary',
description: `
<p>You can control the popover boundaries via <code>boundariesElement</code> input or config option. <code>boundariesElement</code> property of a popover can contain boundaries namely <code>viewport, scrollParent, window</code>.</p>
`,
component: require('!!raw-loader!./demos/adaptive-position-overflow-boundary/adaptive-position-overflow-boundary.ts'),
html: require('!!raw-loader!./demos/adaptive-position-overflow-boundary/adaptive-position-overflow-boundary.html'),
outlet: DemoAdaptivePositionOverflowBoundaryComponent
},
{
title: 'Dismiss on next click',
anchor: 'popover-dismiss',
Expand Down Expand Up @@ -240,6 +251,11 @@ export const demoComponentContent: ContentSection[] = [
anchor: 'adaptive-position-ex',
outlet: DemoPopoverAdaptivePositionComponent
},
{
title: 'Adaptive position with overflow boundary',
anchor: 'adaptive-position-overflow-boundary-ex',
outlet: DemoAdaptivePositionOverflowBoundaryComponent
},
{
title: 'Dismiss on next click',
anchor: 'popover-dismiss-ex',
Expand Down
2 changes: 2 additions & 0 deletions src/popover/popover.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ export class PopoverConfig {
container?: string;
/** delay before showing the tooltip */
delay = 0;

boundariesElement?:string;
}
5 changes: 4 additions & 1 deletion src/popover/popover.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class PopoverDirective implements OnInit, OnDestroy {
popoverId = id++;
/** sets disable adaptive position */
@Input() adaptivePosition = true;

@Input() boundariesElement?: ('viewport' | 'scrollParent' | 'window');
/**
* Content to be displayed as popover.
*/
Expand Down Expand Up @@ -159,7 +161,8 @@ export class PopoverDirective implements OnInit, OnDestroy {
enabled: this.adaptivePosition
},
preventOverflow: {
enabled: this.adaptivePosition
enabled: this.adaptivePosition,
boundariesElement: this.boundariesElement || 'scrollParent'
}
}
});
Expand Down

0 comments on commit 3e818fd

Please sign in to comment.