-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tooltip): keep tooltip content visible as user hovers
Previously, the tooltip content was hidden as soon as the user moused out of the trigger. Now, the tooltip content will stay visible if the user mouses from the trigger into the content. To support this, the tooltip content has an expanded hover target provided by the `::after` pseudo element. VPAT-617
- Loading branch information
1 parent
c3f61eb
commit 9938c1e
Showing
9 changed files
with
156 additions
and
10 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
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
56 changes: 56 additions & 0 deletions
56
projects/angular/src/popover/tooltip/providers/tooltip-mouse.service.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,56 @@ | ||
/* | ||
* Copyright (c) 2016-2022 VMware, Inc. All Rights Reserved. | ||
* This software is released under MIT license. | ||
* The full license information can be found in LICENSE in the root directory of this project. | ||
*/ | ||
|
||
import { fakeAsync, tick } from '@angular/core/testing'; | ||
|
||
import { ClrPopoverToggleService } from '../../../utils/popover/providers/popover-toggle.service'; | ||
import { TooltipMouseService } from './tooltip-mouse.service'; | ||
|
||
export default function (): void { | ||
describe('Tooltip Mouse Service', () => { | ||
let toggleService: ClrPopoverToggleService; | ||
let mouseService: TooltipMouseService; | ||
|
||
beforeEach(() => { | ||
toggleService = new ClrPopoverToggleService(); | ||
mouseService = new TooltipMouseService(toggleService); | ||
}); | ||
|
||
it('should show the tooltip when the mouse enters the trigger', () => { | ||
mouseService.onMouseEnterTrigger(); | ||
|
||
expect(toggleService.open).toBe(true); | ||
}); | ||
|
||
it('should hide the tooltip if the mouse leaves the trigger and does not enter the content', fakeAsync(() => { | ||
toggleService.open = true; | ||
|
||
mouseService.onMouseLeaveTrigger(); | ||
tick(); | ||
|
||
expect(toggleService.open).toBe(false); | ||
})); | ||
|
||
it('should hide the tooltip if the mouse leaves the content and does not enter the trigger', fakeAsync(() => { | ||
toggleService.open = true; | ||
|
||
mouseService.onMouseLeaveContent(); | ||
tick(); | ||
|
||
expect(toggleService.open).toBe(false); | ||
})); | ||
|
||
it('should not hide the tooltip as the mouse moves from the trigger to the content', fakeAsync(() => { | ||
toggleService.open = true; | ||
|
||
mouseService.onMouseLeaveTrigger(); | ||
mouseService.onMouseEnterContent(); | ||
tick(); | ||
|
||
expect(toggleService.open).toBe(true); | ||
})); | ||
}); | ||
} |
46 changes: 46 additions & 0 deletions
46
projects/angular/src/popover/tooltip/providers/tooltip-mouse.service.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,46 @@ | ||
/* | ||
* Copyright (c) 2016-2022 VMware, Inc. All Rights Reserved. | ||
* This software is released under MIT license. | ||
* The full license information can be found in LICENSE in the root directory of this project. | ||
*/ | ||
|
||
import { Injectable } from '@angular/core'; | ||
|
||
import { ClrPopoverToggleService } from '../../../utils/popover/providers/popover-toggle.service'; | ||
|
||
@Injectable() | ||
export class TooltipMouseService { | ||
private mouseOverTrigger: boolean; | ||
private mouseOverContent: boolean; | ||
|
||
constructor(private readonly toggleService: ClrPopoverToggleService) {} | ||
|
||
onMouseEnterTrigger() { | ||
this.mouseOverTrigger = true; | ||
this.toggleService.open = true; | ||
} | ||
|
||
onMouseLeaveTrigger() { | ||
this.mouseOverTrigger = false; | ||
this.hideIfMouseOut(); | ||
} | ||
|
||
onMouseEnterContent() { | ||
this.mouseOverContent = true; | ||
} | ||
|
||
onMouseLeaveContent() { | ||
this.mouseOverContent = false; | ||
this.hideIfMouseOut(); | ||
} | ||
|
||
private hideIfMouseOut() { | ||
// A zero timeout is used so that the code has a chance to update | ||
// the `mouseOverContent` property after the user moves the mouse from the trigger to the content. | ||
setTimeout(() => { | ||
if (!this.mouseOverTrigger && !this.mouseOverContent) { | ||
this.toggleService.open = false; | ||
} | ||
}, 0); | ||
} | ||
} |
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