-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(positioning): use CSS translate for positioning
- Loading branch information
1 parent
932d7f6
commit 64d5716
Showing
16 changed files
with
324 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
e2e-app/src/app/tooltip/position/tooltip-position.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<h3>Tooltip positioning tests</h3> | ||
|
||
<form id="default"> | ||
<div class="m-3"> | ||
<button class="btn btn-outline-secondary mx-1" id="flex-left" (click)="setPosition('start')">Left</button> | ||
<button class="btn btn-outline-secondary mx-1" id="flex-center" (click)="setPosition('center')">Center</button> | ||
<button class="btn btn-outline-secondary mx-1" id="flex-right" (click)="setPosition('end')">Right</button> | ||
</div> | ||
<div class="d-flex {{flexPosition}}"> | ||
<div class="d-flex flex-column mx-3"> | ||
<button id="btn-normal" type="button" container="body" triggers="click" class="btn btn-outline-secondary" placement="auto" [ngbTooltip]="content"> | ||
Normal tooltip | ||
</button> | ||
|
||
<button id="btn-innerHtml" type="button" container="body" triggers="click" class="btn btn-outline-secondary" [placement]="['top', 'top-left', 'top-right']" [ngbTooltip]="tooltipHtml"> | ||
InnerHtml | ||
</button> | ||
|
||
<button id="btn-body-off" type="button" container="body" triggers="click" class="btn btn-outline-secondary" placement="auto" [ngbTooltip]="content"> | ||
body off | ||
</button> | ||
|
||
</div> | ||
<ng-template #tooltipHtml><div [innerHtml]="content"></div></ng-template> | ||
</div> | ||
<div class="m-3"> | ||
<button id="btn-fixed" type="button" triggers="click" class="btn btn-outline-secondary position-fixed" [placement]="['top', 'top-left', 'top-right']" [ngbTooltip]="tooltipHtml" [ngStyle]="{'left': fixedPositionLeft, 'right': fixedPositionRight}"> | ||
Fixed | ||
</button> | ||
</div> | ||
</form> |
27 changes: 27 additions & 0 deletions
27
e2e-app/src/app/tooltip/position/tooltip-position.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
@Component({templateUrl: './tooltip-position.component.html'}) | ||
export class TooltipPositionComponent { | ||
flexPosition = 'justify-content-start'; | ||
content = 'Lorem ipsum dolor sit amet consectetur adipisicing elit.'; | ||
fixedPositionLeft = '20px'; | ||
fixedPositionRight = ''; | ||
|
||
setPosition(position: 'start' | 'center' | 'end') { | ||
this.flexPosition = `justify-content-${position}`; | ||
switch (position) { | ||
case 'start': | ||
this.fixedPositionLeft = '20px'; | ||
this.fixedPositionRight = ''; | ||
break; | ||
case 'center': | ||
this.fixedPositionLeft = '50%'; | ||
this.fixedPositionRight = ''; | ||
break; | ||
case 'end': | ||
this.fixedPositionLeft = ''; | ||
this.fixedPositionRight = '20px'; | ||
break; | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
e2e-app/src/app/tooltip/position/tooltip-position.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import {openUrl} from '../../tools.po'; | ||
import {TooltipPositionPage as TooltipPositionPage} from './tooltip-position.po'; | ||
|
||
const roundLocation = function(location) { | ||
location.x = Math.round(location.x); | ||
location.y = Math.round(location.y); | ||
|
||
return location; | ||
}; | ||
|
||
describe('Tooltip Position', () => { | ||
let page: TooltipPositionPage; | ||
|
||
const expectTooltipsPosition = async(type: string, expectedPlacement: string) => { | ||
|
||
|
||
const btn = page.getTooltipButton(type); | ||
await btn.click(); | ||
const btnLocation = roundLocation(await btn.getLocation()); | ||
const btnSize = await btn.getSize(); | ||
const tooltip = await page.getTooltip(); | ||
const tooltipLocation = roundLocation(await tooltip.getLocation()); | ||
const tooltipSize = await tooltip.getSize(); | ||
|
||
let [primary, secondary] = expectedPlacement.split('-'); | ||
const classname = await tooltip.getAttribute('class'); | ||
expect(classname).toContain(`bs-tooltip-${primary}`, 'Missing primary class'); | ||
if (secondary) { | ||
expect(classname).toContain(`bs-tooltip-${primary}-${secondary}`, 'Missing secondary class'); | ||
} | ||
|
||
let yDiff: number, xDiff: number; | ||
|
||
if (primary === 'top') { | ||
yDiff = (tooltipLocation.y + tooltipSize.height) - btnLocation.y; | ||
if (secondary === 'left') { | ||
xDiff = tooltipLocation.x - btnLocation.x; | ||
} else if (secondary === 'right') { | ||
xDiff = (tooltipLocation.x + tooltipSize.width) - (btnLocation.x + btnSize.width); | ||
} else { | ||
xDiff = (tooltipLocation.x + tooltipSize.width / 2) - (btnLocation.x + (btnSize.width / 2)); | ||
} | ||
} | ||
|
||
if (primary === 'left') { | ||
yDiff = (tooltipLocation.y + tooltipSize.height / 2) - (btnLocation.y + btnSize.height / 2); | ||
xDiff = (tooltipLocation.x + tooltipSize.width) - btnLocation.x; | ||
} | ||
|
||
if (primary === 'right') { | ||
yDiff = (tooltipLocation.y + tooltipSize.height / 2) - (btnLocation.y + btnSize.height / 2); | ||
xDiff = tooltipLocation.x - (btnLocation.x + btnSize.width); | ||
} | ||
|
||
|
||
expect(Math.abs(yDiff)) | ||
.toBeLessThanOrEqual(1, `Tooltip top positionning for expected placement '${expectedPlacement}'`); | ||
expect(Math.abs(xDiff)) | ||
.toBeLessThanOrEqual(1, `Tooltip left positionning for expected placement '${expectedPlacement}'`); | ||
|
||
// Close the tooltip | ||
await btn.click(); | ||
}; | ||
|
||
beforeAll(() => page = new TooltipPositionPage()); | ||
|
||
beforeEach(async() => await openUrl('tooltip/position')); | ||
|
||
it(`should be well positionned on the left edge`, async() => { | ||
page.selectPosition('left'); | ||
await expectTooltipsPosition('normal', 'right'); | ||
await expectTooltipsPosition('innerHtml', 'top-left'); | ||
await expectTooltipsPosition('body-off', 'right'); | ||
await expectTooltipsPosition('fixed', 'top-left'); | ||
}); | ||
|
||
it(`should be well positionned on the center`, async() => { | ||
page.selectPosition('center'); | ||
await expectTooltipsPosition('normal', 'top'); | ||
await expectTooltipsPosition('innerHtml', 'top'); | ||
await expectTooltipsPosition('body-off', 'top'); | ||
await expectTooltipsPosition('fixed', 'top'); | ||
}); | ||
|
||
it(`should be well positionned on the right edge`, async() => { | ||
page.selectPosition('right'); | ||
await expectTooltipsPosition('normal', 'left'); | ||
await expectTooltipsPosition('innerHtml', 'top-right'); | ||
await expectTooltipsPosition('body-off', 'left'); | ||
await expectTooltipsPosition('fixed', 'top-right'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {$} from 'protractor'; | ||
|
||
export class TooltipPositionPage { | ||
getTooltip() { return $('ngb-tooltip-window'); } | ||
|
||
getTooltipButton(type: string) { return $(`#btn-${type}`); } | ||
|
||
async selectPosition(position: string) { await $(`#flex-${position}`).click(); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.