@react-aria/tooltip 3.1.0 → 3.1.4

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/main.js CHANGED
@@ -1,170 +1,148 @@
1
- var {
2
- useFocusable
3
- } = require("@react-aria/focus");
4
-
5
- var {
6
- useEffect,
7
- useRef
8
- } = require("react");
9
-
10
- var {
11
- getInteractionModality,
12
- isFocusVisible,
13
- usePress,
14
- useHover
15
- } = require("@react-aria/interactions");
16
-
17
- var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
18
-
19
- var {
20
- filterDOMProps,
21
- mergeProps,
22
- useId
23
- } = require("@react-aria/utils");
24
-
25
- function $parcel$interopDefault(a) {
26
- return a && a.__esModule ? a.default : a;
27
- }
28
-
29
- /**
30
- * Provides the accessibility implementation for a Tooltip component.
31
- */
32
- function useTooltip(props) {
33
- let domProps = filterDOMProps(props, {
34
- labelable: true
35
- });
36
- return {
37
- tooltipProps: mergeProps(domProps, {
38
- role: 'tooltip'
39
- })
40
- };
41
- }
42
-
43
- exports.useTooltip = useTooltip;
44
-
45
- /**
46
- * Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button
47
- * that shows a description when focused or hovered.
48
- */
49
- function useTooltipTrigger(props, state, ref) {
50
- let {
51
- isDisabled,
52
- trigger
53
- } = props;
54
- let tooltipId = useId();
55
- let isHovered = useRef(false);
56
- let isFocused = useRef(false);
57
-
58
- let handleShow = () => {
59
- if (isHovered.current || isFocused.current) {
60
- state.open(isFocused.current);
1
+ var $i8XfT$reactariautils = require("@react-aria/utils");
2
+ var $i8XfT$reactariainteractions = require("@react-aria/interactions");
3
+ var $i8XfT$react = require("react");
4
+ var $i8XfT$reactariafocus = require("@react-aria/focus");
5
+
6
+ function $parcel$exportWildcard(dest, source) {
7
+ Object.keys(source).forEach(function(key) {
8
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
9
+ return;
61
10
  }
62
- };
63
11
 
64
- let handleHide = () => {
65
- if (!isHovered.current && !isFocused.current) {
66
- state.close();
67
- }
68
- };
69
-
70
- useEffect(() => {
71
- let onKeyDown = e => {
72
- if (ref && ref.current) {
73
- // Escape after clicking something can give it keyboard focus
74
- // dismiss tooltip on esc key press
75
- if (e.key === 'Escape') {
76
- state.close();
77
- }
12
+ Object.defineProperty(dest, key, {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return source[key];
78
16
  }
17
+ });
18
+ });
19
+
20
+ return dest;
21
+ }
22
+ function $parcel$export(e, n, v, s) {
23
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
24
+ }
25
+ var $ee9e5c4a26dbd5fe$exports = {};
26
+
27
+ $parcel$export($ee9e5c4a26dbd5fe$exports, "useTooltip", () => $ee9e5c4a26dbd5fe$export$1c4b08e0eca38426);
28
+
29
+
30
+ function $ee9e5c4a26dbd5fe$export$1c4b08e0eca38426(props, state) {
31
+ let domProps = $i8XfT$reactariautils.filterDOMProps(props, {
32
+ labelable: true
33
+ });
34
+ let { hoverProps: hoverProps } = $i8XfT$reactariainteractions.useHover({
35
+ onHoverStart: ()=>state?.open(true)
36
+ ,
37
+ onHoverEnd: ()=>state?.close()
38
+ });
39
+ return {
40
+ tooltipProps: $i8XfT$reactariautils.mergeProps(domProps, hoverProps, {
41
+ role: 'tooltip'
42
+ })
79
43
  };
44
+ }
80
45
 
81
- if (state.isOpen) {
82
- document.addEventListener('keydown', onKeyDown, true);
83
- return () => {
84
- document.removeEventListener('keydown', onKeyDown, true);
85
- };
86
- }
87
- }, [ref, state]);
88
46
 
89
- let onHoverStart = () => {
90
- if (trigger === 'focus') {
91
- return;
92
- } // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
93
- // interactions for example, hover will end. When hover is restored after that element disappears,
94
- // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
95
- // is the result of moving the mouse.
47
+ var $2dec65ceb6e1926a$exports = {};
96
48
 
49
+ $parcel$export($2dec65ceb6e1926a$exports, "useTooltipTrigger", () => $2dec65ceb6e1926a$export$a6da6c504e4bba8b);
97
50
 
98
- if (getInteractionModality() === 'pointer') {
99
- isHovered.current = true;
100
- } else {
101
- isHovered.current = false;
102
- }
103
51
 
104
- handleShow();
105
- };
106
52
 
107
- let onHoverEnd = () => {
108
- if (trigger === 'focus') {
109
- return;
110
- } // no matter how the trigger is left, we should close the tooltip
111
53
 
112
54
 
113
- isFocused.current = false;
114
- isHovered.current = false;
115
- handleHide();
116
- };
55
+ function $2dec65ceb6e1926a$export$a6da6c504e4bba8b(props, state, ref) {
56
+ let { isDisabled: isDisabled , trigger: trigger } = props;
57
+ let tooltipId = $i8XfT$reactariautils.useId();
58
+ let isHovered = $i8XfT$react.useRef(false);
59
+ let isFocused = $i8XfT$react.useRef(false);
60
+ let handleShow = ()=>{
61
+ if (isHovered.current || isFocused.current) state.open(isFocused.current);
62
+ };
63
+ let handleHide = (immediate)=>{
64
+ if (!isHovered.current && !isFocused.current) state.close(immediate);
65
+ };
66
+ $i8XfT$react.useEffect(()=>{
67
+ let onKeyDown = (e)=>{
68
+ if (ref && ref.current) // Escape after clicking something can give it keyboard focus
69
+ // dismiss tooltip on esc key press
70
+ {
71
+ if (e.key === 'Escape') state.close(true);
72
+ }
73
+ };
74
+ if (state.isOpen) {
75
+ document.addEventListener('keydown', onKeyDown, true);
76
+ return ()=>{
77
+ document.removeEventListener('keydown', onKeyDown, true);
78
+ };
79
+ }
80
+ }, [
81
+ ref,
82
+ state
83
+ ]);
84
+ let onHoverStart = ()=>{
85
+ if (trigger === 'focus') return;
86
+ // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
87
+ // interactions for example, hover will end. When hover is restored after that element disappears,
88
+ // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
89
+ // is the result of moving the mouse.
90
+ if ($i8XfT$reactariainteractions.getInteractionModality() === 'pointer') isHovered.current = true;
91
+ else isHovered.current = false;
92
+ handleShow();
93
+ };
94
+ let onHoverEnd = ()=>{
95
+ if (trigger === 'focus') return;
96
+ // no matter how the trigger is left, we should close the tooltip
97
+ isFocused.current = false;
98
+ isHovered.current = false;
99
+ handleHide();
100
+ };
101
+ let onPressStart = ()=>{
102
+ // no matter how the trigger is pressed, we should close the tooltip
103
+ isFocused.current = false;
104
+ isHovered.current = false;
105
+ handleHide(true);
106
+ };
107
+ let onFocus = ()=>{
108
+ let isVisible = $i8XfT$reactariainteractions.isFocusVisible();
109
+ if (isVisible) {
110
+ isFocused.current = true;
111
+ handleShow();
112
+ }
113
+ };
114
+ let onBlur = ()=>{
115
+ isFocused.current = false;
116
+ isHovered.current = false;
117
+ handleHide(true);
118
+ };
119
+ let { hoverProps: hoverProps } = $i8XfT$reactariainteractions.useHover({
120
+ isDisabled: isDisabled,
121
+ onHoverStart: onHoverStart,
122
+ onHoverEnd: onHoverEnd
123
+ });
124
+ let { pressProps: pressProps } = $i8XfT$reactariainteractions.usePress({
125
+ onPressStart: onPressStart
126
+ });
127
+ let { focusableProps: focusableProps } = $i8XfT$reactariafocus.useFocusable({
128
+ isDisabled: isDisabled,
129
+ onFocus: onFocus,
130
+ onBlur: onBlur
131
+ }, ref);
132
+ return {
133
+ triggerProps: {
134
+ 'aria-describedby': state.isOpen ? tooltipId : undefined,
135
+ ...$i8XfT$reactariautils.mergeProps(focusableProps, hoverProps, pressProps)
136
+ },
137
+ tooltipProps: {
138
+ id: tooltipId
139
+ }
140
+ };
141
+ }
117
142
 
118
- let onPressStart = () => {
119
- // no matter how the trigger is pressed, we should close the tooltip
120
- isFocused.current = false;
121
- isHovered.current = false;
122
- handleHide();
123
- };
124
143
 
125
- let onFocus = () => {
126
- let isVisible = isFocusVisible();
144
+ $parcel$exportWildcard(module.exports, $ee9e5c4a26dbd5fe$exports);
145
+ $parcel$exportWildcard(module.exports, $2dec65ceb6e1926a$exports);
127
146
 
128
- if (isVisible) {
129
- isFocused.current = true;
130
- handleShow();
131
- }
132
- };
133
-
134
- let onBlur = () => {
135
- isFocused.current = false;
136
- isHovered.current = false;
137
- handleHide();
138
- };
139
-
140
- let {
141
- hoverProps
142
- } = useHover({
143
- isDisabled,
144
- onHoverStart,
145
- onHoverEnd
146
- });
147
- let {
148
- pressProps
149
- } = usePress({
150
- onPressStart
151
- });
152
- let {
153
- focusableProps
154
- } = useFocusable({
155
- isDisabled,
156
- onFocus,
157
- onBlur
158
- }, ref);
159
- return {
160
- triggerProps: _babelRuntimeHelpersExtends({
161
- 'aria-describedby': state.isOpen ? tooltipId : undefined
162
- }, mergeProps(focusableProps, hoverProps, pressProps)),
163
- tooltipProps: {
164
- id: tooltipId
165
- }
166
- };
167
- }
168
147
 
169
- exports.useTooltipTrigger = useTooltipTrigger;
170
148
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;ACqBD;;;AAGO,SAASG,UAAT,CAAoBC,KAApB,EAA0D;AAC/D,MAAIC,QAAQ,GAAGC,cAAc,CAACF,KAAD,EAAQ;AAACG,IAAAA,SAAS,EAAE;AAAZ,GAAR,CAA7B;AAEA,SAAO;AACLC,IAAAA,YAAY,EAAEC,UAAU,CAACJ,QAAD,EAAW;AACjCK,MAAAA,IAAI,EAAE;AAD2B,KAAX;AADnB,GAAP;AAKD;;;;ACDD;;;;AAIO,SAASC,iBAAT,CAA2BP,KAA3B,EAAuDQ,KAAvD,EAAmFC,GAAnF,EAAqI;AAC1I,MAAI;AACFC,IAAAA,UADE;AAEFC,IAAAA;AAFE,MAGAX,KAHJ;AAKA,MAAIY,SAAS,GAAGC,KAAK,EAArB;AAEA,MAAIC,SAAS,GAAGC,MAAM,CAAC,KAAD,CAAtB;AACA,MAAIC,SAAS,GAAGD,MAAM,CAAC,KAAD,CAA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,EAAElC;AADQ;AALT,GAAP;AASD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-aria/tooltip/src/useTooltip.ts","./packages/@react-aria/tooltip/src/useTooltipTrigger.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","/*\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 {AriaTooltipProps} from '@react-types/tooltip';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes} from 'react';\n\ninterface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the accessibility implementation for a Tooltip component.\n */\nexport function useTooltip(props: AriaTooltipProps): TooltipAria {\n let domProps = filterDOMProps(props, {labelable: true});\n\n return {\n tooltipProps: mergeProps(domProps, {\n role: 'tooltip'\n })\n };\n}\n","/*\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 {FocusEvents} from '@react-types/shared';\nimport {getInteractionModality, HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';\nimport {HTMLAttributes, RefObject, useEffect, useRef} from 'react';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useFocusable} from '@react-aria/focus';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: HTMLAttributes<HTMLElement> & PressProps & HoverProps & FocusEvents,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\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<HTMLElement>) : 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 = () => {\n if (!isHovered.current && !isFocused.current) {\n state.close();\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 state.close();\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();\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();\n };\n\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart,\n onHoverEnd\n });\n\n let {pressProps} = usePress({onPressStart});\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, pressProps)\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":["$parcel$interopDefault","a","__esModule","default","useTooltip","props","domProps","filterDOMProps","labelable","tooltipProps","mergeProps","role","useTooltipTrigger","state","ref","isDisabled","trigger","tooltipId","useId","isHovered","useRef","isFocused","handleShow","current","open","handleHide","close","useEffect","onKeyDown","e","key","isOpen","document","addEventListener","removeEventListener","onHoverStart","getInteractionModality","onHoverEnd","onPressStart","onFocus","isVisible","isFocusVisible","onBlur","hoverProps","useHover","pressProps","usePress","focusableProps","useFocusable","triggerProps","undefined","id"],"version":3,"file":"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nB,GAAG,CAAC,SAAS,GAAG,2CAAc;QAC9B,EAAE,EAAE,SAAS,EAAE,CAAC;YACd,SAAS,CAAC,OAAO,GAAG,IAAI;YACxB,UAAU;QACZ,CAAC;IACH,CAAC;IAED,GAAG,CAAC,MAAM,OAAS,CAAC;QAClB,SAAS,CAAC,OAAO,GAAG,KAAK;QACzB,SAAS,CAAC,OAAO,GAAG,KAAK;QACzB,UAAU,CAAC,IAAI;IACjB,CAAC;IAED,GAAG,CAAC,CAAC,aAAA,UAAU,EAAA,CAAC,GAAG,qCAAQ,CAAC,CAAC;oBAC3B,UAAU;sBACV,YAAY;oBACZ,UAAU;IACZ,CAAC;IAED,GAAG,CAAC,CAAC,aAAA,UAAU,EAAA,CAAC,GAAG,qCAAQ,CAAC,CAAC;sBAAA,YAAY;IAAA,CAAC;IAE1C,GAAG,CAAC,CAAC,iBAAA,cAAc,EAAA,CAAC,GAAG,kCAAY,CAAC,CAAC;oBACnC,UAAU;iBACV,OAAO;gBACP,MAAM;IACR,CAAC,EAAE,GAAG;IAEN,MAAM,CAAC,CAAC;QACN,YAAY,EAAE,CAAC;YACb,CAAkB,mBAAE,KAAK,CAAC,MAAM,GAAG,SAAS,GAAG,SAAS;eACrD,gCAAU,CAAC,cAAc,EAAE,UAAU,EAAE,UAAU;QACtD,CAAC;QACD,YAAY,EAAE,CAAC;YACb,EAAE,EAAE,SAAS;QACf,CAAC;IACH,CAAC;AACH,CAAC;;","sources":["packages/@react-aria/tooltip/src/index.ts","packages/@react-aria/tooltip/src/useTooltip.ts","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\nexport * from './useTooltip';\nexport * from './useTooltipTrigger';\n","/*\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 {AriaTooltipProps} from '@react-types/tooltip';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes} from 'react';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the accessibility implementation for a Tooltip component.\n */\nexport function useTooltip(props: AriaTooltipProps, state?: TooltipTriggerState): TooltipAria {\n let domProps = filterDOMProps(props, {labelable: true});\n\n let {hoverProps} = useHover({\n onHoverStart: () => state?.open(true),\n onHoverEnd: () => state?.close()\n });\n\n return {\n tooltipProps: mergeProps(domProps, hoverProps, {\n role: 'tooltip'\n })\n };\n}\n","/*\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 {FocusEvents} from '@react-types/shared';\nimport {getInteractionModality, HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';\nimport {HTMLAttributes, RefObject, useEffect, useRef} from 'react';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useFocusable} from '@react-aria/focus';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: HTMLAttributes<HTMLElement> & PressProps & HoverProps & FocusEvents,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\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<HTMLElement>) : 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 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 {pressProps} = usePress({onPressStart});\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, pressProps)\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,144 +1,131 @@
1
- import { useFocusable } from "@react-aria/focus";
2
- import { useEffect, useRef } from "react";
3
- import { getInteractionModality, isFocusVisible, usePress, useHover } from "@react-aria/interactions";
4
- import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
5
- import { filterDOMProps, mergeProps, useId } from "@react-aria/utils";
6
-
7
- /**
8
- * Provides the accessibility implementation for a Tooltip component.
9
- */
10
- export function useTooltip(props) {
11
- let domProps = filterDOMProps(props, {
12
- labelable: true
13
- });
14
- return {
15
- tooltipProps: mergeProps(domProps, {
16
- role: 'tooltip'
17
- })
18
- };
1
+ import {filterDOMProps as $f5fb1$filterDOMProps, mergeProps as $f5fb1$mergeProps, useId as $f5fb1$useId} from "@react-aria/utils";
2
+ import {useHover as $f5fb1$useHover, getInteractionModality as $f5fb1$getInteractionModality, isFocusVisible as $f5fb1$isFocusVisible, usePress as $f5fb1$usePress} from "@react-aria/interactions";
3
+ import {useRef as $f5fb1$useRef, useEffect as $f5fb1$useEffect} from "react";
4
+ import {useFocusable as $f5fb1$useFocusable} from "@react-aria/focus";
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+ var $a3378f049123a239$exports = {};
10
+
11
+ $parcel$export($a3378f049123a239$exports, "useTooltip", () => $a3378f049123a239$export$1c4b08e0eca38426);
12
+
13
+
14
+ function $a3378f049123a239$export$1c4b08e0eca38426(props, state) {
15
+ let domProps = $f5fb1$filterDOMProps(props, {
16
+ labelable: true
17
+ });
18
+ let { hoverProps: hoverProps } = $f5fb1$useHover({
19
+ onHoverStart: ()=>state?.open(true)
20
+ ,
21
+ onHoverEnd: ()=>state?.close()
22
+ });
23
+ return {
24
+ tooltipProps: $f5fb1$mergeProps(domProps, hoverProps, {
25
+ role: 'tooltip'
26
+ })
27
+ };
19
28
  }
20
29
 
21
- /**
22
- * Provides the behavior and accessibility implementation for a tooltip trigger, e.g. a button
23
- * that shows a description when focused or hovered.
24
- */
25
- export function useTooltipTrigger(props, state, ref) {
26
- let {
27
- isDisabled,
28
- trigger
29
- } = props;
30
- let tooltipId = useId();
31
- let isHovered = useRef(false);
32
- let isFocused = useRef(false);
33
-
34
- let handleShow = () => {
35
- if (isHovered.current || isFocused.current) {
36
- state.open(isFocused.current);
37
- }
38
- };
39
-
40
- let handleHide = () => {
41
- if (!isHovered.current && !isFocused.current) {
42
- state.close();
43
- }
44
- };
45
-
46
- useEffect(() => {
47
- let onKeyDown = e => {
48
- if (ref && ref.current) {
49
- // Escape after clicking something can give it keyboard focus
50
- // dismiss tooltip on esc key press
51
- if (e.key === 'Escape') {
52
- state.close();
30
+
31
+ var $c2d8fb326b9f06da$exports = {};
32
+
33
+ $parcel$export($c2d8fb326b9f06da$exports, "useTooltipTrigger", () => $c2d8fb326b9f06da$export$a6da6c504e4bba8b);
34
+
35
+
36
+
37
+
38
+
39
+ function $c2d8fb326b9f06da$export$a6da6c504e4bba8b(props, state, ref) {
40
+ let { isDisabled: isDisabled , trigger: trigger } = props;
41
+ let tooltipId = $f5fb1$useId();
42
+ let isHovered = $f5fb1$useRef(false);
43
+ let isFocused = $f5fb1$useRef(false);
44
+ let handleShow = ()=>{
45
+ if (isHovered.current || isFocused.current) state.open(isFocused.current);
46
+ };
47
+ let handleHide = (immediate)=>{
48
+ if (!isHovered.current && !isFocused.current) state.close(immediate);
49
+ };
50
+ $f5fb1$useEffect(()=>{
51
+ let onKeyDown = (e)=>{
52
+ if (ref && ref.current) // Escape after clicking something can give it keyboard focus
53
+ // dismiss tooltip on esc key press
54
+ {
55
+ if (e.key === 'Escape') state.close(true);
56
+ }
57
+ };
58
+ if (state.isOpen) {
59
+ document.addEventListener('keydown', onKeyDown, true);
60
+ return ()=>{
61
+ document.removeEventListener('keydown', onKeyDown, true);
62
+ };
63
+ }
64
+ }, [
65
+ ref,
66
+ state
67
+ ]);
68
+ let onHoverStart = ()=>{
69
+ if (trigger === 'focus') return;
70
+ // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
71
+ // interactions for example, hover will end. When hover is restored after that element disappears,
72
+ // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
73
+ // is the result of moving the mouse.
74
+ if ($f5fb1$getInteractionModality() === 'pointer') isHovered.current = true;
75
+ else isHovered.current = false;
76
+ handleShow();
77
+ };
78
+ let onHoverEnd = ()=>{
79
+ if (trigger === 'focus') return;
80
+ // no matter how the trigger is left, we should close the tooltip
81
+ isFocused.current = false;
82
+ isHovered.current = false;
83
+ handleHide();
84
+ };
85
+ let onPressStart = ()=>{
86
+ // no matter how the trigger is pressed, we should close the tooltip
87
+ isFocused.current = false;
88
+ isHovered.current = false;
89
+ handleHide(true);
90
+ };
91
+ let onFocus = ()=>{
92
+ let isVisible = $f5fb1$isFocusVisible();
93
+ if (isVisible) {
94
+ isFocused.current = true;
95
+ handleShow();
96
+ }
97
+ };
98
+ let onBlur = ()=>{
99
+ isFocused.current = false;
100
+ isHovered.current = false;
101
+ handleHide(true);
102
+ };
103
+ let { hoverProps: hoverProps } = $f5fb1$useHover({
104
+ isDisabled: isDisabled,
105
+ onHoverStart: onHoverStart,
106
+ onHoverEnd: onHoverEnd
107
+ });
108
+ let { pressProps: pressProps } = $f5fb1$usePress({
109
+ onPressStart: onPressStart
110
+ });
111
+ let { focusableProps: focusableProps } = $f5fb1$useFocusable({
112
+ isDisabled: isDisabled,
113
+ onFocus: onFocus,
114
+ onBlur: onBlur
115
+ }, ref);
116
+ return {
117
+ triggerProps: {
118
+ 'aria-describedby': state.isOpen ? tooltipId : undefined,
119
+ ...$f5fb1$mergeProps(focusableProps, hoverProps, pressProps)
120
+ },
121
+ tooltipProps: {
122
+ id: tooltipId
53
123
  }
54
- }
55
124
  };
56
-
57
- if (state.isOpen) {
58
- document.addEventListener('keydown', onKeyDown, true);
59
- return () => {
60
- document.removeEventListener('keydown', onKeyDown, true);
61
- };
62
- }
63
- }, [ref, state]);
64
-
65
- let onHoverStart = () => {
66
- if (trigger === 'focus') {
67
- return;
68
- } // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
69
- // interactions for example, hover will end. When hover is restored after that element disappears,
70
- // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
71
- // is the result of moving the mouse.
72
-
73
-
74
- if (getInteractionModality() === 'pointer') {
75
- isHovered.current = true;
76
- } else {
77
- isHovered.current = false;
78
- }
79
-
80
- handleShow();
81
- };
82
-
83
- let onHoverEnd = () => {
84
- if (trigger === 'focus') {
85
- return;
86
- } // no matter how the trigger is left, we should close the tooltip
87
-
88
-
89
- isFocused.current = false;
90
- isHovered.current = false;
91
- handleHide();
92
- };
93
-
94
- let onPressStart = () => {
95
- // no matter how the trigger is pressed, we should close the tooltip
96
- isFocused.current = false;
97
- isHovered.current = false;
98
- handleHide();
99
- };
100
-
101
- let onFocus = () => {
102
- let isVisible = isFocusVisible();
103
-
104
- if (isVisible) {
105
- isFocused.current = true;
106
- handleShow();
107
- }
108
- };
109
-
110
- let onBlur = () => {
111
- isFocused.current = false;
112
- isHovered.current = false;
113
- handleHide();
114
- };
115
-
116
- let {
117
- hoverProps
118
- } = useHover({
119
- isDisabled,
120
- onHoverStart,
121
- onHoverEnd
122
- });
123
- let {
124
- pressProps
125
- } = usePress({
126
- onPressStart
127
- });
128
- let {
129
- focusableProps
130
- } = useFocusable({
131
- isDisabled,
132
- onFocus,
133
- onBlur
134
- }, ref);
135
- return {
136
- triggerProps: _babelRuntimeHelpersEsmExtends({
137
- 'aria-describedby': state.isOpen ? tooltipId : undefined
138
- }, mergeProps(focusableProps, hoverProps, pressProps)),
139
- tooltipProps: {
140
- id: tooltipId
141
- }
142
- };
143
125
  }
126
+
127
+
128
+
129
+
130
+ export {$a3378f049123a239$export$1c4b08e0eca38426 as useTooltip, $c2d8fb326b9f06da$export$a6da6c504e4bba8b as useTooltipTrigger};
144
131
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAuBA;;;OAGO,SAASA,UAAT,CAAoBC,KAApB,EAA0D;AAC/D,MAAIC,QAAQ,GAAGC,cAAc,CAACF,KAAD,EAAQ;AAACG,IAAAA,SAAS,EAAE;AAAZ,GAAR,CAA7B;AAEA,SAAO;AACLC,IAAAA,YAAY,EAAEC,UAAU,CAACJ,QAAD,EAAW;AACjCK,MAAAA,IAAI,EAAE;AAD2B,KAAX;AADnB,GAAP;AAKD;;ACDD;;;;OAIO,SAASC,iBAAT,CAA2BP,KAA3B,EAAuDQ,KAAvD,EAAmFC,GAAnF,EAAqI;AAC1I,MAAI;AACFC,IAAAA,UADE;AAEFC,IAAAA;AAFE,MAGAX,KAHJ;AAKA,MAAIY,SAAS,GAAGC,KAAK,EAArB;AAEA,MAAIC,SAAS,GAAGC,MAAM,CAAC,KAAD,CAAtB;AACA,MAAIC,SAAS,GAAGD,MAAM,CAAC,KAAD,CAAtB;;AAEA,MAAIE,UAAU,GAAG,MAAM;AACrB,QAAIH,SAAS,CAACI,OAAV,IAAqBF,SAAS,CAACE,OAAnC,EAA4C;AAC1CV,MAAAA,KAA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B;AACAE,IAAAA,UAAU;AACX,GARD;;AAUA,MAAIa,YAAY,GAAG,MAAM;AACvB;AACAjB,IAAAA,SAAS,CAACE,OAAV,GAAoB,KAApB;AACAJ,IAAAA,SAAS,CAACI,OAAV,GAAoB,KAApB;AACAE,IAAAA,UAAU;AACX,GALD;;AAOA,MAAIc,OAAO,GAAG,MAAM;AAClB,QAAIC,SAAS,GAAGC,cAAc,EAA9B;;AACA,QAAID,SAAJ,EAAe;AACbnB,MAAAA,SAAS,CAACE,OAAV,GAAoB,IAApB;AACAD,MAAAA,UAAU;AACX;AACF,GAND;;AAQA,MAAIoB,MAAM,GAAG,MAAM;AACjBrB,IAAAA,SAAS,CAACE,OAAV,GAAoB,KAApB;AACAJ,IAAAA,SAAS,CAACI,OAAV,GAAoB,KAApB;AACAE,IAAAA,UAAU;AACX,GAJD;;AAMA,MAAI;AAACkB,IAAAA;AAAD,MAAeC,QAAQ,CAAC;AAC1B7B,IAAAA,UAD0B;AAE1BoB,IAAAA,YAF0B;AAG1BE,IAAAA;AAH0B,GAAD,CAA3B;AAMA,MAAI;AAACQ,IAAAA;AAAD,MAAeC,QAAQ,CAAC;AAACR,IAAAA;AAAD,GAAD,CAA3B;AAEA,MAAI;AAACS,IAAAA;AAAD,MAAmBC,YAAY,CAAC;AAClCjC,IAAAA,UADkC;AAElCwB,IAAAA,OAFkC;AAGlCG,IAAAA;AAHkC,GAAD,EAIhC5B,GAJgC,CAAnC;AAMA,SAAO;AACLmC,IAAAA,YAAY;AACV,0BAAoBpC,KAAK,CAACkB,MAAN,GAAed,SAAf,GAA2BiC;AADrC,OAEPxC,UAAU,CAACqC,cAAD,EAAiBJ,UAAjB,EAA6BE,UAA7B,CAFH,CADP;AAKLpC,IAAAA,YAAY,EAAE;AACZ0C,MAAAA,EAAE,EAAElC;AADQ;AALT,GAAP;AASD","sources":["./packages/@react-aria/tooltip/src/useTooltip.ts","./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 {AriaTooltipProps} from '@react-types/tooltip';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes} from 'react';\n\ninterface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the accessibility implementation for a Tooltip component.\n */\nexport function useTooltip(props: AriaTooltipProps): TooltipAria {\n let domProps = filterDOMProps(props, {labelable: true});\n\n return {\n tooltipProps: mergeProps(domProps, {\n role: 'tooltip'\n })\n };\n}\n","/*\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 {FocusEvents} from '@react-types/shared';\nimport {getInteractionModality, HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';\nimport {HTMLAttributes, RefObject, useEffect, useRef} from 'react';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useFocusable} from '@react-aria/focus';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: HTMLAttributes<HTMLElement> & PressProps & HoverProps & FocusEvents,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\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<HTMLElement>) : 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 = () => {\n if (!isHovered.current && !isFocused.current) {\n state.close();\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 state.close();\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();\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();\n };\n\n let {hoverProps} = useHover({\n isDisabled,\n onHoverStart,\n onHoverEnd\n });\n\n let {pressProps} = usePress({onPressStart});\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, pressProps)\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":["useTooltip","props","domProps","filterDOMProps","labelable","tooltipProps","mergeProps","role","useTooltipTrigger","state","ref","isDisabled","trigger","tooltipId","useId","isHovered","useRef","isFocused","handleShow","current","open","handleHide","close","useEffect","onKeyDown","e","key","isOpen","document","addEventListener","removeEventListener","onHoverStart","getInteractionModality","onHoverEnd","onPressStart","onFocus","isVisible","isFocusVisible","onBlur","hoverProps","useHover","pressProps","usePress","focusableProps","useFocusable","triggerProps","undefined","id"],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;SC4BgB,yCAAU,CAAC,KAAuB,EAAE,KAA2B,EAAe,CAAC;IAC7F,GAAG,CAAC,QAAQ,GAAG,qBAAc,CAAC,KAAK,EAAE,CAAC;QAAA,SAAS,EAAE,IAAI;IAAA,CAAC;IAEtD,GAAG,CAAC,CAAC,aAAA,UAAU,EAAA,CAAC,GAAG,eAAQ,CAAC,CAAC;QAC3B,YAAY,MAAQ,KAAK,EAAE,IAAI,CAAC,IAAI;;QACpC,UAAU,MAAQ,KAAK,EAAE,KAAK;IAChC,CAAC;IAED,MAAM,CAAC,CAAC;QACN,YAAY,EAAE,iBAAU,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC;YAC9C,IAAI,EAAE,CAAS;QACjB,CAAC;IACH,CAAC;AACH,CAAC;;;;;;;;;;;SCJe,yCAAiB,CAAC,KAA0B,EAAE,KAA0B,EAAE,GAA2B,EAAuB,CAAC;IAC3I,GAAG,CAAC,CAAC,aACH,UAAU,YACV,OAAO,EACT,CAAC,GAAG,KAAK;IAET,GAAG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,CAAkB,mBAAE,KAAK,CAAC,MAAM,GAAG,SAAS,GAAG,SAAS;eACrD,iBAAU,CAAC,cAAc,EAAE,UAAU,EAAE,UAAU;QACtD,CAAC;QACD,YAAY,EAAE,CAAC;YACb,EAAE,EAAE,SAAS;QACf,CAAC;IACH,CAAC;AACH,CAAC;;","sources":["packages/@react-aria/tooltip/src/index.ts","packages/@react-aria/tooltip/src/useTooltip.ts","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\nexport * from './useTooltip';\nexport * from './useTooltipTrigger';\n","/*\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 {AriaTooltipProps} from '@react-types/tooltip';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {HTMLAttributes} from 'react';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the accessibility implementation for a Tooltip component.\n */\nexport function useTooltip(props: AriaTooltipProps, state?: TooltipTriggerState): TooltipAria {\n let domProps = filterDOMProps(props, {labelable: true});\n\n let {hoverProps} = useHover({\n onHoverStart: () => state?.open(true),\n onHoverEnd: () => state?.close()\n });\n\n return {\n tooltipProps: mergeProps(domProps, hoverProps, {\n role: 'tooltip'\n })\n };\n}\n","/*\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 {FocusEvents} from '@react-types/shared';\nimport {getInteractionModality, HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';\nimport {HTMLAttributes, RefObject, useEffect, useRef} from 'react';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {TooltipTriggerProps} from '@react-types/tooltip';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useFocusable} from '@react-aria/focus';\nimport {useHover} from '@react-aria/interactions';\n\ninterface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: HTMLAttributes<HTMLElement> & PressProps & HoverProps & FocusEvents,\n\n /**\n * Props for the overlay container element.\n */\n tooltipProps: HTMLAttributes<HTMLElement>\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<HTMLElement>) : 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 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 {pressProps} = usePress({onPressStart});\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, pressProps)\n },\n tooltipProps: {\n id: tooltipId\n }\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { AriaTooltipProps, TooltipTriggerProps } from "@react-types/tooltip";
2
2
  import { HTMLAttributes, RefObject } from "react";
3
+ import { TooltipTriggerState } from "@react-stately/tooltip";
3
4
  import { FocusEvents } from "@react-types/shared";
4
5
  import { HoverProps, PressProps } from "@react-aria/interactions";
5
- import { TooltipTriggerState } from "@react-stately/tooltip";
6
6
  interface TooltipAria {
7
7
  /**
8
8
  * Props for the tooltip element.
@@ -12,7 +12,7 @@ interface TooltipAria {
12
12
  /**
13
13
  * Provides the accessibility implementation for a Tooltip component.
14
14
  */
15
- export function useTooltip(props: AriaTooltipProps): TooltipAria;
15
+ export function useTooltip(props: AriaTooltipProps, state?: TooltipTriggerState): TooltipAria;
16
16
  interface TooltipTriggerAria {
17
17
  /**
18
18
  * Props for the trigger element.
@@ -1 +1 @@
1
- {"mappings":"A;A;A;A;A;AAgBA;IACE;A;OAEG;IACH,YAAY,EAAE,eAAe,WAAW,CAAC,CAAA;CAC1C;AAED;A;GAEG;AACH,2BAA2B,KAAK,EAAE,gBAAgB,GAAG,WAAW,CAQ/D;ACbD;IACE;A;OAEG;IACH,YAAY,EAAE,eAAe,WAAW,CAAC,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;IAElF;A;OAEG;IACH,YAAY,EAAE,eAAe,WAAW,CAAC,CAAA;CAC1C;AAED;A;A;GAGG;AACH,kCAAkC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,mBAAmB,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAI,kBAAkB,CA+G1I","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"],"sourcesContent":[null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;;;AAkBA;IACE;;OAEG;IACH,YAAY,EAAE,eAAe,WAAW,CAAC,CAAA;CAC1C;AAED;;GAEG;AACH,2BAA2B,KAAK,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,mBAAmB,GAAG,WAAW,CAa5F;ACpBD;IACE;;OAEG;IACH,YAAY,EAAE,eAAe,WAAW,CAAC,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;IAElF;;OAEG;IACH,YAAY,EAAE,eAAe,WAAW,CAAC,CAAA;CAC1C;AAED;;;GAGG;AACH,kCAAkC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,mBAAmB,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAI,kBAAkB,CA+G1I","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 */\n\nexport * from './useTooltip';\nexport * from './useTooltipTrigger';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/tooltip",
3
- "version": "3.1.0",
3
+ "version": "3.1.4",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -18,13 +18,12 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.6.2",
21
- "@react-aria/focus": "^3.2.3",
22
- "@react-aria/interactions": "^3.3.2",
23
- "@react-aria/overlays": "^3.6.0",
24
- "@react-aria/utils": "^3.4.1",
25
- "@react-stately/tooltip": "^3.0.1",
26
- "@react-types/shared": "^3.3.0",
27
- "@react-types/tooltip": "^3.1.0"
21
+ "@react-aria/focus": "^3.5.1",
22
+ "@react-aria/interactions": "^3.8.0",
23
+ "@react-aria/utils": "^3.11.1",
24
+ "@react-stately/tooltip": "^3.0.6",
25
+ "@react-types/shared": "^3.11.0",
26
+ "@react-types/tooltip": "^3.1.3"
28
27
  },
29
28
  "peerDependencies": {
30
29
  "react": "^16.8.0 || ^17.0.0-rc.1"
@@ -32,5 +31,5 @@
32
31
  "publishConfig": {
33
32
  "access": "public"
34
33
  },
35
- "gitHead": "f5b429ee8615248f2e3c76754bad2ece83f1c444"
34
+ "gitHead": "54c2366c4f31bd4bf619126131cd583c12972acc"
36
35
  }
package/src/useTooltip.ts CHANGED
@@ -13,6 +13,8 @@
13
13
  import {AriaTooltipProps} from '@react-types/tooltip';
14
14
  import {filterDOMProps, mergeProps} from '@react-aria/utils';
15
15
  import {HTMLAttributes} from 'react';
16
+ import {TooltipTriggerState} from '@react-stately/tooltip';
17
+ import {useHover} from '@react-aria/interactions';
16
18
 
17
19
  interface TooltipAria {
18
20
  /**
@@ -24,11 +26,16 @@ interface TooltipAria {
24
26
  /**
25
27
  * Provides the accessibility implementation for a Tooltip component.
26
28
  */
27
- export function useTooltip(props: AriaTooltipProps): TooltipAria {
29
+ export function useTooltip(props: AriaTooltipProps, state?: TooltipTriggerState): TooltipAria {
28
30
  let domProps = filterDOMProps(props, {labelable: true});
29
31
 
32
+ let {hoverProps} = useHover({
33
+ onHoverStart: () => state?.open(true),
34
+ onHoverEnd: () => state?.close()
35
+ });
36
+
30
37
  return {
31
- tooltipProps: mergeProps(domProps, {
38
+ tooltipProps: mergeProps(domProps, hoverProps, {
32
39
  role: 'tooltip'
33
40
  })
34
41
  };
@@ -52,9 +52,9 @@ export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTrig
52
52
  }
53
53
  };
54
54
 
55
- let handleHide = () => {
55
+ let handleHide = (immediate?: boolean) => {
56
56
  if (!isHovered.current && !isFocused.current) {
57
- state.close();
57
+ state.close(immediate);
58
58
  }
59
59
  };
60
60
 
@@ -64,7 +64,7 @@ export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTrig
64
64
  // Escape after clicking something can give it keyboard focus
65
65
  // dismiss tooltip on esc key press
66
66
  if (e.key === 'Escape') {
67
- state.close();
67
+ state.close(true);
68
68
  }
69
69
  }
70
70
  };
@@ -106,7 +106,7 @@ export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTrig
106
106
  // no matter how the trigger is pressed, we should close the tooltip
107
107
  isFocused.current = false;
108
108
  isHovered.current = false;
109
- handleHide();
109
+ handleHide(true);
110
110
  };
111
111
 
112
112
  let onFocus = () => {
@@ -120,7 +120,7 @@ export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTrig
120
120
  let onBlur = () => {
121
121
  isFocused.current = false;
122
122
  isHovered.current = false;
123
- handleHide();
123
+ handleHide(true);
124
124
  };
125
125
 
126
126
  let {hoverProps} = useHover({