@react-aria/tooltip 3.7.3 → 3.7.5
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.
- package/dist/types.d.ts +2 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/useTooltip.main.js +1 -1
- package/dist/useTooltip.mjs +2 -2
- package/dist/useTooltip.module.js +1 -1
- package/dist/useTooltipTrigger.main.js +7 -7
- package/dist/useTooltipTrigger.main.js.map +1 -1
- package/dist/useTooltipTrigger.mjs +8 -8
- package/dist/useTooltipTrigger.module.js +7 -7
- package/dist/useTooltipTrigger.module.js.map +1 -1
- package/package.json +9 -9
- package/src/useTooltipTrigger.ts +3 -3
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AriaTooltipProps, TooltipTriggerProps } from "@react-types/tooltip";
|
|
2
|
-
import { DOMAttributes, FocusableElement } from "@react-types/shared";
|
|
2
|
+
import { DOMAttributes, FocusableElement, RefObject } from "@react-types/shared";
|
|
3
3
|
import { TooltipTriggerState } from "@react-stately/tooltip";
|
|
4
|
-
import { RefObject } from "react";
|
|
5
4
|
export interface TooltipAria {
|
|
6
5
|
/**
|
|
7
6
|
* Props for the tooltip element.
|
|
@@ -26,7 +25,7 @@ export interface TooltipTriggerAria {
|
|
|
26
25
|
* Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button
|
|
27
26
|
* that shows a description when focused or hovered.
|
|
28
27
|
*/
|
|
29
|
-
export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement>): TooltipTriggerAria;
|
|
28
|
+
export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement | null>): TooltipTriggerAria;
|
|
30
29
|
export type { AriaTooltipProps, TooltipTriggerProps } from '@react-types/tooltip';
|
|
31
30
|
|
|
32
31
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;AAkBA;IACE;;OAEG;IACH,YAAY,EAAE,aAAa,CAAA;CAC5B;AAED;;GAEG;AACH,2BAA2B,KAAK,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,mBAAmB,GAAG,WAAW,CAa5F;ACrBD;IACE;;OAEG;IACH,YAAY,EAAE,aAAa,CAAC;IAE5B;;OAEG;IACH,YAAY,EAAE,aAAa,CAAA;CAC5B;AAED;;;GAGG;AACH,kCAAkC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,mBAAmB,EAAE,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAI,kBAAkB,CAiHtJ;ACxID,YAAY,EAAC,gBAAgB,EAAE,mBAAmB,EAAC,MAAM,sBAAsB,CAAC","sources":["packages/@react-aria/tooltip/src/packages/@react-aria/tooltip/src/useTooltip.ts","packages/@react-aria/tooltip/src/packages/@react-aria/tooltip/src/useTooltipTrigger.ts","packages/@react-aria/tooltip/src/packages/@react-aria/tooltip/src/index.ts","packages/@react-aria/tooltip/src/index.ts"],"sourcesContent":[null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useTooltip} from './useTooltip';\nexport {useTooltipTrigger} from './useTooltipTrigger';\nexport type {AriaTooltipProps, TooltipTriggerProps} from '@react-types/tooltip';\nexport type {TooltipAria} from './useTooltip';\nexport type {TooltipTriggerAria} from './useTooltipTrigger';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/dist/useTooltip.main.js
CHANGED
package/dist/useTooltip.mjs
CHANGED
|
@@ -23,11 +23,11 @@ function $326e436e94273fe1$export$1c4b08e0eca38426(props, state) {
|
|
|
23
23
|
});
|
|
24
24
|
return {
|
|
25
25
|
tooltipProps: (0, $kwmr2$mergeProps)(domProps, hoverProps, {
|
|
26
|
-
role:
|
|
26
|
+
role: 'tooltip'
|
|
27
27
|
})
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
export {$326e436e94273fe1$export$1c4b08e0eca38426 as useTooltip};
|
|
33
|
-
//# sourceMappingURL=useTooltip.
|
|
33
|
+
//# sourceMappingURL=useTooltip.module.js.map
|
|
@@ -39,16 +39,16 @@ function $f017bbc46d58d42a$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
39
39
|
if (ref && ref.current) // Escape after clicking something can give it keyboard focus
|
|
40
40
|
// dismiss tooltip on esc key press
|
|
41
41
|
{
|
|
42
|
-
if (e.key ===
|
|
42
|
+
if (e.key === 'Escape') {
|
|
43
43
|
e.stopPropagation();
|
|
44
44
|
state.close(true);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
if (state.isOpen) {
|
|
49
|
-
document.addEventListener(
|
|
49
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
50
50
|
return ()=>{
|
|
51
|
-
document.removeEventListener(
|
|
51
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
}, [
|
|
@@ -56,17 +56,17 @@ function $f017bbc46d58d42a$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
56
56
|
state
|
|
57
57
|
]);
|
|
58
58
|
let onHoverStart = ()=>{
|
|
59
|
-
if (trigger ===
|
|
59
|
+
if (trigger === 'focus') return;
|
|
60
60
|
// In chrome, if you hover a trigger, then another element obscures it, due to keyboard
|
|
61
61
|
// interactions for example, hover will end. When hover is restored after that element disappears,
|
|
62
62
|
// focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
|
|
63
63
|
// is the result of moving the mouse.
|
|
64
|
-
if ((0, $jCY2B$reactariainteractions.getInteractionModality)() ===
|
|
64
|
+
if ((0, $jCY2B$reactariainteractions.getInteractionModality)() === 'pointer') isHovered.current = true;
|
|
65
65
|
else isHovered.current = false;
|
|
66
66
|
handleShow();
|
|
67
67
|
};
|
|
68
68
|
let onHoverEnd = ()=>{
|
|
69
|
-
if (trigger ===
|
|
69
|
+
if (trigger === 'focus') return;
|
|
70
70
|
// no matter how the trigger is left, we should close the tooltip
|
|
71
71
|
isFocused.current = false;
|
|
72
72
|
isHovered.current = false;
|
|
@@ -102,7 +102,7 @@ function $f017bbc46d58d42a$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
102
102
|
}, ref);
|
|
103
103
|
return {
|
|
104
104
|
triggerProps: {
|
|
105
|
-
|
|
105
|
+
'aria-describedby': state.isOpen ? tooltipId : undefined,
|
|
106
106
|
...(0, $jCY2B$reactariautils.mergeProps)(focusableProps, hoverProps, {
|
|
107
107
|
onPointerDown: onPressStart,
|
|
108
108
|
onKeyDown: onPressStart
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA0BM,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA0BM,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAuC;IAC/H,IAAI,cACF,UAAU,WACV,OAAO,EACR,GAAG;IAEJ,IAAI,YAAY,CAAA,GAAA,2BAAI;IAEpB,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE;IACvB,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE;IAEvB,IAAI,aAAa;QACf,IAAI,UAAU,OAAO,IAAI,UAAU,OAAO,EACxC,MAAM,IAAI,CAAC,UAAU,OAAO;IAEhC;IAEA,IAAI,aAAa,CAAC;QACh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BACA;IACF,GAAG;IAEH,OAAO;QACL,cAAc;YACZ,oBAAoB,MAAM,MAAM,GAAG,YAAY;YAC/C,GAAG,CAAA,GAAA,gCAAS,EAAE,gBAAgB,YAAY;gBACxC,eAAe;gBACf,WAAW;YACb,EAAE;QACJ;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF","sources":["packages/@react-aria/tooltip/src/useTooltipTrigger.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {getInteractionModality, isFocusVisible, useHover} from '@react-aria/interactions';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useEffect, useRef} from 'react';\nimport {useFocusable} from '@react-aria/focus';\n\nexport interface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: DOMAttributes,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button\n * that shows a description when focused or hovered.\n */\nexport function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement | null>) : TooltipTriggerAria {\n let {\n isDisabled,\n trigger\n } = props;\n\n let tooltipId = useId();\n\n let isHovered = useRef(false);\n let isFocused = useRef(false);\n\n let handleShow = () => {\n if (isHovered.current || isFocused.current) {\n state.open(isFocused.current);\n }\n };\n\n let handleHide = (immediate?: boolean) => {\n if (!isHovered.current && !isFocused.current) {\n state.close(immediate);\n }\n };\n\n useEffect(() => {\n let onKeyDown = (e) => {\n if (ref && ref.current) {\n // Escape after clicking something can give it keyboard focus\n // dismiss tooltip on esc key press\n if (e.key === 'Escape') {\n e.stopPropagation();\n state.close(true);\n }\n }\n };\n if (state.isOpen) {\n document.addEventListener('keydown', onKeyDown, true);\n return () => {\n document.removeEventListener('keydown', onKeyDown, true);\n };\n }\n }, [ref, state]);\n\n let onHoverStart = () => {\n if (trigger === 'focus') {\n return;\n }\n // In chrome, if you hover a trigger, then another element obscures it, due to keyboard\n // interactions for example, hover will end. When hover is restored after that element disappears,\n // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover\n // is the result of moving the mouse.\n if (getInteractionModality() === 'pointer') {\n isHovered.current = true;\n } else {\n isHovered.current = false;\n }\n handleShow();\n };\n\n let onHoverEnd = () => {\n if (trigger === 'focus') {\n return;\n }\n // no matter how the trigger is left, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide();\n };\n\n let onPressStart = () => {\n // no matter how the trigger is pressed, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let onFocus = () => {\n let isVisible = isFocusVisible();\n if (isVisible) {\n isFocused.current = true;\n handleShow();\n }\n };\n\n let onBlur = () => {\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart,\n onHoverEnd\n });\n\n let {focusableProps} = useFocusable({\n isDisabled,\n onFocus,\n onBlur\n }, ref);\n\n return {\n triggerProps: {\n 'aria-describedby': state.isOpen ? tooltipId : undefined,\n ...mergeProps(focusableProps, hoverProps, {\n onPointerDown: onPressStart,\n onKeyDown: onPressStart\n })\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":[],"version":3,"file":"useTooltipTrigger.main.js.map"}
|
|
@@ -33,16 +33,16 @@ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
33
33
|
if (ref && ref.current) // Escape after clicking something can give it keyboard focus
|
|
34
34
|
// dismiss tooltip on esc key press
|
|
35
35
|
{
|
|
36
|
-
if (e.key ===
|
|
36
|
+
if (e.key === 'Escape') {
|
|
37
37
|
e.stopPropagation();
|
|
38
38
|
state.close(true);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
if (state.isOpen) {
|
|
43
|
-
document.addEventListener(
|
|
43
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
44
44
|
return ()=>{
|
|
45
|
-
document.removeEventListener(
|
|
45
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
}, [
|
|
@@ -50,17 +50,17 @@ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
50
50
|
state
|
|
51
51
|
]);
|
|
52
52
|
let onHoverStart = ()=>{
|
|
53
|
-
if (trigger ===
|
|
53
|
+
if (trigger === 'focus') return;
|
|
54
54
|
// In chrome, if you hover a trigger, then another element obscures it, due to keyboard
|
|
55
55
|
// interactions for example, hover will end. When hover is restored after that element disappears,
|
|
56
56
|
// focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
|
|
57
57
|
// is the result of moving the mouse.
|
|
58
|
-
if ((0, $6VwSn$getInteractionModality)() ===
|
|
58
|
+
if ((0, $6VwSn$getInteractionModality)() === 'pointer') isHovered.current = true;
|
|
59
59
|
else isHovered.current = false;
|
|
60
60
|
handleShow();
|
|
61
61
|
};
|
|
62
62
|
let onHoverEnd = ()=>{
|
|
63
|
-
if (trigger ===
|
|
63
|
+
if (trigger === 'focus') return;
|
|
64
64
|
// no matter how the trigger is left, we should close the tooltip
|
|
65
65
|
isFocused.current = false;
|
|
66
66
|
isHovered.current = false;
|
|
@@ -96,7 +96,7 @@ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
96
96
|
}, ref);
|
|
97
97
|
return {
|
|
98
98
|
triggerProps: {
|
|
99
|
-
|
|
99
|
+
'aria-describedby': state.isOpen ? tooltipId : undefined,
|
|
100
100
|
...(0, $6VwSn$mergeProps)(focusableProps, hoverProps, {
|
|
101
101
|
onPointerDown: onPressStart,
|
|
102
102
|
onKeyDown: onPressStart
|
|
@@ -110,4 +110,4 @@ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
110
110
|
|
|
111
111
|
|
|
112
112
|
export {$4e1b34546679e357$export$a6da6c504e4bba8b as useTooltipTrigger};
|
|
113
|
-
//# sourceMappingURL=useTooltipTrigger.
|
|
113
|
+
//# sourceMappingURL=useTooltipTrigger.module.js.map
|
|
@@ -33,16 +33,16 @@ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
33
33
|
if (ref && ref.current) // Escape after clicking something can give it keyboard focus
|
|
34
34
|
// dismiss tooltip on esc key press
|
|
35
35
|
{
|
|
36
|
-
if (e.key ===
|
|
36
|
+
if (e.key === 'Escape') {
|
|
37
37
|
e.stopPropagation();
|
|
38
38
|
state.close(true);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
if (state.isOpen) {
|
|
43
|
-
document.addEventListener(
|
|
43
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
44
44
|
return ()=>{
|
|
45
|
-
document.removeEventListener(
|
|
45
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
}, [
|
|
@@ -50,17 +50,17 @@ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
50
50
|
state
|
|
51
51
|
]);
|
|
52
52
|
let onHoverStart = ()=>{
|
|
53
|
-
if (trigger ===
|
|
53
|
+
if (trigger === 'focus') return;
|
|
54
54
|
// In chrome, if you hover a trigger, then another element obscures it, due to keyboard
|
|
55
55
|
// interactions for example, hover will end. When hover is restored after that element disappears,
|
|
56
56
|
// focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
|
|
57
57
|
// is the result of moving the mouse.
|
|
58
|
-
if ((0, $6VwSn$getInteractionModality)() ===
|
|
58
|
+
if ((0, $6VwSn$getInteractionModality)() === 'pointer') isHovered.current = true;
|
|
59
59
|
else isHovered.current = false;
|
|
60
60
|
handleShow();
|
|
61
61
|
};
|
|
62
62
|
let onHoverEnd = ()=>{
|
|
63
|
-
if (trigger ===
|
|
63
|
+
if (trigger === 'focus') return;
|
|
64
64
|
// no matter how the trigger is left, we should close the tooltip
|
|
65
65
|
isFocused.current = false;
|
|
66
66
|
isHovered.current = false;
|
|
@@ -96,7 +96,7 @@ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
96
96
|
}, ref);
|
|
97
97
|
return {
|
|
98
98
|
triggerProps: {
|
|
99
|
-
|
|
99
|
+
'aria-describedby': state.isOpen ? tooltipId : undefined,
|
|
100
100
|
...(0, $6VwSn$mergeProps)(focusableProps, hoverProps, {
|
|
101
101
|
onPointerDown: onPressStart,
|
|
102
102
|
onKeyDown: onPressStart
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA0BM,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA0BM,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAuC;IAC/H,IAAI,cACF,UAAU,WACV,OAAO,EACR,GAAG;IAEJ,IAAI,YAAY,CAAA,GAAA,YAAI;IAEpB,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE;IACvB,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE;IAEvB,IAAI,aAAa;QACf,IAAI,UAAU,OAAO,IAAI,UAAU,OAAO,EACxC,MAAM,IAAI,CAAC,UAAU,OAAO;IAEhC;IAEA,IAAI,aAAa,CAAC;QAChB,IAAI,CAAC,UAAU,OAAO,IAAI,CAAC,UAAU,OAAO,E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MAAM,MAAM,GAAG,YAAY;YAC/C,GAAG,CAAA,GAAA,iBAAS,EAAE,gBAAgB,YAAY;gBACxC,eAAe;gBACf,WAAW;YACb,EAAE;QACJ;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF","sources":["packages/@react-aria/tooltip/src/useTooltipTrigger.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {getInteractionModality, isFocusVisible, useHover} from '@react-aria/interactions';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useEffect, useRef} from 'react';\nimport {useFocusable} from '@react-aria/focus';\n\nexport interface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: DOMAttributes,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button\n * that shows a description when focused or hovered.\n */\nexport function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement | null>) : TooltipTriggerAria {\n let {\n isDisabled,\n trigger\n } = props;\n\n let tooltipId = useId();\n\n let isHovered = useRef(false);\n let isFocused = useRef(false);\n\n let handleShow = () => {\n if (isHovered.current || isFocused.current) {\n state.open(isFocused.current);\n }\n };\n\n let handleHide = (immediate?: boolean) => {\n if (!isHovered.current && !isFocused.current) {\n state.close(immediate);\n }\n };\n\n useEffect(() => {\n let onKeyDown = (e) => {\n if (ref && ref.current) {\n // Escape after clicking something can give it keyboard focus\n // dismiss tooltip on esc key press\n if (e.key === 'Escape') {\n e.stopPropagation();\n state.close(true);\n }\n }\n };\n if (state.isOpen) {\n document.addEventListener('keydown', onKeyDown, true);\n return () => {\n document.removeEventListener('keydown', onKeyDown, true);\n };\n }\n }, [ref, state]);\n\n let onHoverStart = () => {\n if (trigger === 'focus') {\n return;\n }\n // In chrome, if you hover a trigger, then another element obscures it, due to keyboard\n // interactions for example, hover will end. When hover is restored after that element disappears,\n // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover\n // is the result of moving the mouse.\n if (getInteractionModality() === 'pointer') {\n isHovered.current = true;\n } else {\n isHovered.current = false;\n }\n handleShow();\n };\n\n let onHoverEnd = () => {\n if (trigger === 'focus') {\n return;\n }\n // no matter how the trigger is left, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide();\n };\n\n let onPressStart = () => {\n // no matter how the trigger is pressed, we should close the tooltip\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let onFocus = () => {\n let isVisible = isFocusVisible();\n if (isVisible) {\n isFocused.current = true;\n handleShow();\n }\n };\n\n let onBlur = () => {\n isFocused.current = false;\n isHovered.current = false;\n handleHide(true);\n };\n\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart,\n onHoverEnd\n });\n\n let {focusableProps} = useFocusable({\n isDisabled,\n onFocus,\n onBlur\n }, ref);\n\n return {\n triggerProps: {\n 'aria-describedby': state.isOpen ? tooltipId : undefined,\n ...mergeProps(focusableProps, hoverProps, {\n onPointerDown: onPressStart,\n onKeyDown: onPressStart\n })\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":[],"version":3,"file":"useTooltipTrigger.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/tooltip",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.5",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,19 +22,19 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/focus": "^3.
|
|
26
|
-
"@react-aria/interactions": "^3.
|
|
27
|
-
"@react-aria/utils": "^3.
|
|
28
|
-
"@react-stately/tooltip": "^3.4.
|
|
29
|
-
"@react-types/shared": "^3.
|
|
30
|
-
"@react-types/tooltip": "^3.4.
|
|
25
|
+
"@react-aria/focus": "^3.18.0",
|
|
26
|
+
"@react-aria/interactions": "^3.22.0",
|
|
27
|
+
"@react-aria/utils": "^3.25.0",
|
|
28
|
+
"@react-stately/tooltip": "^3.4.10",
|
|
29
|
+
"@react-types/shared": "^3.24.0",
|
|
30
|
+
"@react-types/tooltip": "^3.4.10",
|
|
31
31
|
"@swc/helpers": "^0.5.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
34
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "86d80e3216bc32e75108831cf3a5a720bc849206"
|
|
40
40
|
}
|
package/src/useTooltipTrigger.ts
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {DOMAttributes, FocusableElement} from '@react-types/shared';
|
|
13
|
+
import {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';
|
|
14
14
|
import {getInteractionModality, isFocusVisible, useHover} from '@react-aria/interactions';
|
|
15
15
|
import {mergeProps, useId} from '@react-aria/utils';
|
|
16
|
-
import {RefObject, useEffect, useRef} from 'react';
|
|
17
16
|
import {TooltipTriggerProps} from '@react-types/tooltip';
|
|
18
17
|
import {TooltipTriggerState} from '@react-stately/tooltip';
|
|
18
|
+
import {useEffect, useRef} from 'react';
|
|
19
19
|
import {useFocusable} from '@react-aria/focus';
|
|
20
20
|
|
|
21
21
|
export interface TooltipTriggerAria {
|
|
@@ -34,7 +34,7 @@ export interface TooltipTriggerAria {
|
|
|
34
34
|
* Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button
|
|
35
35
|
* that shows a description when focused or hovered.
|
|
36
36
|
*/
|
|
37
|
-
export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement>) : TooltipTriggerAria {
|
|
37
|
+
export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement | null>) : TooltipTriggerAria {
|
|
38
38
|
let {
|
|
39
39
|
isDisabled,
|
|
40
40
|
trigger
|