@box/blueprint-web 9.13.1 → 9.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import * as Ariakit from '@ariakit/react';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
|
-
import { forwardRef, useLayoutEffect, useCallback } from 'react';
|
|
4
|
+
import { forwardRef, useRef, useLayoutEffect, useCallback } from 'react';
|
|
5
5
|
import { Card } from '../card/card.js';
|
|
6
6
|
import { composeEventHandlers } from '../utils/composeEventHandlers.js';
|
|
7
7
|
import styles from './card-tooltip-v2.module.js';
|
|
@@ -27,14 +27,16 @@ const CardTooltipV2 = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
27
27
|
hideOnInteractOutside,
|
|
28
28
|
placement = 'bottom',
|
|
29
29
|
elevation = 'dropshadow-3',
|
|
30
|
+
addDelayOnFocus,
|
|
30
31
|
...contentProps
|
|
31
32
|
} = props;
|
|
33
|
+
const SHOW_TIMEOUT = 300;
|
|
32
34
|
const tooltipStore = Ariakit.useTooltipStore({
|
|
33
35
|
open,
|
|
34
36
|
setOpen,
|
|
35
37
|
defaultOpen,
|
|
36
38
|
placement,
|
|
37
|
-
showTimeout:
|
|
39
|
+
showTimeout: SHOW_TIMEOUT,
|
|
38
40
|
hideTimeout: 0,
|
|
39
41
|
skipTimeout
|
|
40
42
|
});
|
|
@@ -42,6 +44,7 @@ const CardTooltipV2 = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
42
44
|
const contentId = Ariakit.useStoreState(tooltipStore, state => state.contentElement?.id);
|
|
43
45
|
const mounted = Ariakit.useStoreState(tooltipStore, 'mounted');
|
|
44
46
|
const isOpen = Ariakit.useStoreState(tooltipStore, 'open');
|
|
47
|
+
const focusTimeout = useRef(0);
|
|
45
48
|
useLayoutEffect(() => {
|
|
46
49
|
if (mounted && !isOpen) {
|
|
47
50
|
// Make sure that tooltip disappears instantly after it is closed.
|
|
@@ -65,6 +68,18 @@ const CardTooltipV2 = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
65
68
|
}
|
|
66
69
|
return true;
|
|
67
70
|
}, [hideOnInteractOutside, tooltipStore]);
|
|
71
|
+
const handleOnFocusVisibleWithDelay = event => {
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
event.currentTarget.setAttribute('data-focus-visible', 'true');
|
|
74
|
+
focusTimeout.current = window.setTimeout(() => {
|
|
75
|
+
tooltipStore?.setAnchorElement(event.currentTarget);
|
|
76
|
+
tooltipStore?.show();
|
|
77
|
+
}, SHOW_TIMEOUT);
|
|
78
|
+
};
|
|
79
|
+
const handleBlur = event => {
|
|
80
|
+
event.currentTarget.removeAttribute('data-focus-visible');
|
|
81
|
+
window.clearTimeout(focusTimeout.current);
|
|
82
|
+
};
|
|
68
83
|
return jsxs(Ariakit.TooltipProvider, {
|
|
69
84
|
store: tooltipStore,
|
|
70
85
|
children: [jsx(Ariakit.TooltipAnchor, {
|
|
@@ -72,7 +87,11 @@ const CardTooltipV2 = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
72
87
|
'aria-describedby': contentId
|
|
73
88
|
}),
|
|
74
89
|
onClick: tooltipStore.hide,
|
|
75
|
-
render: children
|
|
90
|
+
render: children,
|
|
91
|
+
...(addDelayOnFocus && {
|
|
92
|
+
onFocusVisible: handleOnFocusVisibleWithDelay,
|
|
93
|
+
onBlur: handleBlur
|
|
94
|
+
})
|
|
76
95
|
}), jsx(Ariakit.Tooltip, {
|
|
77
96
|
...contentProps,
|
|
78
97
|
...(hideTooltipOnContentClick && {
|
|
@@ -2,6 +2,11 @@ import { type TooltipProps, type TooltipStoreProps } from '@ariakit/react';
|
|
|
2
2
|
import { type ReactElement, type ReactNode } from 'react';
|
|
3
3
|
import { type CardProps } from '../card/types';
|
|
4
4
|
export interface CardTooltipV2Props extends Omit<TooltipProps, 'content' | 'ref'> {
|
|
5
|
+
/**
|
|
6
|
+
* If true, the tooltip will be opened with delay when user focuses on the anchor. Be mindful that are accessibility concerns when using this prop. It should only be used in cases where the content is purely decorative and does not convey important information that needs to be accessible to screen readers or assistive technologies.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
addDelayOnFocus?: boolean;
|
|
5
10
|
/** The anchor for the tooltip. */
|
|
6
11
|
children: ReactElement;
|
|
7
12
|
/** The content of the tooltip. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@box/blueprint-web",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"publishConfig": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"react-stately": "^3.31.1",
|
|
63
63
|
"tsx": "^4.16.5"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "0861d779ab8438a8210aa09902b92b389837462a",
|
|
66
66
|
"module": "lib-esm/index.js",
|
|
67
67
|
"main": "lib-esm/index.js",
|
|
68
68
|
"exports": {
|