From f565162c0839841e578fa5c1111bac39432c66e9 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Sat, 18 Apr 2020 20:52:03 +0100 Subject: [PATCH] fix(tooltip): hide tooltip when dragging starts --- .../common/calendar-tooltip.directive.ts | 4 ++ .../test/calendar-week-view.component.spec.ts | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/projects/angular-calendar/src/modules/common/calendar-tooltip.directive.ts b/projects/angular-calendar/src/modules/common/calendar-tooltip.directive.ts index 0ed2ae345..346e283c0 100644 --- a/projects/angular-calendar/src/modules/common/calendar-tooltip.directive.ts +++ b/projects/angular-calendar/src/modules/common/calendar-tooltip.directive.ts @@ -99,6 +99,10 @@ export class CalendarTooltipDirective implements OnDestroy, OnChanges { this.tooltipRef.instance.customTemplate = this.customTemplate; this.tooltipRef.instance.event = this.event; this.tooltipRef.changeDetectorRef.markForCheck(); + + if (!this.contents) { + this.hide(); + } } } diff --git a/projects/angular-calendar/test/calendar-week-view.component.spec.ts b/projects/angular-calendar/test/calendar-week-view.component.spec.ts index 36c57b96f..e205f3c91 100644 --- a/projects/angular-calendar/test/calendar-week-view.component.spec.ts +++ b/projects/angular-calendar/test/calendar-week-view.component.spec.ts @@ -380,6 +380,51 @@ describe('calendarWeekView component', () => { fixture.destroy(); })); + it('should hide the tooltip when dragging', fakeAsync(() => { + const fixture: ComponentFixture = TestBed.createComponent( + CalendarWeekViewComponent + ); + eventTitle.weekTooltip = (e: CalendarEvent) => { + return `title: ${e.title}`; + }; + fixture.componentInstance.viewDate = new Date('2016-06-01'); + fixture.componentInstance.events = [ + { + start: new Date('2016-05-30'), + end: new Date('2016-06-02'), + title: 'foo bar', + color: { + primary: 'blue', + secondary: '', + }, + draggable: true, + }, + ]; + fixture.componentInstance.ngOnChanges({ viewDate: {}, events: {} }); + fixture.detectChanges(); + const event: HTMLElement = fixture.nativeElement.querySelector( + '.cal-event' + ); + triggerDomEvent('mouseenter', event); + fixture.detectChanges(); + flush(); + expect(document.body.querySelector('.cal-tooltip')).to.be.ok; + const eventPosition = event.getBoundingClientRect(); + triggerDomEvent('mousedown', event, { + clientX: eventPosition.left, + clientY: eventPosition.top, + button: 0, + }); + fixture.detectChanges(); + triggerDomEvent('mousemove', event, { + clientX: eventPosition.left, + clientY: eventPosition.top + 100, + }); + fixture.detectChanges(); + expect(document.body.querySelector('.cal-tooltip')).not.to.be.ok; + fixture.destroy(); + })); + it('should allow the start of the week to be changed', () => { const fixture: ComponentFixture = TestBed.createComponent( CalendarWeekViewComponent