Skip to content

Commit

Permalink
fix(position): wrong placement class applies in some cases (#3042)
Browse files Browse the repository at this point in the history
Fixes #3040
  • Loading branch information
fbasso authored and maxokorokov committed Feb 27, 2019
1 parent 49d48c6 commit 5fdc3fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/popover/popover.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('ngb-popover', () => {
const windowEl = getWindow(fixture.nativeElement);

expect(windowEl).toHaveCssClass('popover');
expect(windowEl).toHaveCssClass(`bs-popover-${defaultConfig.placement}`);
expect(windowEl).toHaveCssClass('bs-popover-top');
expect(windowEl.textContent.trim()).toBe('TitleHello, World!');
expect(windowEl.getAttribute('role')).toBe('tooltip');
expect(windowEl.getAttribute('id')).toBe('ngb-popover-1');
Expand All @@ -133,7 +133,7 @@ describe('ngb-popover', () => {
const windowEl = getWindow(fixture.nativeElement);

expect(windowEl).toHaveCssClass('popover');
expect(windowEl).toHaveCssClass(`bs-popover-${defaultConfig.placement}`);
expect(windowEl).toHaveCssClass('bs-popover-top');
expect(windowEl.textContent.trim()).toBe('TitleHello, John!');
expect(windowEl.getAttribute('role')).toBe('tooltip');
expect(windowEl.getAttribute('id')).toBe('ngb-popover-2');
Expand Down Expand Up @@ -384,8 +384,8 @@ describe('ngb-popover', () => {
expect(windowEl.textContent.trim()).toBe('Great tip!');
});

it('should accept placement in array(second value of the array should be applied)', () => {
const fixture = createTestComponent(`<div ngbPopover="Great tip!" [placement]="['left-top','top-right']"></div>`);
it('should accept placement in array (second value of the array should be applied)', () => {
const fixture = createTestComponent(`<div ngbPopover="Great tip!" [placement]="['left-top','top-left']"></div>`);
const directive = fixture.debugElement.query(By.directive(NgbPopover));

directive.triggerEventHandler('click', {});
Expand All @@ -394,7 +394,7 @@ describe('ngb-popover', () => {

expect(windowEl).toHaveCssClass('popover');
expect(windowEl).toHaveCssClass('bs-popover-top');
expect(windowEl).toHaveCssClass('bs-popover-top-right');
expect(windowEl).toHaveCssClass('bs-popover-top-left');
expect(windowEl.textContent.trim()).toBe('Great tip!');
});

Expand Down
8 changes: 4 additions & 4 deletions src/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('ngb-tooltip', () => {
const windowEl = getWindow(fixture.nativeElement);

expect(windowEl).toHaveCssClass('tooltip');
expect(windowEl).toHaveCssClass(`bs-tooltip-${defaultConfig.placement}`);
expect(windowEl).toHaveCssClass('bs-tooltip-top');
expect(windowEl.textContent.trim()).toBe('Great tip!');
expect(windowEl.getAttribute('role')).toBe('tooltip');
expect(windowEl.getAttribute('id')).toBe('ngb-tooltip-0');
Expand Down Expand Up @@ -270,9 +270,9 @@ describe('ngb-tooltip', () => {
expect(windowEl.textContent.trim()).toBe('Great tip!');
});

it('should accept placement in array(second value of the array should be applied)', () => {
it('should accept placement in array (second value of the array should be applied)', () => {
const fixture =
createTestComponent(`<div ngbTooltip="Great tip!" [placement]="['left-top','top-right']"></div>`);
createTestComponent(`<div ngbTooltip="Great tip!" [placement]="['left-top','top-left']"></div>`);
const directive = fixture.debugElement.query(By.directive(NgbTooltip));

directive.triggerEventHandler('mouseenter', {});
Expand All @@ -281,7 +281,7 @@ describe('ngb-tooltip', () => {

expect(windowEl).toHaveCssClass('tooltip');
expect(windowEl).toHaveCssClass('bs-tooltip-top');
expect(windowEl).toHaveCssClass('bs-tooltip-top-right');
expect(windowEl).toHaveCssClass('bs-tooltip-top-left');
expect(windowEl.textContent.trim()).toBe('Great tip!');
});

Expand Down
5 changes: 2 additions & 3 deletions src/util/positioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ export function positionElements(
// The translate3d/gpu acceleration render a blurry text on chrome, the next line is commented until a browser fix
// style['will-change'] = 'transform';

const lastPlacement = placementVals[placementVals.length - 1];
let testPlacement: Placement;
let isInViewport = false;
for (testPlacement of placementVals) {
Expand All @@ -232,8 +231,8 @@ export function positionElements(
break;
}

// Remove the baseClasses for further calculation, except for the last one
if (baseClass && testPlacement !== lastPlacement) {
// Remove the baseClasses for further calculation
if (baseClass) {
addedClasses.forEach((classname) => { classList.remove(classname); });
}
}
Expand Down

0 comments on commit 5fdc3fa

Please sign in to comment.