@react-aria/tooltip 3.3.4 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,158 @@
1
+ import {filterDOMProps as $kgVYN$filterDOMProps, mergeProps as $kgVYN$mergeProps, useId as $kgVYN$useId} from "@react-aria/utils";
2
+ import {useHover as $kgVYN$useHover, getInteractionModality as $kgVYN$getInteractionModality, isFocusVisible as $kgVYN$isFocusVisible, usePress as $kgVYN$usePress} from "@react-aria/interactions";
3
+ import {useRef as $kgVYN$useRef, useEffect as $kgVYN$useEffect} from "react";
4
+ import {useFocusable as $kgVYN$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
+ * Copyright 2020 Adobe. All rights reserved.
18
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
19
+ * you may not use this file except in compliance with the License. You may obtain a copy
20
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
21
+ *
22
+ * Unless required by applicable law or agreed to in writing, software distributed under
23
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
24
+ * OF ANY KIND, either express or implied. See the License for the specific language
25
+ * governing permissions and limitations under the License.
26
+ */
27
+
28
+ function $326e436e94273fe1$export$1c4b08e0eca38426(props, state) {
29
+ let domProps = (0, $kgVYN$filterDOMProps)(props, {
30
+ labelable: true
31
+ });
32
+ let { hoverProps: hoverProps } = (0, $kgVYN$useHover)({
33
+ onHoverStart: ()=>{
34
+ return state === null || state === void 0 ? void 0 : state.open(true);
35
+ },
36
+ onHoverEnd: ()=>{
37
+ return state === null || state === void 0 ? void 0 : state.close();
38
+ }
39
+ });
40
+ return {
41
+ tooltipProps: (0, $kgVYN$mergeProps)(domProps, hoverProps, {
42
+ role: "tooltip"
43
+ })
44
+ };
45
+ }
46
+
47
+
48
+ /*
49
+ * Copyright 2020 Adobe. All rights reserved.
50
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
51
+ * you may not use this file except in compliance with the License. You may obtain a copy
52
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
53
+ *
54
+ * Unless required by applicable law or agreed to in writing, software distributed under
55
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
56
+ * OF ANY KIND, either express or implied. See the License for the specific language
57
+ * governing permissions and limitations under the License.
58
+ */
59
+
60
+
61
+
62
+
63
+ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
64
+ let { isDisabled: isDisabled , trigger: trigger } = props;
65
+ let tooltipId = (0, $kgVYN$useId)();
66
+ let isHovered = (0, $kgVYN$useRef)(false);
67
+ let isFocused = (0, $kgVYN$useRef)(false);
68
+ let handleShow = ()=>{
69
+ if (isHovered.current || isFocused.current) state.open(isFocused.current);
70
+ };
71
+ let handleHide = (immediate)=>{
72
+ if (!isHovered.current && !isFocused.current) state.close(immediate);
73
+ };
74
+ (0, $kgVYN$useEffect)(()=>{
75
+ let onKeyDown = (e)=>{
76
+ if (ref && ref.current) // Escape after clicking something can give it keyboard focus
77
+ // dismiss tooltip on esc key press
78
+ {
79
+ if (e.key === "Escape") {
80
+ e.stopPropagation();
81
+ state.close(true);
82
+ }
83
+ }
84
+ };
85
+ if (state.isOpen) {
86
+ document.addEventListener("keydown", onKeyDown, true);
87
+ return ()=>{
88
+ document.removeEventListener("keydown", onKeyDown, true);
89
+ };
90
+ }
91
+ }, [
92
+ ref,
93
+ state
94
+ ]);
95
+ let onHoverStart = ()=>{
96
+ if (trigger === "focus") return;
97
+ // In chrome, if you hover a trigger, then another element obscures it, due to keyboard
98
+ // interactions for example, hover will end. When hover is restored after that element disappears,
99
+ // focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
100
+ // is the result of moving the mouse.
101
+ if ((0, $kgVYN$getInteractionModality)() === "pointer") isHovered.current = true;
102
+ else isHovered.current = false;
103
+ handleShow();
104
+ };
105
+ let onHoverEnd = ()=>{
106
+ if (trigger === "focus") return;
107
+ // no matter how the trigger is left, we should close the tooltip
108
+ isFocused.current = false;
109
+ isHovered.current = false;
110
+ handleHide();
111
+ };
112
+ let onPressStart = ()=>{
113
+ // no matter how the trigger is pressed, we should close the tooltip
114
+ isFocused.current = false;
115
+ isHovered.current = false;
116
+ handleHide(true);
117
+ };
118
+ let onFocus = ()=>{
119
+ let isVisible = (0, $kgVYN$isFocusVisible)();
120
+ if (isVisible) {
121
+ isFocused.current = true;
122
+ handleShow();
123
+ }
124
+ };
125
+ let onBlur = ()=>{
126
+ isFocused.current = false;
127
+ isHovered.current = false;
128
+ handleHide(true);
129
+ };
130
+ let { hoverProps: hoverProps } = (0, $kgVYN$useHover)({
131
+ isDisabled: isDisabled,
132
+ onHoverStart: onHoverStart,
133
+ onHoverEnd: onHoverEnd
134
+ });
135
+ let { pressProps: pressProps } = (0, $kgVYN$usePress)({
136
+ onPressStart: onPressStart
137
+ });
138
+ let { focusableProps: focusableProps } = (0, $kgVYN$useFocusable)({
139
+ isDisabled: isDisabled,
140
+ onFocus: onFocus,
141
+ onBlur: onBlur
142
+ }, ref);
143
+ return {
144
+ triggerProps: {
145
+ "aria-describedby": state.isOpen ? tooltipId : undefined,
146
+ ...(0, $kgVYN$mergeProps)(focusableProps, hoverProps, pressProps)
147
+ },
148
+ tooltipProps: {
149
+ id: tooltipId
150
+ }
151
+ };
152
+ }
153
+
154
+
155
+
156
+
157
+ export {$326e436e94273fe1$export$1c4b08e0eca38426 as useTooltip, $4e1b34546679e357$export$a6da6c504e4bba8b as useTooltipTrigger};
158
+ //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -82,7 +82,10 @@ function $f017bbc46d58d42a$export$a6da6c504e4bba8b(props, state, ref) {
82
82
  if (ref && ref.current) // Escape after clicking something can give it keyboard focus
83
83
  // dismiss tooltip on esc key press
84
84
  {
85
- if (e.key === "Escape") state.close(true);
85
+ if (e.key === "Escape") {
86
+ e.stopPropagation();
87
+ state.close(true);
88
+ }
86
89
  }
87
90
  };
88
91
  if (state.isOpen) {
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;AAgBO,SAAS,0CAAW,KAAuB,EAAE,KAA2B,EAAe;IAC5F,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW,IAAI;IAAA;IAErD,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,qCAAQ,AAAD,EAAE;QAC1B,cAAc;YAAM,OAAA,kBAAA,mBAAA,KAAA,IAAA,MAAO,IAAI,CAAC,IAAI;;QACpC,YAAY;YAAM,OAAA,kBAAA,mBAAA,KAAA,IAAA,MAAO,KAAK;;IAChC;IAEA,OAAO;QACL,cAAc,CAAA,GAAA,gCAAU,AAAD,EAAE,UAAU,YAAY;YAC7C,MAAM;QACR;IACF;AACF;;CD/BC,GACD;AEXA;;;;;;;;;;CAUC,GAED;;;;;AAyBO,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAgC,EAAuB;IAC/I,IAAI,cACF,WAAU,WACV,QAAO,EACR,GAAG;IAEJ,IAAI,YAAY,CAAA,GAAA,2BAAK,AAAD;IAEpB,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE,KAAK;IAC5B,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE,KAAK;IAE5B,IAAI,aAAa,IAAM;QACrB,IAAI,UAAU,OAAO,IAAI,UAAU,OAAO,EACxC,MAAM,I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,KAAK;QACzB,WAAW,IAAI;IACjB;IAEA,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,qCAAQ,AAAD,EAAE;oBAC1B;sBACA;oBACA;IACF;IAEA,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,qCAAQ,AAAD,EAAE;sBAAC;IAAY;IAEzC,IAAI,kBAAC,eAAc,EAAC,GAAG,CAAA,GAAA,kCAAY,AAAD,EAAE;oBAClC;iBACA;gBACA;IACF,GAAG;IAEH,OAAO;QACL,cAAc;YACZ,oBAAoB,MAAM,MAAM,GAAG,YAAY,SAAS;YACxD,GAAG,CAAA,GAAA,gCAAS,EAAE,gBAAgB,YAAY,WAAW;QACvD;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF;","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 */\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","/*\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 {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\nexport interface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: DOMAttributes\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 {DOMAttributes, FocusableElement, FocusEvents} from '@react-types/shared';\nimport {getInteractionModality, HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {RefObject, useEffect, useRef} from 'react';\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\nexport interface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: DOMAttributes & PressProps & HoverProps & FocusEvents,\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>) : 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"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;AAgBO,SAAS,0CAAW,KAAuB,EAAE,KAA2B,EAAe;IAC5F,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW,IAAI;IAAA;IAErD,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,qCAAQ,AAAD,EAAE;QAC1B,cAAc;YAAM,OAAA,kBAAA,mBAAA,KAAA,IAAA,MAAO,IAAI,CAAC,IAAI;;QACpC,YAAY;YAAM,OAAA,kBAAA,mBAAA,KAAA,IAAA,MAAO,KAAK;;IAChC;IAEA,OAAO;QACL,cAAc,CAAA,GAAA,gCAAU,AAAD,EAAE,UAAU,YAAY;YAC7C,MAAM;QACR;IACF;AACF;;CD/BC,GACD;AEXA;;;;;;;;;;CAUC,GAED;;;;;AAyBO,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAgC,EAAuB;IAC/I,IAAI,cACF,WAAU,WACV,QAAO,EACR,GAAG;IAEJ,IAAI,YAAY,CAAA,GAAA,2BAAK,AAAD;IAEpB,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE,KAAK;IAC5B,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE,KAAK;IAE5B,IAAI,aAAa,IAAM;QACrB,IAAI,UAAU,OAAO,IAAI,UAAU,OAAO,EACxC,MAAM,IAAI,CAAC,UAAU,OAAO;IAEhC;IAEA,IAAI,aAAa,CAAC,YAAwB;QACxC,IAAI,CAAC,UAAU,OAAO,IAAI,C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C,GAAG,CAAA,GAAA,qCAAQ,AAAD,EAAE;oBAC1B;sBACA;oBACA;IACF;IAEA,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,qCAAQ,AAAD,EAAE;sBAAC;IAAY;IAEzC,IAAI,kBAAC,eAAc,EAAC,GAAG,CAAA,GAAA,kCAAY,AAAD,EAAE;oBAClC;iBACA;gBACA;IACF,GAAG;IAEH,OAAO;QACL,cAAc;YACZ,oBAAoB,MAAM,MAAM,GAAG,YAAY,SAAS;YACxD,GAAG,CAAA,GAAA,gCAAS,EAAE,gBAAgB,YAAY,WAAW;QACvD;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF;","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 */\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","/*\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 {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\nexport interface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: DOMAttributes\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 {DOMAttributes, FocusableElement, FocusEvents} from '@react-types/shared';\nimport {getInteractionModality, HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {RefObject, useEffect, useRef} from 'react';\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\nexport interface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: DOMAttributes & PressProps & HoverProps & FocusEvents,\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>) : 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 {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
@@ -76,7 +76,10 @@ function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
76
76
  if (ref && ref.current) // Escape after clicking something can give it keyboard focus
77
77
  // dismiss tooltip on esc key press
78
78
  {
79
- if (e.key === "Escape") state.close(true);
79
+ if (e.key === "Escape") {
80
+ e.stopPropagation();
81
+ state.close(true);
82
+ }
80
83
  }
81
84
  };
82
85
  if (state.isOpen) {
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;AAgBO,SAAS,0CAAW,KAAuB,EAAE,KAA2B,EAAe;IAC5F,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW,IAAI;IAAA;IAErD,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,eAAQ,AAAD,EAAE;QAC1B,cAAc;YAAM,OAAA,kBAAA,mBAAA,KAAA,IAAA,MAAO,IAAI,CAAC,IAAI;;QACpC,YAAY;YAAM,OAAA,kBAAA,mBAAA,KAAA,IAAA,MAAO,KAAK;;IAChC;IAEA,OAAO;QACL,cAAc,CAAA,GAAA,iBAAU,AAAD,EAAE,UAAU,YAAY;YAC7C,MAAM;QACR;IACF;AACF;;CD/BC,GACD;AEXA;;;;;;;;;;CAUC,GAED;;;;;AAyBO,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAgC,EAAuB;IAC/I,IAAI,cACF,WAAU,WACV,QAAO,EACR,GAAG;IAEJ,IAAI,YAAY,CAAA,GAAA,YAAK,AAAD;IAEpB,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE,KAAK;I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;YACb,UAAU,OAAO,GAAG,IAAI;YACxB;QACF,CAAC;IACH;IAEA,IAAI,SAAS,IAAM;QACjB,UAAU,OAAO,GAAG,KAAK;QACzB,UAAU,OAAO,GAAG,KAAK;QACzB,WAAW,IAAI;IACjB;IAEA,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,eAAQ,AAAD,EAAE;oBAC1B;sBACA;oBACA;IACF;IAEA,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,eAAQ,AAAD,EAAE;sBAAC;IAAY;IAEzC,IAAI,kBAAC,eAAc,EAAC,GAAG,CAAA,GAAA,mBAAY,AAAD,EAAE;oBAClC;iBACA;gBACA;IACF,GAAG;IAEH,OAAO;QACL,cAAc;YACZ,oBAAoB,MAAM,MAAM,GAAG,YAAY,SAAS;YACxD,GAAG,CAAA,GAAA,iBAAS,EAAE,gBAAgB,YAAY,WAAW;QACvD;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF;","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 */\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","/*\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 {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\nexport interface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: DOMAttributes\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 {DOMAttributes, FocusableElement, FocusEvents} from '@react-types/shared';\nimport {getInteractionModality, HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {RefObject, useEffect, useRef} from 'react';\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\nexport interface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: DOMAttributes & PressProps & HoverProps & FocusEvents,\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>) : 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"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;AAgBO,SAAS,0CAAW,KAAuB,EAAE,KAA2B,EAAe;IAC5F,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW,IAAI;IAAA;IAErD,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,eAAQ,AAAD,EAAE;QAC1B,cAAc;YAAM,OAAA,kBAAA,mBAAA,KAAA,IAAA,MAAO,IAAI,CAAC,IAAI;;QACpC,YAAY;YAAM,OAAA,kBAAA,mBAAA,KAAA,IAAA,MAAO,KAAK;;IAChC;IAEA,OAAO;QACL,cAAc,CAAA,GAAA,iBAAU,AAAD,EAAE,UAAU,YAAY;YAC7C,MAAM;QACR;IACF;AACF;;CD/BC,GACD;AEXA;;;;;;;;;;CAUC,GAED;;;;;AAyBO,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAgC,EAAuB;IAC/I,IAAI,cACF,WAAU,WACV,QAAO,EACR,GAAG;IAEJ,IAAI,YAAY,CAAA,GAAA,YAAK,AAAD;IAEpB,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE,KAAK;IAC5B,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE,KAAK;IAE5B,IAAI,aAAa,IAAM;QACrB,IAAI,UAAU,OAAO,IAAI,UAAU,OAA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M;QACjB,UAAU,OAAO,GAAG,KAAK;QACzB,UAAU,OAAO,GAAG,KAAK;QACzB,WAAW,IAAI;IACjB;IAEA,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,eAAQ,AAAD,EAAE;oBAC1B;sBACA;oBACA;IACF;IAEA,IAAI,cAAC,WAAU,EAAC,GAAG,CAAA,GAAA,eAAQ,AAAD,EAAE;sBAAC;IAAY;IAEzC,IAAI,kBAAC,eAAc,EAAC,GAAG,CAAA,GAAA,mBAAY,AAAD,EAAE;oBAClC;iBACA;gBACA;IACF,GAAG;IAEH,OAAO;QACL,cAAc;YACZ,oBAAoB,MAAM,MAAM,GAAG,YAAY,SAAS;YACxD,GAAG,CAAA,GAAA,iBAAS,EAAE,gBAAgB,YAAY,WAAW;QACvD;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF;","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 */\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","/*\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 {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {TooltipTriggerState} from '@react-stately/tooltip';\nimport {useHover} from '@react-aria/interactions';\n\nexport interface TooltipAria {\n /**\n * Props for the tooltip element.\n */\n tooltipProps: DOMAttributes\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 {DOMAttributes, FocusableElement, FocusEvents} from '@react-types/shared';\nimport {getInteractionModality, HoverProps, isFocusVisible, PressProps, usePress} from '@react-aria/interactions';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {RefObject, useEffect, useRef} from 'react';\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\nexport interface TooltipTriggerAria {\n /**\n * Props for the trigger element.\n */\n triggerProps: DOMAttributes & PressProps & HoverProps & FocusEvents,\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>) : 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 {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"}
@@ -1 +1 @@
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;ACpBD;IACE;;OAEG;IACH,YAAY,EAAE,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;IAEpE;;OAEG;IACH,YAAY,EAAE,aAAa,CAAA;CAC5B;AAED;;;GAGG;AACH,kCAAkC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,mBAAmB,EAAE,GAAG,EAAE,UAAU,gBAAgB,CAAC,GAAI,kBAAkB,CA+G/I;ACvID,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"}
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;ACpBD;IACE;;OAEG;IACH,YAAY,EAAE,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;IAEpE;;OAEG;IACH,YAAY,EAAE,aAAa,CAAA;CAC5B;AAED;;;GAGG;AACH,kCAAkC,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,mBAAmB,EAAE,GAAG,EAAE,UAAU,gBAAgB,CAAC,GAAI,kBAAkB,CAgH/I;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/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "@react-aria/tooltip",
3
- "version": "3.3.4",
3
+ "version": "3.5.0",
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,12 +22,12 @@
17
22
  "url": "https://github.com/adobe/react-spectrum"
18
23
  },
19
24
  "dependencies": {
20
- "@react-aria/focus": "^3.10.1",
21
- "@react-aria/interactions": "^3.13.1",
22
- "@react-aria/utils": "^3.14.2",
23
- "@react-stately/tooltip": "^3.2.4",
24
- "@react-types/shared": "^3.16.0",
25
- "@react-types/tooltip": "^3.2.5",
25
+ "@react-aria/focus": "^3.12.0",
26
+ "@react-aria/interactions": "^3.15.0",
27
+ "@react-aria/utils": "^3.16.0",
28
+ "@react-stately/tooltip": "^3.4.0",
29
+ "@react-types/shared": "^3.18.0",
30
+ "@react-types/tooltip": "^3.4.0",
26
31
  "@swc/helpers": "^0.4.14"
27
32
  },
28
33
  "peerDependencies": {
@@ -31,5 +36,5 @@
31
36
  "publishConfig": {
32
37
  "access": "public"
33
38
  },
34
- "gitHead": "5480d76bd815e239366f92852c76b6831ad2a4fd"
39
+ "gitHead": "9d1ba9bd8ebcd63bf3495ade16d349bcb71795ce"
35
40
  }
@@ -64,6 +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
+ e.stopPropagation();
67
68
  state.close(true);
68
69
  }
69
70
  }