@react-aria/tooltip 3.0.0-alpha.0 → 3.0.0-nightly-4980928d3-240906

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.
@@ -0,0 +1 @@
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;QAChB,IAAI,CAAC,UAAU,OAAO,IAAI,CAAC,UAAU,OAAO,EAC1C,MAAM,KAAK,CAAC;IAEhB;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,YAAY,CAAC;YACf,IAAI,OAAO,IAAI,OAAO,EACpB,6DAA6D;YAC7D,mCAAmC;YACnC;gBAAA,IAAI,EAAE,GAAG,KAAK,UAAU;oBACtB,EAAE,eAAe;oBACjB,MAAM,KAAK,CAAC;gBACd;YAAA;QAEJ;QACA,IAAI,MAAM,MAAM,EAAE;YAChB,SAAS,gBAAgB,CAAC,WAAW,WAAW;YAChD,OAAO;gBACL,SAAS,mBAAmB,CAAC,WAAW,WAAW;YACrD;QACF;IACF,GAAG;QAAC;QAAK;KAAM;IAEf,IAAI,eAAe;QACjB,IAAI,YAAY,SACd;QAEF,uFAAuF;QACvF,kGAAkG;QAClG,uGAAuG;QACvG,qCAAqC;QACrC,IAAI,CAAA,GAAA,mDAAqB,QAAQ,WAC/B,UAAU,OAAO,GAAG;aAEpB,UAAU,OAAO,GAAG;QAEtB;IACF;IAEA,IAAI,aAAa;QACf,IAAI,YAAY,SACd;QAEF,iEAAiE;QACjE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB;IACF;IAEA,IAAI,eAAe;QACjB,oEAAoE;QACpE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,UAAU;QACZ,IAAI,YAAY,CAAA,GAAA,2CAAa;QAC7B,IAAI,WAAW;YACb,UAAU,OAAO,GAAG;YACpB;QACF;IACF;IAEA,IAAI,SAAS;QACX,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;oBAC1B;sBACA;oBACA;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE;oBAClC;iBACA;gBACA;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"}
@@ -0,0 +1,113 @@
1
+ import {getInteractionModality as $6VwSn$getInteractionModality, isFocusVisible as $6VwSn$isFocusVisible, useHover as $6VwSn$useHover} from "@react-aria/interactions";
2
+ import {useId as $6VwSn$useId, mergeProps as $6VwSn$mergeProps} from "@react-aria/utils";
3
+ import {useRef as $6VwSn$useRef, useEffect as $6VwSn$useEffect} from "react";
4
+ import {useFocusable as $6VwSn$useFocusable} from "@react-aria/focus";
5
+
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
21
+ let { isDisabled: isDisabled, trigger: trigger } = props;
22
+ let tooltipId = (0, $6VwSn$useId)();
23
+ let isHovered = (0, $6VwSn$useRef)(false);
24
+ let isFocused = (0, $6VwSn$useRef)(false);
25
+ let handleShow = ()=>{
26
+ if (isHovered.current || isFocused.current) state.open(isFocused.current);
27
+ };
28
+ let handleHide = (immediate)=>{
29
+ if (!isHovered.current && !isFocused.current) state.close(immediate);
30
+ };
31
+ (0, $6VwSn$useEffect)(()=>{
32
+ let onKeyDown = (e)=>{
33
+ if (ref && ref.current) // Escape after clicking something can give it keyboard focus
34
+ // dismiss tooltip on esc key press
35
+ {
36
+ if (e.key === 'Escape') {
37
+ e.stopPropagation();
38
+ state.close(true);
39
+ }
40
+ }
41
+ };
42
+ if (state.isOpen) {
43
+ document.addEventListener('keydown', onKeyDown, true);
44
+ return ()=>{
45
+ document.removeEventListener('keydown', onKeyDown, true);
46
+ };
47
+ }
48
+ }, [
49
+ ref,
50
+ state
51
+ ]);
52
+ let onHoverStart = ()=>{
53
+ if (trigger === 'focus') return;
54
+ // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
55
+ // interactions for example, hover will end. When hover is restored after that element disappears,
56
+ // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
57
+ // is the result of moving the mouse.
58
+ if ((0, $6VwSn$getInteractionModality)() === 'pointer') isHovered.current = true;
59
+ else isHovered.current = false;
60
+ handleShow();
61
+ };
62
+ let onHoverEnd = ()=>{
63
+ if (trigger === 'focus') return;
64
+ // no matter how the trigger is left, we should close the tooltip
65
+ isFocused.current = false;
66
+ isHovered.current = false;
67
+ handleHide();
68
+ };
69
+ let onPressStart = ()=>{
70
+ // no matter how the trigger is pressed, we should close the tooltip
71
+ isFocused.current = false;
72
+ isHovered.current = false;
73
+ handleHide(true);
74
+ };
75
+ let onFocus = ()=>{
76
+ let isVisible = (0, $6VwSn$isFocusVisible)();
77
+ if (isVisible) {
78
+ isFocused.current = true;
79
+ handleShow();
80
+ }
81
+ };
82
+ let onBlur = ()=>{
83
+ isFocused.current = false;
84
+ isHovered.current = false;
85
+ handleHide(true);
86
+ };
87
+ let { hoverProps: hoverProps } = (0, $6VwSn$useHover)({
88
+ isDisabled: isDisabled,
89
+ onHoverStart: onHoverStart,
90
+ onHoverEnd: onHoverEnd
91
+ });
92
+ let { focusableProps: focusableProps } = (0, $6VwSn$useFocusable)({
93
+ isDisabled: isDisabled,
94
+ onFocus: onFocus,
95
+ onBlur: onBlur
96
+ }, ref);
97
+ return {
98
+ triggerProps: {
99
+ 'aria-describedby': state.isOpen ? tooltipId : undefined,
100
+ ...(0, $6VwSn$mergeProps)(focusableProps, hoverProps, {
101
+ onPointerDown: onPressStart,
102
+ onKeyDown: onPressStart
103
+ })
104
+ },
105
+ tooltipProps: {
106
+ id: tooltipId
107
+ }
108
+ };
109
+ }
110
+
111
+
112
+ export {$4e1b34546679e357$export$a6da6c504e4bba8b as useTooltipTrigger};
113
+ //# sourceMappingURL=useTooltipTrigger.module.js.map
@@ -0,0 +1,113 @@
1
+ import {getInteractionModality as $6VwSn$getInteractionModality, isFocusVisible as $6VwSn$isFocusVisible, useHover as $6VwSn$useHover} from "@react-aria/interactions";
2
+ import {useId as $6VwSn$useId, mergeProps as $6VwSn$mergeProps} from "@react-aria/utils";
3
+ import {useRef as $6VwSn$useRef, useEffect as $6VwSn$useEffect} from "react";
4
+ import {useFocusable as $6VwSn$useFocusable} from "@react-aria/focus";
5
+
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
21
+ let { isDisabled: isDisabled, trigger: trigger } = props;
22
+ let tooltipId = (0, $6VwSn$useId)();
23
+ let isHovered = (0, $6VwSn$useRef)(false);
24
+ let isFocused = (0, $6VwSn$useRef)(false);
25
+ let handleShow = ()=>{
26
+ if (isHovered.current || isFocused.current) state.open(isFocused.current);
27
+ };
28
+ let handleHide = (immediate)=>{
29
+ if (!isHovered.current && !isFocused.current) state.close(immediate);
30
+ };
31
+ (0, $6VwSn$useEffect)(()=>{
32
+ let onKeyDown = (e)=>{
33
+ if (ref && ref.current) // Escape after clicking something can give it keyboard focus
34
+ // dismiss tooltip on esc key press
35
+ {
36
+ if (e.key === 'Escape') {
37
+ e.stopPropagation();
38
+ state.close(true);
39
+ }
40
+ }
41
+ };
42
+ if (state.isOpen) {
43
+ document.addEventListener('keydown', onKeyDown, true);
44
+ return ()=>{
45
+ document.removeEventListener('keydown', onKeyDown, true);
46
+ };
47
+ }
48
+ }, [
49
+ ref,
50
+ state
51
+ ]);
52
+ let onHoverStart = ()=>{
53
+ if (trigger === 'focus') return;
54
+ // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
55
+ // interactions for example, hover will end. When hover is restored after that element disappears,
56
+ // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
57
+ // is the result of moving the mouse.
58
+ if ((0, $6VwSn$getInteractionModality)() === 'pointer') isHovered.current = true;
59
+ else isHovered.current = false;
60
+ handleShow();
61
+ };
62
+ let onHoverEnd = ()=>{
63
+ if (trigger === 'focus') return;
64
+ // no matter how the trigger is left, we should close the tooltip
65
+ isFocused.current = false;
66
+ isHovered.current = false;
67
+ handleHide();
68
+ };
69
+ let onPressStart = ()=>{
70
+ // no matter how the trigger is pressed, we should close the tooltip
71
+ isFocused.current = false;
72
+ isHovered.current = false;
73
+ handleHide(true);
74
+ };
75
+ let onFocus = ()=>{
76
+ let isVisible = (0, $6VwSn$isFocusVisible)();
77
+ if (isVisible) {
78
+ isFocused.current = true;
79
+ handleShow();
80
+ }
81
+ };
82
+ let onBlur = ()=>{
83
+ isFocused.current = false;
84
+ isHovered.current = false;
85
+ handleHide(true);
86
+ };
87
+ let { hoverProps: hoverProps } = (0, $6VwSn$useHover)({
88
+ isDisabled: isDisabled,
89
+ onHoverStart: onHoverStart,
90
+ onHoverEnd: onHoverEnd
91
+ });
92
+ let { focusableProps: focusableProps } = (0, $6VwSn$useFocusable)({
93
+ isDisabled: isDisabled,
94
+ onFocus: onFocus,
95
+ onBlur: onBlur
96
+ }, ref);
97
+ return {
98
+ triggerProps: {
99
+ 'aria-describedby': state.isOpen ? tooltipId : undefined,
100
+ ...(0, $6VwSn$mergeProps)(focusableProps, hoverProps, {
101
+ onPointerDown: onPressStart,
102
+ onKeyDown: onPressStart
103
+ })
104
+ },
105
+ tooltipProps: {
106
+ id: tooltipId
107
+ }
108
+ };
109
+ }
110
+
111
+
112
+ export {$4e1b34546679e357$export$a6da6c504e4bba8b as useTooltipTrigger};
113
+ //# sourceMappingURL=useTooltipTrigger.module.js.map
@@ -0,0 +1 @@
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,EAC1C,MAAM,KAAK,CAAC;IAEhB;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,YAAY,CAAC;YACf,IAAI,OAAO,IAAI,OAAO,EACpB,6DAA6D;YAC7D,mCAAmC;YACnC;gBAAA,IAAI,EAAE,GAAG,KAAK,UAAU;oBACtB,EAAE,eAAe;oBACjB,MAAM,KAAK,CAAC;gBACd;YAAA;QAEJ;QACA,IAAI,MAAM,MAAM,EAAE;YAChB,SAAS,gBAAgB,CAAC,WAAW,WAAW;YAChD,OAAO;gBACL,SAAS,mBAAmB,CAAC,WAAW,WAAW;YACrD;QACF;IACF,GAAG;QAAC;QAAK;KAAM;IAEf,IAAI,eAAe;QACjB,IAAI,YAAY,SACd;QAEF,uFAAuF;QACvF,kGAAkG;QAClG,uGAAuG;QACvG,qCAAqC;QACrC,IAAI,CAAA,GAAA,6BAAqB,QAAQ,WAC/B,UAAU,OAAO,GAAG;aAEpB,UAAU,OAAO,GAAG;QAEtB;IACF;IAEA,IAAI,aAAa;QACf,IAAI,YAAY,SACd;QAEF,iEAAiE;QACjE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB;IACF;IAEA,IAAI,eAAe;QACjB,oEAAoE;QACpE,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,UAAU;QACZ,IAAI,YAAY,CAAA,GAAA,qBAAa;QAC7B,IAAI,WAAW;YACb,UAAU,OAAO,GAAG;YACpB;QACF;IACF;IAEA,IAAI,SAAS;QACX,UAAU,OAAO,GAAG;QACpB,UAAU,OAAO,GAAG;QACpB,WAAW;IACb;IAEA,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;oBAC1B;sBACA;oBACA;IACF;IAEA,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE;oBAClC;iBACA;gBACA;IACF,GAAG;IAEH,OAAO;QACL,cAAc;YACZ,oBAAoB,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,10 +1,15 @@
1
1
  {
2
2
  "name": "@react-aria/tooltip",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-nightly-4980928d3-240906",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
+ "exports": {
9
+ "types": "./dist/types.d.ts",
10
+ "import": "./dist/import.mjs",
11
+ "require": "./dist/main.js"
12
+ },
8
13
  "types": "dist/types.d.ts",
9
14
  "source": "src/index.ts",
10
15
  "files": [
@@ -17,20 +22,19 @@
17
22
  "url": "https://github.com/adobe/react-spectrum"
18
23
  },
19
24
  "dependencies": {
20
- "@babel/runtime": "^7.6.2",
21
- "@react-aria/focus": "^3.2.0",
22
- "@react-aria/interactions": "^3.2.0",
23
- "@react-aria/overlays": "^3.2.0",
24
- "@react-aria/utils": "^3.2.0",
25
- "@react-stately/tooltip": "3.0.0-alpha.0",
26
- "@react-types/shared": "^3.2.0",
27
- "@react-types/tooltip": "3.0.0-alpha.0"
25
+ "@react-aria/focus": "^3.0.0-nightly-4980928d3-240906",
26
+ "@react-aria/interactions": "^3.0.0-nightly-4980928d3-240906",
27
+ "@react-aria/utils": "^3.0.0-nightly-4980928d3-240906",
28
+ "@react-stately/tooltip": "^3.0.0-nightly-4980928d3-240906",
29
+ "@react-types/shared": "^3.0.0-nightly-4980928d3-240906",
30
+ "@react-types/tooltip": "^3.0.0-nightly-4980928d3-240906",
31
+ "@swc/helpers": "^0.5.0"
28
32
  },
29
33
  "peerDependencies": {
30
- "react": "^16.8.0"
34
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
31
35
  },
32
36
  "publishConfig": {
33
37
  "access": "public"
34
38
  },
35
- "gitHead": "661f0f2e3b8648a75aae83043267954700059fe0"
36
- }
39
+ "stableVersion": "3.7.7"
40
+ }
package/src/index.ts CHANGED
@@ -9,6 +9,8 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
-
13
- export * from './useTooltip';
14
- export * from './useTooltipTrigger';
12
+ export {useTooltip} from './useTooltip';
13
+ export {useTooltipTrigger} from './useTooltipTrigger';
14
+ export type {AriaTooltipProps, TooltipTriggerProps} from '@react-types/tooltip';
15
+ export type {TooltipAria} from './useTooltip';
16
+ export type {TooltipTriggerAria} from './useTooltipTrigger';
package/src/useTooltip.ts CHANGED
@@ -11,25 +11,32 @@
11
11
  */
12
12
 
13
13
  import {AriaTooltipProps} from '@react-types/tooltip';
14
- import {filterDOMProps, mergeProps, useId} from '@react-aria/utils';
15
- import {HTMLAttributes} from 'react';
14
+ import {DOMAttributes} from '@react-types/shared';
15
+ import {filterDOMProps, mergeProps} from '@react-aria/utils';
16
+ import {TooltipTriggerState} from '@react-stately/tooltip';
17
+ import {useHover} from '@react-aria/interactions';
16
18
 
17
- interface TooltipAria {
18
- tooltipProps: HTMLAttributes<HTMLElement>
19
+ export interface TooltipAria {
20
+ /**
21
+ * Props for the tooltip element.
22
+ */
23
+ tooltipProps: DOMAttributes
19
24
  }
20
25
 
21
- export function useTooltip(props: AriaTooltipProps): TooltipAria {
22
- let {
23
- id,
24
- role = 'tooltip'
25
- } = props;
26
+ /**
27
+ * Provides the accessibility implementation for a Tooltip component.
28
+ */
29
+ export function useTooltip(props: AriaTooltipProps, state?: TooltipTriggerState): TooltipAria {
30
+ let domProps = filterDOMProps(props, {labelable: true});
26
31
 
27
- let domProps = filterDOMProps(props);
32
+ let {hoverProps} = useHover({
33
+ onHoverStart: () => state?.open(true),
34
+ onHoverEnd: () => state?.close()
35
+ });
28
36
 
29
37
  return {
30
- tooltipProps: mergeProps(domProps, {
31
- role,
32
- id: useId(id)
38
+ tooltipProps: mergeProps(domProps, hoverProps, {
39
+ role: 'tooltip'
33
40
  })
34
41
  };
35
42
  }
@@ -10,23 +10,34 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {FocusEvents} from '@react-types/shared';
14
- import {HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';
15
- import {HTMLAttributes, RefObject, useEffect, useRef} from 'react';
13
+ import {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';
14
+ import {getInteractionModality, isFocusVisible, useHover} from '@react-aria/interactions';
16
15
  import {mergeProps, useId} from '@react-aria/utils';
17
- import {TooltipTriggerAriaProps} from '@react-types/tooltip';
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
- import {useHover} from '@react-aria/interactions';
21
20
 
22
- interface TooltipTriggerAria {
23
- triggerProps: HTMLAttributes<HTMLElement> & PressProps & HoverProps & FocusEvents,
24
- tooltipProps: HTMLAttributes<HTMLElement>
21
+ export interface TooltipTriggerAria {
22
+ /**
23
+ * Props for the trigger element.
24
+ */
25
+ triggerProps: DOMAttributes,
26
+
27
+ /**
28
+ * Props for the overlay container element.
29
+ */
30
+ tooltipProps: DOMAttributes
25
31
  }
26
32
 
27
- export function useTooltipTrigger(props: TooltipTriggerAriaProps, state: TooltipTriggerState, ref: RefObject<HTMLElement>) : TooltipTriggerAria {
33
+ /**
34
+ * Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button
35
+ * that shows a description when focused or hovered.
36
+ */
37
+ export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref: RefObject<FocusableElement | null>) : TooltipTriggerAria {
28
38
  let {
29
- isDisabled
39
+ isDisabled,
40
+ trigger
30
41
  } = props;
31
42
 
32
43
  let tooltipId = useId();
@@ -35,12 +46,14 @@ export function useTooltipTrigger(props: TooltipTriggerAriaProps, state: Tooltip
35
46
  let isFocused = useRef(false);
36
47
 
37
48
  let handleShow = () => {
38
- state.open(isFocused.current);
49
+ if (isHovered.current || isFocused.current) {
50
+ state.open(isFocused.current);
51
+ }
39
52
  };
40
53
 
41
- let handleHide = () => {
54
+ let handleHide = (immediate?: boolean) => {
42
55
  if (!isHovered.current && !isFocused.current) {
43
- state.close();
56
+ state.close(immediate);
44
57
  }
45
58
  };
46
59
 
@@ -50,32 +63,52 @@ export function useTooltipTrigger(props: TooltipTriggerAriaProps, state: Tooltip
50
63
  // Escape after clicking something can give it keyboard focus
51
64
  // dismiss tooltip on esc key press
52
65
  if (e.key === 'Escape') {
53
- state.close();
66
+ e.stopPropagation();
67
+ state.close(true);
54
68
  }
55
69
  }
56
70
  };
57
71
  if (state.isOpen) {
58
- document.addEventListener('keydown', onKeyDown);
72
+ document.addEventListener('keydown', onKeyDown, true);
59
73
  return () => {
60
- document.removeEventListener('keydown', onKeyDown);
74
+ document.removeEventListener('keydown', onKeyDown, true);
61
75
  };
62
76
  }
63
77
  }, [ref, state]);
64
78
 
65
79
  let onHoverStart = () => {
66
- isHovered.current = true;
80
+ if (trigger === 'focus') {
81
+ return;
82
+ }
83
+ // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
84
+ // interactions for example, hover will end. When hover is restored after that element disappears,
85
+ // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
86
+ // is the result of moving the mouse.
87
+ if (getInteractionModality() === 'pointer') {
88
+ isHovered.current = true;
89
+ } else {
90
+ isHovered.current = false;
91
+ }
67
92
  handleShow();
68
93
  };
94
+
69
95
  let onHoverEnd = () => {
96
+ if (trigger === 'focus') {
97
+ return;
98
+ }
99
+ // no matter how the trigger is left, we should close the tooltip
100
+ isFocused.current = false;
70
101
  isHovered.current = false;
71
102
  handleHide();
72
103
  };
104
+
73
105
  let onPressStart = () => {
74
- if (isFocused.current) {
75
- isFocused.current = false;
76
- }
77
- handleHide();
106
+ // no matter how the trigger is pressed, we should close the tooltip
107
+ isFocused.current = false;
108
+ isHovered.current = false;
109
+ handleHide(true);
78
110
  };
111
+
79
112
  let onFocus = () => {
80
113
  let isVisible = isFocusVisible();
81
114
  if (isVisible) {
@@ -83,9 +116,11 @@ export function useTooltipTrigger(props: TooltipTriggerAriaProps, state: Tooltip
83
116
  handleShow();
84
117
  }
85
118
  };
119
+
86
120
  let onBlur = () => {
87
121
  isFocused.current = false;
88
- handleHide();
122
+ isHovered.current = false;
123
+ handleHide(true);
89
124
  };
90
125
 
91
126
  let {hoverProps} = useHover({
@@ -94,8 +129,6 @@ export function useTooltipTrigger(props: TooltipTriggerAriaProps, state: Tooltip
94
129
  onHoverEnd
95
130
  });
96
131
 
97
- let {pressProps} = usePress({onPressStart});
98
-
99
132
  let {focusableProps} = useFocusable({
100
133
  isDisabled,
101
134
  onFocus,
@@ -104,8 +137,11 @@ export function useTooltipTrigger(props: TooltipTriggerAriaProps, state: Tooltip
104
137
 
105
138
  return {
106
139
  triggerProps: {
107
- 'aria-describedby': state.open ? tooltipId : undefined,
108
- ...mergeProps(focusableProps, hoverProps, pressProps)
140
+ 'aria-describedby': state.isOpen ? tooltipId : undefined,
141
+ ...mergeProps(focusableProps, hoverProps, {
142
+ onPointerDown: onPressStart,
143
+ onKeyDown: onPressStart
144
+ })
109
145
  },
110
146
  tooltipProps: {
111
147
  id: tooltipId