Skip to content
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

STCOM-1391 Tooltip - check for hover on tooltip content before closing the tooltip. #2411

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Clear filter value after an action chosen from `MultiSelection` menu. Refs STCOM-1385.
* ExportCSV - fix usage within `<Modal>`s by rendering the download link to the `div#OverlayContainer`. Refs STCOM-1387.
* `<MenuSection>` should default its heading/label tag to `H3` instead of `H1`. Refs STCOM-1392.
* `<Tooltip>` should allow for tooltip content to be hovered without closing the tooltip. Refs STCOM-1391.

## [12.2.0](https://github.com/folio-org/stripes-components/tree/v12.2.0) (2024-10-11)
[Full Changelog](https://github.com/folio-org/stripes-components/compare/v12.1.0...v12.2.0)
Expand Down
1 change: 1 addition & 0 deletions lib/Tooltip/Tooltip.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
animation-timing-function: ease-in;
animation-duration: 0.1s;
font-size: var(--font-size-small);
pointer-events: all;
}

.text {
Expand Down
25 changes: 19 additions & 6 deletions lib/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default class Tooltip extends Component {
constructor(props) {
super(props);
this.triggerRef = props.triggerRef || createRef(null);
this.overlayRef = createRef(null);
}

state = {
Expand Down Expand Up @@ -99,10 +100,22 @@ export default class Tooltip extends Component {
const disable = hideOnTouch && isTouch;
clearTimeout(this.timeout);

if (bool !== open && !disable) {
this.setState({
open: bool,
});
// Accessibuilty - When hiding the tooltip, ensure that the mouse is not hovered over the tooltip
JohnC-80 marked this conversation as resolved.
Show resolved Hide resolved
// - for mouse readers (WCAG 2.1 - 1.4.13 )
if (!bool) {
if (!this.overlayRef?.current?.matches(':hover') &&
!this.triggerRef?.current?.matches(':hover')
) {
this.setState({
open: bool,
});
}
} else {
if (bool !== open && !disable) {
this.setState({
open: bool,
});
}
}
}

Expand All @@ -114,7 +127,7 @@ export default class Tooltip extends Component {

hide = () => {
clearTimeout(this.timeout);
this.toggle(false);
this.timeout = setTimeout(() => this.toggle(false), 150);
}

/**
Expand Down Expand Up @@ -213,7 +226,7 @@ export default class Tooltip extends Component {
placement={placement}
modifiers={modifiers}
>
<div className={css.tooltip} aria-hidden data-test-tooltip>
<div className={css.tooltip} ref={this.overlayRef} onMouseLeave={()=>this.hide()} aria-hidden data-test-tooltip>
{text && (
<div className={css.text} data-test-tooltip-text>
{text}
Expand Down
Loading