Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions projects/coreui-angular/src/lib/popover/popover.directive.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Directive, inject, input, model, TemplateRef } from '@angular/core';
import { booleanAttribute, Directive, inject, input, model, TemplateRef } from '@angular/core';
import { Options } from '@popperjs/core';

import { Triggers } from '../coreui.types';
import { ListenersService, UIDService } from '../services';
import { ElementRefDirective } from '../shared';
import { TooltipDirectiveBase } from '../tooltip/tooltip-directive-base';
import { delayAttribute, TooltipDelay, TooltipDirectiveBase } from '../tooltip/tooltip-directive-base';
import { PopoverComponent } from './popover/popover.component';

@Directive({
Expand All @@ -17,12 +17,31 @@ export class PopoverDirective extends TooltipDirectiveBase {
protected readonly offset = 9;
protected readonly tooltipId = inject(UIDService).getUID('popover');

/**
* Fades the popover in and out.
* @returns boolean
* @default true
* @since 5.7.45
*/
readonly animation = input(true, { alias: 'cPopoverAnimation', transform: booleanAttribute });

/**
* Content of popover
* @returns string | TemplateRef<any> | undefined
*/
readonly content = input<string | TemplateRef<any> | undefined>(undefined, { alias: 'cPopover' });

/**
* Delay in ms: `show` before the popover appears, `hide` after its trigger ends. A number sets both.
* @returns number | { show?: number; hide?: number }
* @default { show: 150, hide: 0 }
* @since 5.7.45
*/
readonly delay = input<number | { show?: number; hide?: number }, TooltipDelay | string | null | undefined>(
{},
{ alias: 'cPopoverDelay', transform: delayAttribute }
);

/**
* Describes the placement of your component after Popper.js has applied all the modifiers that may have flipped or altered the originally provided placement property.
* @returns 'top' | 'bottom' | 'left' | 'right'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { Component, signal } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { PopoverComponent } from './popover.component';

@Component({
template: '<c-popover />',
template: `
<c-popover />
<c-popover [animation]="animation()" [visible]="visible()" />
`,
imports: [PopoverComponent]
})
class TestComponent {}
class TestComponent {
readonly animation = signal(true);
readonly visible = signal(false);
}

describe('PopoverComponent', () => {
let component: PopoverComponent;
let element: HTMLElement;
let boundElement: HTMLElement;
let fixture: ComponentFixture<TestComponent>;

beforeEach(async () => {
const fixture = TestBed.createComponent(TestComponent);
fixture = TestBed.createComponent(TestComponent);
await fixture.whenStable();

const debugElement = fixture.debugElement.query(By.directive(PopoverComponent));
const [debugElement, boundDebugElement] = fixture.debugElement.queryAll(By.directive(PopoverComponent));
component = debugElement.componentInstance;
element = debugElement.nativeElement;
boundElement = boundDebugElement.nativeElement;
});

it('should create', () => {
Expand All @@ -33,6 +42,23 @@ describe('PopoverComponent', () => {
expect(element.classList.contains('bs-popover-auto')).toBe(true);
});

it('should not fade without animation', async () => {
fixture.componentInstance.animation.set(false);
await fixture.whenStable();
expect(boundElement.classList.contains('popover')).toBe(true);
expect(boundElement.classList.contains('fade')).toBe(false);
});

it('should be hidden without animation while not visible', async () => {
expect(boundElement.classList.contains('invisible')).toBe(false);
fixture.componentInstance.animation.set(false);
await fixture.whenStable();
expect(boundElement.classList.contains('invisible')).toBe(true);
fixture.componentInstance.visible.set(true);
await fixture.whenStable();
expect(boundElement.classList.contains('invisible')).toBe(false);
});

it('should not have the tooltip css classes', () => {
expect(element.classList.contains('tooltip')).toBe(false);
expect(element.classList.contains('bs-tooltip-auto')).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import { TooltipComponentBase } from '../../tooltip/tooltip/tooltip-component-ba
export class PopoverComponent extends TooltipComponentBase {
protected readonly prefix = 'popover';

/**
* Fades the popover in and out.
* @returns boolean
* @default true
* @since 5.7.45
*/
readonly animation = input(true, { transform: booleanAttribute });

/**
* Content of popover
* @returns string | TemplateRef<any>
Expand Down
Loading
Loading