-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(tooltip): keep tooltip content visible as user hovers #447
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3c26a1e
chore(tooltip): execute `TooltipIdService` tests
kevinbuhmann 83990d0
chore(tooltip): add blank line between properties and constructor
kevinbuhmann e1389dd
chore(tooltip): move component lifecycle method before event handlers
kevinbuhmann 7d77a00
fix(tooltip): keep tooltip content visible as user hovers
kevinbuhmann File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great solution, thanks!