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

fix: #6680, Tooltip: Escape key not dismissing tooltip (WCAG 2.1 1.4.13) #6687

Merged
merged 5 commits into from
May 27, 2024
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
8 changes: 8 additions & 0 deletions components/doc/common/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -51144,6 +51144,14 @@
"default": "",
"description": "Content to be displayed in tooltip."
},
{
"name": "closeOnEscape",
"optional": true,
"readonly": false,
"type": "boolean",
"default": "false",
"description": "Specifies if pressing escape key should hide the tooltip."
},
{
"name": "disabled",
"optional": true,
Expand Down
3 changes: 2 additions & 1 deletion components/lib/hooks/useGlobalOnEscapeKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const ESC_KEY_HANDLING_PRIORITIES = {
PASSWORD: 700,
CASCADE_SELECT: 800,
SPLIT_BUTTON: 900,
SPEED_DIAL: 1000
SPEED_DIAL: 1000,
TOOLTIP: 1200
};

/**
Expand Down
9 changes: 8 additions & 1 deletion components/lib/tooltip/Tooltip.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import PrimeReact, { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { useMergeProps, useMountEffect, useOverlayScrollListener, useResizeListener, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks';
import { useMergeProps, useMountEffect, useOverlayScrollListener, useResizeListener, useUnmountEffect, useUpdateEffect, useGlobalOnEscapeKey, ESC_KEY_HANDLING_PRIORITIES } from '../hooks/Hooks';
import { Portal } from '../portal/Portal';
import { DomHandler, ObjectUtils, ZIndexUtils, classNames } from '../utils/Utils';
import { TooltipBase } from './TooltipBase';
Expand Down Expand Up @@ -32,6 +32,13 @@ export const Tooltip = React.memo(
const { ptm, cx, sx, isUnstyled } = TooltipBase.setMetaData(metaData);

useHandleStyle(TooltipBase.css.styles, isUnstyled, { name: 'tooltip' });
useGlobalOnEscapeKey({
callback: () => {
hide();
},
when: props.closeOnEscape,
priority: [ESC_KEY_HANDLING_PRIORITIES.TOOLTIP, 0]
});
const elementRef = React.useRef(null);
const textRef = React.useRef(null);
const currentTargetRef = React.useRef(null);
Expand Down
1 change: 1 addition & 0 deletions components/lib/tooltip/TooltipBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const TooltipBase = ComponentBase.extend({
autoZIndex: true,
baseZIndex: 0,
className: null,
closeOnEscape: false,
content: null,
disabled: false,
event: null,
Expand Down
5 changes: 5 additions & 0 deletions components/lib/tooltip/tooltipoptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export interface TooltipOptions {
* Style class of the tooltip.
*/
className?: string | undefined;
/**
* Specifies if pressing escape key should hide the tooltip.
* @defaultValue false
*/
closeOnEscape?: boolean | undefined;
/**
* When present, it specifies that the tooltip should be hidden.
* @defaultValue false
Expand Down
Loading