@react-aria/tooltip 3.1.4 → 3.1.7
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 +31 -28
- package/dist/main.js.map +1 -1
- package/dist/module.js +30 -27
- package/dist/module.js.map +1 -1
- package/package.json +8 -8
package/dist/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
3
|
-
var $
|
|
4
|
-
var $
|
|
1
|
+
var $aGFp5$reactariautils = require("@react-aria/utils");
|
|
2
|
+
var $aGFp5$reactariainteractions = require("@react-aria/interactions");
|
|
3
|
+
var $aGFp5$react = require("react");
|
|
4
|
+
var $aGFp5$reactariafocus = require("@react-aria/focus");
|
|
5
5
|
|
|
6
6
|
function $parcel$exportWildcard(dest, source) {
|
|
7
7
|
Object.keys(source).forEach(function(key) {
|
|
@@ -22,48 +22,51 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
22
22
|
function $parcel$export(e, n, v, s) {
|
|
23
23
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
24
24
|
}
|
|
25
|
-
var $
|
|
25
|
+
var $199fa2aaa84f20b7$exports = {};
|
|
26
26
|
|
|
27
|
-
$parcel$export($
|
|
27
|
+
$parcel$export($199fa2aaa84f20b7$exports, "useTooltip", () => $199fa2aaa84f20b7$export$1c4b08e0eca38426);
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
function $
|
|
31
|
-
let domProps = $
|
|
30
|
+
function $199fa2aaa84f20b7$export$1c4b08e0eca38426(props, state) {
|
|
31
|
+
let domProps = $aGFp5$reactariautils.filterDOMProps(props, {
|
|
32
32
|
labelable: true
|
|
33
33
|
});
|
|
34
|
-
let { hoverProps: hoverProps } = $
|
|
35
|
-
onHoverStart: ()=>
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
let { hoverProps: hoverProps } = $aGFp5$reactariainteractions.useHover({
|
|
35
|
+
onHoverStart: ()=>{
|
|
36
|
+
return state === null || state === void 0 ? void 0 : state.open(true);
|
|
37
|
+
},
|
|
38
|
+
onHoverEnd: ()=>{
|
|
39
|
+
return state === null || state === void 0 ? void 0 : state.close();
|
|
40
|
+
}
|
|
38
41
|
});
|
|
39
42
|
return {
|
|
40
|
-
tooltipProps: $
|
|
43
|
+
tooltipProps: $aGFp5$reactariautils.mergeProps(domProps, hoverProps, {
|
|
41
44
|
role: 'tooltip'
|
|
42
45
|
})
|
|
43
46
|
};
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
|
|
47
|
-
var $
|
|
50
|
+
var $f017bbc46d58d42a$exports = {};
|
|
48
51
|
|
|
49
|
-
$parcel$export($
|
|
52
|
+
$parcel$export($f017bbc46d58d42a$exports, "useTooltipTrigger", () => $f017bbc46d58d42a$export$a6da6c504e4bba8b);
|
|
50
53
|
|
|
51
54
|
|
|
52
55
|
|
|
53
56
|
|
|
54
57
|
|
|
55
|
-
function $
|
|
58
|
+
function $f017bbc46d58d42a$export$a6da6c504e4bba8b(props, state, ref) {
|
|
56
59
|
let { isDisabled: isDisabled , trigger: trigger } = props;
|
|
57
|
-
let tooltipId = $
|
|
58
|
-
let isHovered = $
|
|
59
|
-
let isFocused = $
|
|
60
|
+
let tooltipId = $aGFp5$reactariautils.useId();
|
|
61
|
+
let isHovered = $aGFp5$react.useRef(false);
|
|
62
|
+
let isFocused = $aGFp5$react.useRef(false);
|
|
60
63
|
let handleShow = ()=>{
|
|
61
64
|
if (isHovered.current || isFocused.current) state.open(isFocused.current);
|
|
62
65
|
};
|
|
63
66
|
let handleHide = (immediate)=>{
|
|
64
67
|
if (!isHovered.current && !isFocused.current) state.close(immediate);
|
|
65
68
|
};
|
|
66
|
-
$
|
|
69
|
+
$aGFp5$react.useEffect(()=>{
|
|
67
70
|
let onKeyDown = (e)=>{
|
|
68
71
|
if (ref && ref.current) // Escape after clicking something can give it keyboard focus
|
|
69
72
|
// dismiss tooltip on esc key press
|
|
@@ -87,7 +90,7 @@ function $2dec65ceb6e1926a$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
87
90
|
// interactions for example, hover will end. When hover is restored after that element disappears,
|
|
88
91
|
// focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
|
|
89
92
|
// is the result of moving the mouse.
|
|
90
|
-
if ($
|
|
93
|
+
if ($aGFp5$reactariainteractions.getInteractionModality() === 'pointer') isHovered.current = true;
|
|
91
94
|
else isHovered.current = false;
|
|
92
95
|
handleShow();
|
|
93
96
|
};
|
|
@@ -105,7 +108,7 @@ function $2dec65ceb6e1926a$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
105
108
|
handleHide(true);
|
|
106
109
|
};
|
|
107
110
|
let onFocus = ()=>{
|
|
108
|
-
let isVisible = $
|
|
111
|
+
let isVisible = $aGFp5$reactariainteractions.isFocusVisible();
|
|
109
112
|
if (isVisible) {
|
|
110
113
|
isFocused.current = true;
|
|
111
114
|
handleShow();
|
|
@@ -116,15 +119,15 @@ function $2dec65ceb6e1926a$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
116
119
|
isHovered.current = false;
|
|
117
120
|
handleHide(true);
|
|
118
121
|
};
|
|
119
|
-
let { hoverProps: hoverProps } = $
|
|
122
|
+
let { hoverProps: hoverProps } = $aGFp5$reactariainteractions.useHover({
|
|
120
123
|
isDisabled: isDisabled,
|
|
121
124
|
onHoverStart: onHoverStart,
|
|
122
125
|
onHoverEnd: onHoverEnd
|
|
123
126
|
});
|
|
124
|
-
let { pressProps: pressProps } = $
|
|
127
|
+
let { pressProps: pressProps } = $aGFp5$reactariainteractions.usePress({
|
|
125
128
|
onPressStart: onPressStart
|
|
126
129
|
});
|
|
127
|
-
let { focusableProps: focusableProps } = $
|
|
130
|
+
let { focusableProps: focusableProps } = $aGFp5$reactariafocus.useFocusable({
|
|
128
131
|
isDisabled: isDisabled,
|
|
129
132
|
onFocus: onFocus,
|
|
130
133
|
onBlur: onBlur
|
|
@@ -132,7 +135,7 @@ function $2dec65ceb6e1926a$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
132
135
|
return {
|
|
133
136
|
triggerProps: {
|
|
134
137
|
'aria-describedby': state.isOpen ? tooltipId : undefined,
|
|
135
|
-
...$
|
|
138
|
+
...$aGFp5$reactariautils.mergeProps(focusableProps, hoverProps, pressProps)
|
|
136
139
|
},
|
|
137
140
|
tooltipProps: {
|
|
138
141
|
id: tooltipId
|
|
@@ -141,8 +144,8 @@ function $2dec65ceb6e1926a$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
141
144
|
}
|
|
142
145
|
|
|
143
146
|
|
|
144
|
-
$parcel$exportWildcard(module.exports, $
|
|
145
|
-
$parcel$exportWildcard(module.exports, $
|
|
147
|
+
$parcel$exportWildcard(module.exports, $199fa2aaa84f20b7$exports);
|
|
148
|
+
$parcel$exportWildcard(module.exports, $f017bbc46d58d42a$exports);
|
|
146
149
|
|
|
147
150
|
|
|
148
151
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;SC4BgB,yCAAU,CAAC,KAAuB,EAAE,KAA2B,EAAe,CAAC;IAC7F,GAAG,CAAC,QAAQ,GAAG,oCAAc,CAAC,KAAK,EAAE,CAAC;QAAA,SAAS,EAAE,IAAI;IAAA,CAAC;IAEtD,GAAG,CAAC,CAAC,aAAA,UAAU,EAAA,CAAC,GAAG,qCAAQ,CAAC,CAAC;QAC3B,YAAY,
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;SC4BgB,yCAAU,CAAC,KAAuB,EAAE,KAA2B,EAAe,CAAC;IAC7F,GAAG,CAAC,QAAQ,GAAG,oCAAc,CAAC,KAAK,EAAE,CAAC;QAAA,SAAS,EAAE,IAAI;IAAA,CAAC;IAEtD,GAAG,CAAC,CAAC,aAAA,UAAU,EAAA,CAAC,GAAG,qCAAQ,CAAC,CAAC;QA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H,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,53 +1,56 @@
|
|
|
1
|
-
import {filterDOMProps as $
|
|
2
|
-
import {useHover as $
|
|
3
|
-
import {useRef as $
|
|
4
|
-
import {useFocusable as $
|
|
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
5
|
|
|
6
6
|
function $parcel$export(e, n, v, s) {
|
|
7
7
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
8
|
}
|
|
9
|
-
var $
|
|
9
|
+
var $326e436e94273fe1$exports = {};
|
|
10
10
|
|
|
11
|
-
$parcel$export($
|
|
11
|
+
$parcel$export($326e436e94273fe1$exports, "useTooltip", () => $326e436e94273fe1$export$1c4b08e0eca38426);
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
function $
|
|
15
|
-
let domProps = $
|
|
14
|
+
function $326e436e94273fe1$export$1c4b08e0eca38426(props, state) {
|
|
15
|
+
let domProps = $kgVYN$filterDOMProps(props, {
|
|
16
16
|
labelable: true
|
|
17
17
|
});
|
|
18
|
-
let { hoverProps: hoverProps } = $
|
|
19
|
-
onHoverStart: ()=>
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
let { hoverProps: hoverProps } = $kgVYN$useHover({
|
|
19
|
+
onHoverStart: ()=>{
|
|
20
|
+
return state === null || state === void 0 ? void 0 : state.open(true);
|
|
21
|
+
},
|
|
22
|
+
onHoverEnd: ()=>{
|
|
23
|
+
return state === null || state === void 0 ? void 0 : state.close();
|
|
24
|
+
}
|
|
22
25
|
});
|
|
23
26
|
return {
|
|
24
|
-
tooltipProps: $
|
|
27
|
+
tooltipProps: $kgVYN$mergeProps(domProps, hoverProps, {
|
|
25
28
|
role: 'tooltip'
|
|
26
29
|
})
|
|
27
30
|
};
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
|
|
31
|
-
var $
|
|
34
|
+
var $4e1b34546679e357$exports = {};
|
|
32
35
|
|
|
33
|
-
$parcel$export($
|
|
36
|
+
$parcel$export($4e1b34546679e357$exports, "useTooltipTrigger", () => $4e1b34546679e357$export$a6da6c504e4bba8b);
|
|
34
37
|
|
|
35
38
|
|
|
36
39
|
|
|
37
40
|
|
|
38
41
|
|
|
39
|
-
function $
|
|
42
|
+
function $4e1b34546679e357$export$a6da6c504e4bba8b(props, state, ref) {
|
|
40
43
|
let { isDisabled: isDisabled , trigger: trigger } = props;
|
|
41
|
-
let tooltipId = $
|
|
42
|
-
let isHovered = $
|
|
43
|
-
let isFocused = $
|
|
44
|
+
let tooltipId = $kgVYN$useId();
|
|
45
|
+
let isHovered = $kgVYN$useRef(false);
|
|
46
|
+
let isFocused = $kgVYN$useRef(false);
|
|
44
47
|
let handleShow = ()=>{
|
|
45
48
|
if (isHovered.current || isFocused.current) state.open(isFocused.current);
|
|
46
49
|
};
|
|
47
50
|
let handleHide = (immediate)=>{
|
|
48
51
|
if (!isHovered.current && !isFocused.current) state.close(immediate);
|
|
49
52
|
};
|
|
50
|
-
$
|
|
53
|
+
$kgVYN$useEffect(()=>{
|
|
51
54
|
let onKeyDown = (e)=>{
|
|
52
55
|
if (ref && ref.current) // Escape after clicking something can give it keyboard focus
|
|
53
56
|
// dismiss tooltip on esc key press
|
|
@@ -71,7 +74,7 @@ function $c2d8fb326b9f06da$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
71
74
|
// interactions for example, hover will end. When hover is restored after that element disappears,
|
|
72
75
|
// focus moves on for example, then the tooltip will reopen. We check the modality to know if the hover
|
|
73
76
|
// is the result of moving the mouse.
|
|
74
|
-
if ($
|
|
77
|
+
if ($kgVYN$getInteractionModality() === 'pointer') isHovered.current = true;
|
|
75
78
|
else isHovered.current = false;
|
|
76
79
|
handleShow();
|
|
77
80
|
};
|
|
@@ -89,7 +92,7 @@ function $c2d8fb326b9f06da$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
89
92
|
handleHide(true);
|
|
90
93
|
};
|
|
91
94
|
let onFocus = ()=>{
|
|
92
|
-
let isVisible = $
|
|
95
|
+
let isVisible = $kgVYN$isFocusVisible();
|
|
93
96
|
if (isVisible) {
|
|
94
97
|
isFocused.current = true;
|
|
95
98
|
handleShow();
|
|
@@ -100,15 +103,15 @@ function $c2d8fb326b9f06da$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
100
103
|
isHovered.current = false;
|
|
101
104
|
handleHide(true);
|
|
102
105
|
};
|
|
103
|
-
let { hoverProps: hoverProps } = $
|
|
106
|
+
let { hoverProps: hoverProps } = $kgVYN$useHover({
|
|
104
107
|
isDisabled: isDisabled,
|
|
105
108
|
onHoverStart: onHoverStart,
|
|
106
109
|
onHoverEnd: onHoverEnd
|
|
107
110
|
});
|
|
108
|
-
let { pressProps: pressProps } = $
|
|
111
|
+
let { pressProps: pressProps } = $kgVYN$usePress({
|
|
109
112
|
onPressStart: onPressStart
|
|
110
113
|
});
|
|
111
|
-
let { focusableProps: focusableProps } = $
|
|
114
|
+
let { focusableProps: focusableProps } = $kgVYN$useFocusable({
|
|
112
115
|
isDisabled: isDisabled,
|
|
113
116
|
onFocus: onFocus,
|
|
114
117
|
onBlur: onBlur
|
|
@@ -116,7 +119,7 @@ function $c2d8fb326b9f06da$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
116
119
|
return {
|
|
117
120
|
triggerProps: {
|
|
118
121
|
'aria-describedby': state.isOpen ? tooltipId : undefined,
|
|
119
|
-
...$
|
|
122
|
+
...$kgVYN$mergeProps(focusableProps, hoverProps, pressProps)
|
|
120
123
|
},
|
|
121
124
|
tooltipProps: {
|
|
122
125
|
id: tooltipId
|
|
@@ -127,5 +130,5 @@ function $c2d8fb326b9f06da$export$a6da6c504e4bba8b(props, state, ref) {
|
|
|
127
130
|
|
|
128
131
|
|
|
129
132
|
|
|
130
|
-
export {$
|
|
133
|
+
export {$326e436e94273fe1$export$1c4b08e0eca38426 as useTooltip, $4e1b34546679e357$export$a6da6c504e4bba8b as useTooltipTrigger};
|
|
131
134
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CA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,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,eAAQ,CAAC,CAAC;oBAC3B,UAAU;sBACV,YAAY;oBACZ,UAAU;IACZ,CAAC;IAED,GAAG,CAAC,CAAC,aAAA,UAAU,EAAA,CAAC,GAAG,eAAQ,CAAC,CAAC;sBAAA,YAAY;IAAA,CAAC;IAE1C,GAAG,CAAC,CAAC,iBAAA,cAAc,EAAA,CAAC,GAAG,mBAAY,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,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/tooltip",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.7",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/focus": "^3.5.
|
|
22
|
-
"@react-aria/interactions": "^3.8.
|
|
23
|
-
"@react-aria/utils": "^3.11.
|
|
24
|
-
"@react-stately/tooltip": "^3.0.
|
|
25
|
-
"@react-types/shared": "^3.11.
|
|
26
|
-
"@react-types/tooltip": "^3.1.
|
|
21
|
+
"@react-aria/focus": "^3.5.4",
|
|
22
|
+
"@react-aria/interactions": "^3.8.3",
|
|
23
|
+
"@react-aria/utils": "^3.11.3",
|
|
24
|
+
"@react-stately/tooltip": "^3.0.8",
|
|
25
|
+
"@react-types/shared": "^3.11.2",
|
|
26
|
+
"@react-types/tooltip": "^3.1.5"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "e7708349a637642a30d33a11ca4a75ad5829eaa3"
|
|
35
35
|
}
|