@fluentui/react-tooltip 9.2.34 → 9.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +40 -1
- package/CHANGELOG.md +15 -2
- package/dist/index.d.ts +9 -1
- package/lib/components/Tooltip/Tooltip.types.js.map +1 -1
- package/lib/components/Tooltip/useTooltip.js +15 -10
- package/lib/components/Tooltip/useTooltip.js.map +1 -1
- package/lib-commonjs/components/Tooltip/useTooltip.js +15 -10
- package/lib-commonjs/components/Tooltip/useTooltip.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,46 @@
|
|
2
2
|
"name": "@fluentui/react-tooltip",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
5
|
+
"date": "Thu, 24 Aug 2023 10:23:07 GMT",
|
6
|
+
"tag": "@fluentui/react-tooltip_v9.3.0",
|
7
|
+
"version": "9.3.0",
|
8
|
+
"comments": {
|
9
|
+
"minor": [
|
10
|
+
{
|
11
|
+
"author": "behowell@microsoft.com",
|
12
|
+
"package": "@fluentui/react-tooltip",
|
13
|
+
"commit": "45b2bea5f7bd1c8a453ce37726818f572afe0ab0",
|
14
|
+
"comment": "feat: Add documentKeyboardEvent to OnVisibleChangeData when Tooltip is hidden via Escape"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"author": "beachball",
|
18
|
+
"package": "@fluentui/react-tooltip",
|
19
|
+
"comment": "Bump @fluentui/react-jsx-runtime to v9.0.2",
|
20
|
+
"commit": "3f6c5a749ef403c06b9c9e753df9afbb84a2ecb5"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"author": "beachball",
|
24
|
+
"package": "@fluentui/react-tooltip",
|
25
|
+
"comment": "Bump @fluentui/react-portal to v9.3.9",
|
26
|
+
"commit": "3f6c5a749ef403c06b9c9e753df9afbb84a2ecb5"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"author": "beachball",
|
30
|
+
"package": "@fluentui/react-tooltip",
|
31
|
+
"comment": "Bump @fluentui/react-positioning to v9.9.7",
|
32
|
+
"commit": "3f6c5a749ef403c06b9c9e753df9afbb84a2ecb5"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"author": "beachball",
|
36
|
+
"package": "@fluentui/react-tooltip",
|
37
|
+
"comment": "Bump @fluentui/react-utilities to v9.12.0",
|
38
|
+
"commit": "3f6c5a749ef403c06b9c9e753df9afbb84a2ecb5"
|
39
|
+
}
|
40
|
+
]
|
41
|
+
}
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"date": "Wed, 23 Aug 2023 12:01:49 GMT",
|
6
45
|
"tag": "@fluentui/react-tooltip_v9.2.34",
|
7
46
|
"version": "9.2.34",
|
8
47
|
"comments": {
|
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,25 @@
|
|
1
1
|
# Change Log - @fluentui/react-tooltip
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Thu, 24 Aug 2023 10:23:07 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.3.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-tooltip_v9.3.0)
|
8
|
+
|
9
|
+
Thu, 24 Aug 2023 10:23:07 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tooltip_v9.2.34..@fluentui/react-tooltip_v9.3.0)
|
11
|
+
|
12
|
+
### Minor changes
|
13
|
+
|
14
|
+
- feat: Add documentKeyboardEvent to OnVisibleChangeData when Tooltip is hidden via Escape ([PR #28951](https://github.com/microsoft/fluentui/pull/28951) by behowell@microsoft.com)
|
15
|
+
- Bump @fluentui/react-jsx-runtime to v9.0.2 ([PR #28973](https://github.com/microsoft/fluentui/pull/28973) by beachball)
|
16
|
+
- Bump @fluentui/react-portal to v9.3.9 ([PR #28973](https://github.com/microsoft/fluentui/pull/28973) by beachball)
|
17
|
+
- Bump @fluentui/react-positioning to v9.9.7 ([PR #28973](https://github.com/microsoft/fluentui/pull/28973) by beachball)
|
18
|
+
- Bump @fluentui/react-utilities to v9.12.0 ([PR #28973](https://github.com/microsoft/fluentui/pull/28973) by beachball)
|
19
|
+
|
7
20
|
## [9.2.34](https://github.com/microsoft/fluentui/tree/@fluentui/react-tooltip_v9.2.34)
|
8
21
|
|
9
|
-
Wed, 23 Aug 2023
|
22
|
+
Wed, 23 Aug 2023 12:01:49 GMT
|
10
23
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tooltip_v9.2.33..@fluentui/react-tooltip_v9.2.34)
|
11
24
|
|
12
25
|
### Patches
|
package/dist/index.d.ts
CHANGED
@@ -12,6 +12,11 @@ import type { TriggerProps } from '@fluentui/react-utilities';
|
|
12
12
|
*/
|
13
13
|
export declare type OnVisibleChangeData = {
|
14
14
|
visible: boolean;
|
15
|
+
/**
|
16
|
+
* The event object, if this visibility change was triggered by a keyboard event on the document element
|
17
|
+
* (such as Escape to hide the visible tooltip). Otherwise undefined.
|
18
|
+
*/
|
19
|
+
documentKeyboardEvent?: KeyboardEvent;
|
15
20
|
};
|
16
21
|
|
17
22
|
/**
|
@@ -45,7 +50,10 @@ export declare type TooltipProps = ComponentProps<TooltipSlots> & TriggerProps<T
|
|
45
50
|
*/
|
46
51
|
hideDelay?: number;
|
47
52
|
/**
|
48
|
-
* Notification when the visibility of the tooltip is changing
|
53
|
+
* Notification when the visibility of the tooltip is changing.
|
54
|
+
*
|
55
|
+
* **Note**: for backwards compatibility, `event` will be undefined if this was triggered by a keyboard event on
|
56
|
+
* the document element. Use `data.documentKeyboardEvent` if the keyboard event object is needed.
|
49
57
|
*/
|
50
58
|
onVisibleChange?: (event: React_2.PointerEvent<HTMLElement> | React_2.FocusEvent<HTMLElement> | undefined, data: OnVisibleChangeData) => void;
|
51
59
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Tooltip.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { PositioningShorthand } from '@fluentui/react-positioning';\nimport type { ComponentProps, ComponentState, Slot, TriggerProps } from '@fluentui/react-utilities';\nimport type { PortalProps } from '@fluentui/react-portal';\n\n/**\n * Slot properties for Tooltip\n */\nexport type TooltipSlots = {\n /**\n * The text or JSX content of the tooltip.\n */\n content: NonNullable<Slot<'div'>>;\n};\n\n/**\n * The properties that are added to the child of the Tooltip\n */\nexport type TooltipChildProps = {\n ref?: React.Ref<unknown>;\n} & Pick<\n React.HTMLAttributes<HTMLElement>,\n 'aria-describedby' | 'aria-label' | 'aria-labelledby' | 'onBlur' | 'onFocus' | 'onPointerEnter' | 'onPointerLeave'\n>;\n\n/**\n * Data for the Tooltip's onVisibleChange event.\n */\nexport type OnVisibleChangeData = {\n visible: boolean;\n};\n\n/**\n * Properties for Tooltip\n */\nexport type TooltipProps = ComponentProps<TooltipSlots> &\n TriggerProps<TooltipChildProps> &\n Pick<PortalProps, 'mountNode'> & {\n /**\n * The tooltip's visual appearance.\n * * `normal` - Uses the theme's background and text colors.\n * * `inverted` - Higher contrast variant that uses the theme's inverted colors.\n *\n * @default normal\n */\n appearance?: 'normal' | 'inverted';\n /**\n * Delay before the tooltip is hidden, in milliseconds.\n *\n * @default 250\n */\n hideDelay?: number;\n\n /**\n * Notification when the visibility of the tooltip is changing\n */\n onVisibleChange?: (\n event: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement> | undefined,\n data: OnVisibleChangeData,\n ) => void;\n\n /**\n * Configure the positioning of the tooltip\n *\n * @default above\n */\n positioning?: PositioningShorthand;\n\n /**\n * (Required) Specifies whether this tooltip is acting as the description or label of its trigger element.\n *\n * * `label` - The tooltip sets the trigger's aria-label or aria-labelledby attribute. This is useful for buttons\n * displaying only an icon, for example.\n * * `description` - The tooltip sets the trigger's aria-description or aria-describedby attribute.\n * * `inaccessible` - No aria attributes are set on the trigger. This makes the tooltip's content inaccessible to\n * screen readers, and should only be used if the tooltip's text is available by some other means.\n */\n relationship: 'label' | 'description' | 'inaccessible';\n\n /**\n * Delay before the tooltip is shown, in milliseconds.\n *\n * @default 250\n */\n showDelay?: number;\n\n /**\n * Control the tooltip's visibility programatically.\n *\n * This can be used in conjunction with onVisibleChange to modify the tooltip's show and hide behavior.\n *\n * If not provided, the visibility will be controlled by the tooltip itself, based on hover and focus events on the\n * trigger (child) element.\n *\n * @default false\n */\n visible?: boolean;\n\n /**\n * Render an arrow pointing to the target element\n *\n * @default false\n */\n withArrow?: boolean;\n };\n\n/**\n * State used in rendering Tooltip\n */\nexport type TooltipState = ComponentState<TooltipSlots> &\n Pick<TooltipProps, 'mountNode' | 'relationship'> &\n Required<Pick<TooltipProps, 'appearance' | 'hideDelay' | 'positioning' | 'showDelay' | 'visible' | 'withArrow'>> & {\n children?: React.ReactElement | null;\n\n /**\n * Whether the tooltip should be rendered to the DOM.\n */\n shouldRenderTooltip?: boolean;\n\n /**\n * Ref to the arrow element\n */\n arrowRef?: React.Ref<HTMLDivElement>;\n\n /**\n * CSS class for the arrow element\n */\n arrowClassName?: string;\n };\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
|
1
|
+
{"version":3,"sources":["Tooltip.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { PositioningShorthand } from '@fluentui/react-positioning';\nimport type { ComponentProps, ComponentState, Slot, TriggerProps } from '@fluentui/react-utilities';\nimport type { PortalProps } from '@fluentui/react-portal';\n\n/**\n * Slot properties for Tooltip\n */\nexport type TooltipSlots = {\n /**\n * The text or JSX content of the tooltip.\n */\n content: NonNullable<Slot<'div'>>;\n};\n\n/**\n * The properties that are added to the child of the Tooltip\n */\nexport type TooltipChildProps = {\n ref?: React.Ref<unknown>;\n} & Pick<\n React.HTMLAttributes<HTMLElement>,\n 'aria-describedby' | 'aria-label' | 'aria-labelledby' | 'onBlur' | 'onFocus' | 'onPointerEnter' | 'onPointerLeave'\n>;\n\n/**\n * Data for the Tooltip's onVisibleChange event.\n */\nexport type OnVisibleChangeData = {\n visible: boolean;\n\n /**\n * The event object, if this visibility change was triggered by a keyboard event on the document element\n * (such as Escape to hide the visible tooltip). Otherwise undefined.\n */\n documentKeyboardEvent?: KeyboardEvent;\n};\n\n/**\n * Properties for Tooltip\n */\nexport type TooltipProps = ComponentProps<TooltipSlots> &\n TriggerProps<TooltipChildProps> &\n Pick<PortalProps, 'mountNode'> & {\n /**\n * The tooltip's visual appearance.\n * * `normal` - Uses the theme's background and text colors.\n * * `inverted` - Higher contrast variant that uses the theme's inverted colors.\n *\n * @default normal\n */\n appearance?: 'normal' | 'inverted';\n /**\n * Delay before the tooltip is hidden, in milliseconds.\n *\n * @default 250\n */\n hideDelay?: number;\n\n /**\n * Notification when the visibility of the tooltip is changing.\n *\n * **Note**: for backwards compatibility, `event` will be undefined if this was triggered by a keyboard event on\n * the document element. Use `data.documentKeyboardEvent` if the keyboard event object is needed.\n */\n onVisibleChange?: (\n event: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement> | undefined,\n data: OnVisibleChangeData,\n ) => void;\n\n /**\n * Configure the positioning of the tooltip\n *\n * @default above\n */\n positioning?: PositioningShorthand;\n\n /**\n * (Required) Specifies whether this tooltip is acting as the description or label of its trigger element.\n *\n * * `label` - The tooltip sets the trigger's aria-label or aria-labelledby attribute. This is useful for buttons\n * displaying only an icon, for example.\n * * `description` - The tooltip sets the trigger's aria-description or aria-describedby attribute.\n * * `inaccessible` - No aria attributes are set on the trigger. This makes the tooltip's content inaccessible to\n * screen readers, and should only be used if the tooltip's text is available by some other means.\n */\n relationship: 'label' | 'description' | 'inaccessible';\n\n /**\n * Delay before the tooltip is shown, in milliseconds.\n *\n * @default 250\n */\n showDelay?: number;\n\n /**\n * Control the tooltip's visibility programatically.\n *\n * This can be used in conjunction with onVisibleChange to modify the tooltip's show and hide behavior.\n *\n * If not provided, the visibility will be controlled by the tooltip itself, based on hover and focus events on the\n * trigger (child) element.\n *\n * @default false\n */\n visible?: boolean;\n\n /**\n * Render an arrow pointing to the target element\n *\n * @default false\n */\n withArrow?: boolean;\n };\n\n/**\n * State used in rendering Tooltip\n */\nexport type TooltipState = ComponentState<TooltipSlots> &\n Pick<TooltipProps, 'mountNode' | 'relationship'> &\n Required<Pick<TooltipProps, 'appearance' | 'hideDelay' | 'positioning' | 'showDelay' | 'visible' | 'withArrow'>> & {\n children?: React.ReactElement | null;\n\n /**\n * Whether the tooltip should be rendered to the DOM.\n */\n shouldRenderTooltip?: boolean;\n\n /**\n * Ref to the arrow element\n */\n arrowRef?: React.Ref<HTMLDivElement>;\n\n /**\n * CSS class for the arrow element\n */\n arrowClassName?: string;\n };\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
|
@@ -22,15 +22,13 @@ import { Escape } from '@fluentui/keyboard-keys';
|
|
22
22
|
state: props.visible,
|
23
23
|
initialState: false
|
24
24
|
});
|
25
|
-
const setVisible = React.useCallback((
|
25
|
+
const setVisible = React.useCallback((ev, data)=>{
|
26
26
|
clearDelayTimeout();
|
27
27
|
setVisibleInternal((oldVisible)=>{
|
28
|
-
if (
|
29
|
-
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev,
|
30
|
-
visible: newVisible
|
31
|
-
});
|
28
|
+
if (data.visible !== oldVisible) {
|
29
|
+
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev, data);
|
32
30
|
}
|
33
|
-
return
|
31
|
+
return data.visible;
|
34
32
|
});
|
35
33
|
}, [
|
36
34
|
clearDelayTimeout,
|
@@ -80,13 +78,16 @@ import { Escape } from '@fluentui/keyboard-keys';
|
|
80
78
|
if (visible) {
|
81
79
|
var _context_visibleTooltip;
|
82
80
|
const thisTooltip = {
|
83
|
-
hide: ()=>setVisible(
|
81
|
+
hide: (ev)=>setVisible(undefined, {
|
82
|
+
visible: false,
|
83
|
+
documentKeyboardEvent: ev
|
84
|
+
})
|
84
85
|
};
|
85
86
|
(_context_visibleTooltip = context.visibleTooltip) === null || _context_visibleTooltip === void 0 ? void 0 : _context_visibleTooltip.hide();
|
86
87
|
context.visibleTooltip = thisTooltip;
|
87
88
|
const onDocumentKeyDown = (ev)=>{
|
88
89
|
if (ev.key === Escape) {
|
89
|
-
thisTooltip.hide();
|
90
|
+
thisTooltip.hide(ev);
|
90
91
|
// stop propagation to avoid conflicting with other elements that listen for `Escape`
|
91
92
|
// e,g: Dialog, Popover, Menu
|
92
93
|
ev.stopPropagation();
|
@@ -127,7 +128,9 @@ import { Escape } from '@fluentui/keyboard-keys';
|
|
127
128
|
// Show immediately if another tooltip is already visible
|
128
129
|
const delay = context.visibleTooltip ? 0 : state.showDelay;
|
129
130
|
setDelayTimeout(()=>{
|
130
|
-
setVisible(
|
131
|
+
setVisible(ev, {
|
132
|
+
visible: true
|
133
|
+
});
|
131
134
|
}, delay);
|
132
135
|
ev.persist(); // Persist the event since the setVisible call will happen asynchronously
|
133
136
|
}, [
|
@@ -145,7 +148,9 @@ import { Escape } from '@fluentui/keyboard-keys';
|
|
145
148
|
ignoreNextFocusEventRef.current = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) === ev.target;
|
146
149
|
}
|
147
150
|
setDelayTimeout(()=>{
|
148
|
-
setVisible(
|
151
|
+
setVisible(ev, {
|
152
|
+
visible: false
|
153
|
+
});
|
149
154
|
}, delay);
|
150
155
|
ev.persist(); // Persist the event since the setVisible call will happen asynchronously
|
151
156
|
}, [
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useTooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { mergeArrowOffset, resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport {\n useTooltipVisibility_unstable as useTooltipVisibility,\n useFluent_unstable as useFluent,\n} from '@fluentui/react-shared-contexts';\nimport {\n applyTriggerPropsToChildren,\n useControllableState,\n useId,\n useIsomorphicLayoutEffect,\n useIsSSR,\n useMergedRefs,\n useTimeout,\n getTriggerChild,\n mergeCallbacks,\n useEventCallback,\n slot,\n} from '@fluentui/react-utilities';\nimport type { TooltipProps, TooltipState, TooltipChildProps } from './Tooltip.types';\nimport { arrowHeight, tooltipBorderRadius } from './private/constants';\nimport { Escape } from '@fluentui/keyboard-keys';\n\n/**\n * Create the state required to render Tooltip.\n *\n * The returned state can be modified with hooks such as useTooltipStyles_unstable,\n * before being passed to renderTooltip_unstable.\n *\n * @param props - props from this instance of Tooltip\n */\nexport const useTooltip_unstable = (props: TooltipProps): TooltipState => {\n const context = useTooltipVisibility();\n const isServerSideRender = useIsSSR();\n const { targetDocument } = useFluent();\n const [setDelayTimeout, clearDelayTimeout] = useTimeout();\n\n const {\n appearance = 'normal',\n children,\n content,\n withArrow = false,\n positioning = 'above',\n onVisibleChange,\n relationship,\n showDelay = 250,\n hideDelay = 250,\n mountNode,\n } = props;\n\n const [visible, setVisibleInternal] = useControllableState({ state: props.visible, initialState: false });\n const setVisible = React.useCallback(\n (newVisible: boolean, ev?: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement>) => {\n clearDelayTimeout();\n setVisibleInternal(oldVisible => {\n if (newVisible !== oldVisible) {\n onVisibleChange?.(ev, { visible: newVisible });\n }\n return newVisible;\n });\n },\n [clearDelayTimeout, setVisibleInternal, onVisibleChange],\n );\n\n const state: TooltipState = {\n withArrow,\n positioning,\n showDelay,\n hideDelay,\n relationship,\n visible,\n shouldRenderTooltip: visible,\n appearance,\n mountNode,\n // Slots\n components: {\n content: 'div',\n },\n content: slot.always(content, {\n defaultProps: {\n role: 'tooltip',\n },\n elementType: 'div',\n }),\n };\n\n state.content.id = useId('tooltip-', state.content.id);\n\n const positioningOptions = {\n enabled: state.visible,\n arrowPadding: 2 * tooltipBorderRadius,\n position: 'above' as const,\n align: 'center' as const,\n offset: 4,\n ...resolvePositioningShorthand(state.positioning),\n };\n\n if (state.withArrow) {\n positioningOptions.offset = mergeArrowOffset(positioningOptions.offset, arrowHeight);\n }\n\n const {\n targetRef,\n containerRef,\n arrowRef,\n }: {\n targetRef: React.MutableRefObject<unknown>;\n containerRef: React.MutableRefObject<HTMLDivElement>;\n arrowRef: React.MutableRefObject<HTMLDivElement>;\n } = usePositioning(positioningOptions);\n\n state.content.ref = useMergedRefs(state.content.ref, containerRef);\n state.arrowRef = arrowRef;\n\n // When this tooltip is visible, hide any other tooltips, and register it\n // as the visibleTooltip with the TooltipContext.\n // Also add a listener on document to hide the tooltip if Escape is pressed\n useIsomorphicLayoutEffect(() => {\n if (visible) {\n const thisTooltip = { hide: () => setVisible(false) };\n\n context.visibleTooltip?.hide();\n context.visibleTooltip = thisTooltip;\n\n const onDocumentKeyDown = (ev: KeyboardEvent) => {\n if (ev.key === Escape) {\n thisTooltip.hide();\n // stop propagation to avoid conflicting with other elements that listen for `Escape`\n // e,g: Dialog, Popover, Menu\n ev.stopPropagation();\n }\n };\n\n targetDocument?.addEventListener('keydown', onDocumentKeyDown, {\n // As this event is added at targeted document,\n // we need to capture the event to be sure keydown handling from tooltip happens first\n capture: true,\n });\n\n return () => {\n if (context.visibleTooltip === thisTooltip) {\n context.visibleTooltip = undefined;\n }\n\n targetDocument?.removeEventListener('keydown', onDocumentKeyDown, { capture: true });\n };\n }\n }, [context, targetDocument, visible, setVisible]);\n\n // The focused element gets a blur event when the document loses focus\n // (e.g. switching tabs in the browser), but we don't want to show the\n // tooltip again when the document gets focus back. Handle this case by\n // checking if the blurred element is still the document's activeElement.\n // See https://github.com/microsoft/fluentui/issues/13541\n const ignoreNextFocusEventRef = React.useRef(false);\n\n // Listener for onPointerEnter and onFocus on the trigger element\n const onEnterTrigger = React.useCallback(\n (ev: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement>) => {\n if (ev.type === 'focus' && ignoreNextFocusEventRef.current) {\n ignoreNextFocusEventRef.current = false;\n return;\n }\n\n // Show immediately if another tooltip is already visible\n const delay = context.visibleTooltip ? 0 : state.showDelay;\n\n setDelayTimeout(() => {\n setVisible(true, ev);\n }, delay);\n\n ev.persist(); // Persist the event since the setVisible call will happen asynchronously\n },\n [setDelayTimeout, setVisible, state.showDelay, context],\n );\n\n // Listener for onPointerLeave and onBlur on the trigger element\n const onLeaveTrigger = React.useCallback(\n (ev: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement>) => {\n let delay = state.hideDelay;\n\n if (ev.type === 'blur') {\n // Hide immediately when losing focus\n delay = 0;\n\n ignoreNextFocusEventRef.current = targetDocument?.activeElement === ev.target;\n }\n\n setDelayTimeout(() => {\n setVisible(false, ev);\n }, delay);\n\n ev.persist(); // Persist the event since the setVisible call will happen asynchronously\n },\n [setDelayTimeout, setVisible, state.hideDelay, targetDocument],\n );\n\n // Cancel the hide timer when the mouse or focus enters the tooltip, and restart it when the mouse or focus leaves.\n // This keeps the tooltip visible when the mouse is moved over it, or it has focus within.\n state.content.onPointerEnter = mergeCallbacks(state.content.onPointerEnter, clearDelayTimeout);\n state.content.onPointerLeave = mergeCallbacks(state.content.onPointerLeave, onLeaveTrigger);\n state.content.onFocus = mergeCallbacks(state.content.onFocus, clearDelayTimeout);\n state.content.onBlur = mergeCallbacks(state.content.onBlur, onLeaveTrigger);\n\n const child = getTriggerChild(children);\n\n const triggerAriaProps: Pick<TooltipChildProps, 'aria-label' | 'aria-labelledby' | 'aria-describedby'> = {};\n\n if (relationship === 'label') {\n // aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.\n if (typeof state.content.children === 'string') {\n triggerAriaProps['aria-label'] = state.content.children;\n } else {\n triggerAriaProps['aria-labelledby'] = state.content.id;\n // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element\n state.shouldRenderTooltip = true;\n }\n } else if (relationship === 'description') {\n triggerAriaProps['aria-describedby'] = state.content.id;\n // Always render the tooltip even if hidden, so that aria-describedby refers to a valid element\n state.shouldRenderTooltip = true;\n }\n\n // Don't render the Tooltip in SSR to avoid hydration errors\n if (isServerSideRender) {\n state.shouldRenderTooltip = false;\n }\n\n const childTargetRef = useMergedRefs(child?.ref, targetRef);\n\n // Apply the trigger props to the child, either by calling the render function, or cloning with the new props\n state.children = applyTriggerPropsToChildren(children, {\n ...triggerAriaProps,\n ...child?.props,\n // If the target prop is not provided, attach targetRef to the trigger element's ref prop\n ref: positioningOptions.target === undefined ? childTargetRef : child?.ref,\n onPointerEnter: useEventCallback(mergeCallbacks(child?.props?.onPointerEnter, onEnterTrigger)),\n onPointerLeave: useEventCallback(mergeCallbacks(child?.props?.onPointerLeave, onLeaveTrigger)),\n onFocus: useEventCallback(mergeCallbacks(child?.props?.onFocus, onEnterTrigger)),\n onBlur: useEventCallback(mergeCallbacks(child?.props?.onBlur, onLeaveTrigger)),\n });\n\n return state;\n};\n"],"names":["React","mergeArrowOffset","resolvePositioningShorthand","usePositioning","useTooltipVisibility_unstable","useTooltipVisibility","useFluent_unstable","useFluent","applyTriggerPropsToChildren","useControllableState","useId","useIsomorphicLayoutEffect","useIsSSR","useMergedRefs","useTimeout","getTriggerChild","mergeCallbacks","useEventCallback","slot","arrowHeight","tooltipBorderRadius","Escape","useTooltip_unstable","props","child","context","isServerSideRender","targetDocument","setDelayTimeout","clearDelayTimeout","appearance","children","content","withArrow","positioning","onVisibleChange","relationship","showDelay","hideDelay","mountNode","visible","setVisibleInternal","state","initialState","setVisible","useCallback","newVisible","ev","oldVisible","shouldRenderTooltip","components","always","defaultProps","role","elementType","id","positioningOptions","enabled","arrowPadding","position","align","offset","targetRef","containerRef","arrowRef","ref","thisTooltip","hide","visibleTooltip","onDocumentKeyDown","key","stopPropagation","addEventListener","capture","undefined","removeEventListener","ignoreNextFocusEventRef","useRef","onEnterTrigger","type","current","delay","persist","onLeaveTrigger","activeElement","target","onPointerEnter","onPointerLeave","onFocus","onBlur","triggerAriaProps","childTargetRef"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,gBAAgB,EAAEC,2BAA2B,EAAEC,cAAc,QAAQ,8BAA8B;AAC5G,SACEC,iCAAiCC,oBAAoB,EACrDC,sBAAsBC,SAAS,QAC1B,kCAAkC;AACzC,SACEC,2BAA2B,EAC3BC,oBAAoB,EACpBC,KAAK,EACLC,yBAAyB,EACzBC,QAAQ,EACRC,aAAa,EACbC,UAAU,EACVC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AA,mBAAAA,KAAAA,IAAAA,MAAOyC,GAAG;QAC1EqB,gBAAgBrE,iBAAiBD,eAAeQ,kBAAAA,mBAAAA,KAAAA,IAAAA,CAAAA,eAAAA,MAAOD,KAAK,cAAZC,0BAAAA,KAAAA,IAAAA,aAAc8D,cAAF,EAAkBR;QAC9ES,gBAAgBtE,iBAAiBD,eAAeQ,kBAAAA,mBAAAA,KAAAA,IAAAA,CAAAA,gBAAAA,MAAOD,KAAK,cAAZC,2BAAAA,KAAAA,IAAAA,cAAc+D,cAAF,EAAkBJ;QAC9EK,SAASvE,iBAAiBD,eAAeQ,kBAAAA,mBAAAA,KAAAA,IAAAA,CAAAA,gBAAAA,MAAOD,KAAK,cAAZC,2BAAAA,KAAAA,IAAAA,cAAcgE,OAAF,EAAWV;QAChEW,QAAQxE,iBAAiBD,eAAeQ,kBAAAA,mBAAAA,KAAAA,IAAAA,CAAAA,gBAAAA,MAAOD,KAAK,cAAZC,2BAAAA,KAAAA,IAAAA,cAAciE,MAAF,EAAUN;IAChE;IAEA,OAAOzC;AACT,EAAE"}
|
1
|
+
{"version":3,"sources":["useTooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { mergeArrowOffset, resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport {\n useTooltipVisibility_unstable as useTooltipVisibility,\n useFluent_unstable as useFluent,\n} from '@fluentui/react-shared-contexts';\nimport {\n applyTriggerPropsToChildren,\n useControllableState,\n useId,\n useIsomorphicLayoutEffect,\n useIsSSR,\n useMergedRefs,\n useTimeout,\n getTriggerChild,\n mergeCallbacks,\n useEventCallback,\n slot,\n} from '@fluentui/react-utilities';\nimport type { TooltipProps, TooltipState, TooltipChildProps, OnVisibleChangeData } from './Tooltip.types';\nimport { arrowHeight, tooltipBorderRadius } from './private/constants';\nimport { Escape } from '@fluentui/keyboard-keys';\n\n/**\n * Create the state required to render Tooltip.\n *\n * The returned state can be modified with hooks such as useTooltipStyles_unstable,\n * before being passed to renderTooltip_unstable.\n *\n * @param props - props from this instance of Tooltip\n */\nexport const useTooltip_unstable = (props: TooltipProps): TooltipState => {\n const context = useTooltipVisibility();\n const isServerSideRender = useIsSSR();\n const { targetDocument } = useFluent();\n const [setDelayTimeout, clearDelayTimeout] = useTimeout();\n\n const {\n appearance = 'normal',\n children,\n content,\n withArrow = false,\n positioning = 'above',\n onVisibleChange,\n relationship,\n showDelay = 250,\n hideDelay = 250,\n mountNode,\n } = props;\n\n const [visible, setVisibleInternal] = useControllableState({ state: props.visible, initialState: false });\n const setVisible = React.useCallback(\n (ev: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement> | undefined, data: OnVisibleChangeData) => {\n clearDelayTimeout();\n setVisibleInternal(oldVisible => {\n if (data.visible !== oldVisible) {\n onVisibleChange?.(ev, data);\n }\n return data.visible;\n });\n },\n [clearDelayTimeout, setVisibleInternal, onVisibleChange],\n );\n\n const state: TooltipState = {\n withArrow,\n positioning,\n showDelay,\n hideDelay,\n relationship,\n visible,\n shouldRenderTooltip: visible,\n appearance,\n mountNode,\n // Slots\n components: {\n content: 'div',\n },\n content: slot.always(content, {\n defaultProps: {\n role: 'tooltip',\n },\n elementType: 'div',\n }),\n };\n\n state.content.id = useId('tooltip-', state.content.id);\n\n const positioningOptions = {\n enabled: state.visible,\n arrowPadding: 2 * tooltipBorderRadius,\n position: 'above' as const,\n align: 'center' as const,\n offset: 4,\n ...resolvePositioningShorthand(state.positioning),\n };\n\n if (state.withArrow) {\n positioningOptions.offset = mergeArrowOffset(positioningOptions.offset, arrowHeight);\n }\n\n const {\n targetRef,\n containerRef,\n arrowRef,\n }: {\n targetRef: React.MutableRefObject<unknown>;\n containerRef: React.MutableRefObject<HTMLDivElement>;\n arrowRef: React.MutableRefObject<HTMLDivElement>;\n } = usePositioning(positioningOptions);\n\n state.content.ref = useMergedRefs(state.content.ref, containerRef);\n state.arrowRef = arrowRef;\n\n // When this tooltip is visible, hide any other tooltips, and register it\n // as the visibleTooltip with the TooltipContext.\n // Also add a listener on document to hide the tooltip if Escape is pressed\n useIsomorphicLayoutEffect(() => {\n if (visible) {\n const thisTooltip = {\n hide: (ev?: KeyboardEvent) => setVisible(undefined, { visible: false, documentKeyboardEvent: ev }),\n };\n\n context.visibleTooltip?.hide();\n context.visibleTooltip = thisTooltip;\n\n const onDocumentKeyDown = (ev: KeyboardEvent) => {\n if (ev.key === Escape) {\n thisTooltip.hide(ev);\n // stop propagation to avoid conflicting with other elements that listen for `Escape`\n // e,g: Dialog, Popover, Menu\n ev.stopPropagation();\n }\n };\n\n targetDocument?.addEventListener('keydown', onDocumentKeyDown, {\n // As this event is added at targeted document,\n // we need to capture the event to be sure keydown handling from tooltip happens first\n capture: true,\n });\n\n return () => {\n if (context.visibleTooltip === thisTooltip) {\n context.visibleTooltip = undefined;\n }\n\n targetDocument?.removeEventListener('keydown', onDocumentKeyDown, { capture: true });\n };\n }\n }, [context, targetDocument, visible, setVisible]);\n\n // The focused element gets a blur event when the document loses focus\n // (e.g. switching tabs in the browser), but we don't want to show the\n // tooltip again when the document gets focus back. Handle this case by\n // checking if the blurred element is still the document's activeElement.\n // See https://github.com/microsoft/fluentui/issues/13541\n const ignoreNextFocusEventRef = React.useRef(false);\n\n // Listener for onPointerEnter and onFocus on the trigger element\n const onEnterTrigger = React.useCallback(\n (ev: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement>) => {\n if (ev.type === 'focus' && ignoreNextFocusEventRef.current) {\n ignoreNextFocusEventRef.current = false;\n return;\n }\n\n // Show immediately if another tooltip is already visible\n const delay = context.visibleTooltip ? 0 : state.showDelay;\n\n setDelayTimeout(() => {\n setVisible(ev, { visible: true });\n }, delay);\n\n ev.persist(); // Persist the event since the setVisible call will happen asynchronously\n },\n [setDelayTimeout, setVisible, state.showDelay, context],\n );\n\n // Listener for onPointerLeave and onBlur on the trigger element\n const onLeaveTrigger = React.useCallback(\n (ev: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement>) => {\n let delay = state.hideDelay;\n\n if (ev.type === 'blur') {\n // Hide immediately when losing focus\n delay = 0;\n\n ignoreNextFocusEventRef.current = targetDocument?.activeElement === ev.target;\n }\n\n setDelayTimeout(() => {\n setVisible(ev, { visible: false });\n }, delay);\n\n ev.persist(); // Persist the event since the setVisible call will happen asynchronously\n },\n [setDelayTimeout, setVisible, state.hideDelay, targetDocument],\n );\n\n // Cancel the hide timer when the mouse or focus enters the tooltip, and restart it when the mouse or focus leaves.\n // This keeps the tooltip visible when the mouse is moved over it, or it has focus within.\n state.content.onPointerEnter = mergeCallbacks(state.content.onPointerEnter, clearDelayTimeout);\n state.content.onPointerLeave = mergeCallbacks(state.content.onPointerLeave, onLeaveTrigger);\n state.content.onFocus = mergeCallbacks(state.content.onFocus, clearDelayTimeout);\n state.content.onBlur = mergeCallbacks(state.content.onBlur, onLeaveTrigger);\n\n const child = getTriggerChild(children);\n\n const triggerAriaProps: Pick<TooltipChildProps, 'aria-label' | 'aria-labelledby' | 'aria-describedby'> = {};\n\n if (relationship === 'label') {\n // aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.\n if (typeof state.content.children === 'string') {\n triggerAriaProps['aria-label'] = state.content.children;\n } else {\n triggerAriaProps['aria-labelledby'] = state.content.id;\n // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element\n state.shouldRenderTooltip = true;\n }\n } else if (relationship === 'description') {\n triggerAriaProps['aria-describedby'] = state.content.id;\n // Always render the tooltip even if hidden, so that aria-describedby refers to a valid element\n state.shouldRenderTooltip = true;\n }\n\n // Don't render the Tooltip in SSR to avoid hydration errors\n if (isServerSideRender) {\n state.shouldRenderTooltip = false;\n }\n\n const childTargetRef = useMergedRefs(child?.ref, targetRef);\n\n // Apply the trigger props to the child, either by calling the render function, or cloning with the new props\n state.children = applyTriggerPropsToChildren(children, {\n ...triggerAriaProps,\n ...child?.props,\n // If the target prop is not provided, attach targetRef to the trigger element's ref prop\n ref: positioningOptions.target === undefined ? childTargetRef : child?.ref,\n onPointerEnter: useEventCallback(mergeCallbacks(child?.props?.onPointerEnter, onEnterTrigger)),\n onPointerLeave: useEventCallback(mergeCallbacks(child?.props?.onPointerLeave, onLeaveTrigger)),\n onFocus: useEventCallback(mergeCallbacks(child?.props?.onFocus, onEnterTrigger)),\n onBlur: useEventCallback(mergeCallbacks(child?.props?.onBlur, onLeaveTrigger)),\n });\n\n return state;\n};\n"],"names":["React","mergeArrowOffset","resolvePositioningShorthand","usePositioning","useTooltipVisibility_unstable","useTooltipVisibility","useFluent_unstable","useFluent","applyTriggerPropsToChildren","useControllableState","useId","useIsomorphicLayoutEffect","useIsSSR","useMergedRefs","useTimeout","getTriggerChild","mergeCallbacks","useEventCallback","slot","arrowHeight","tooltipBorderRadius","Escape","useTooltip_unstable","props","child","context","isServerSideRender","targetDocument","setDelayTimeout","clearDelayTimeout","appearance","children","content","withArrow","positioning","onVisibleChange","relationship","showDelay","hideDelay","mountNode","visible","setVisibleInternal","state","initialState","setVisible","useCallback","ev","data","oldVisible","shouldRenderTooltip","components","always","defaultProps","role","elementType","id","positioningOptions","enabled","arrowPadding","position","align","offset","targetRef","containerRef","arrowRef","ref","thisTooltip","hide","undefined","documentKeyboardEvent","visibleTooltip","onDocumentKeyDown","key","stopPropagation","addEventListener","capture","removeEventListener","ignoreNextFocusEventRef","useRef","onEnterTrigger","type","current","delay","persist","onLeaveTrigger","activeElement","target","onPointerEnter","onPointerLeave","onFocus","onBlur","triggerAriaProps","childTargetRef"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,gBAAgB,EAAEC,2BAA2B,EAAEC,cAAc,QAAQ,8BAA8B;AAC5G,SACEC,iCAAiCC,oBAAoB,EACrDC,sBAAsBC,SAAS,QAC1B,kCAAkC;AACzC,SACEC,2BAA2B,EAC3BC,oBAAoB,EACpBC,KAAK,EACLC,yBAAyB,EACzBC,QAAQ,EACRC,aAAa,EACbC,UAAU,EACVC,eAAe,EACfC,cAAc,EACdC,gBAAgB,EAChBC,IAAI,QACC,4BAA4B;AAEn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KT,mBAAmB8B,MAAM,KAAKlB,YAAYwB,iBAAiBpE,kBAAAA,mBAAAA,KAAAA,IAAAA,MAAOyC,GAAG;QAC1EsB,gBAAgBtE,iBAAiBD,eAAeQ,kBAAAA,mBAAAA,KAAAA,IAAAA,CAAAA,eAAAA,MAAOD,KAAK,cAAZC,0BAAAA,KAAAA,IAAAA,aAAc+D,cAAF,EAAkBR;QAC9ES,gBAAgBvE,iBAAiBD,eAAeQ,kBAAAA,mBAAAA,KAAAA,IAAAA,CAAAA,gBAAAA,MAAOD,KAAK,cAAZC,2BAAAA,KAAAA,IAAAA,cAAcgE,cAAF,EAAkBJ;QAC9EK,SAASxE,iBAAiBD,eAAeQ,kBAAAA,mBAAAA,KAAAA,IAAAA,CAAAA,gBAAAA,MAAOD,KAAK,cAAZC,2BAAAA,KAAAA,IAAAA,cAAciE,OAAF,EAAWV;QAChEW,QAAQzE,iBAAiBD,eAAeQ,kBAAAA,mBAAAA,KAAAA,IAAAA,CAAAA,gBAAAA,MAAOD,KAAK,cAAZC,2BAAAA,KAAAA,IAAAA,cAAckE,MAAF,EAAUN;IAChE;IAEA,OAAO1C;AACT,EAAE"}
|
@@ -24,15 +24,13 @@ const useTooltip_unstable = (props)=>{
|
|
24
24
|
state: props.visible,
|
25
25
|
initialState: false
|
26
26
|
});
|
27
|
-
const setVisible = _react.useCallback((
|
27
|
+
const setVisible = _react.useCallback((ev, data)=>{
|
28
28
|
clearDelayTimeout();
|
29
29
|
setVisibleInternal((oldVisible)=>{
|
30
|
-
if (
|
31
|
-
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev,
|
32
|
-
visible: newVisible
|
33
|
-
});
|
30
|
+
if (data.visible !== oldVisible) {
|
31
|
+
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev, data);
|
34
32
|
}
|
35
|
-
return
|
33
|
+
return data.visible;
|
36
34
|
});
|
37
35
|
}, [
|
38
36
|
clearDelayTimeout,
|
@@ -82,13 +80,16 @@ const useTooltip_unstable = (props)=>{
|
|
82
80
|
if (visible) {
|
83
81
|
var _context_visibleTooltip;
|
84
82
|
const thisTooltip = {
|
85
|
-
hide: ()=>setVisible(
|
83
|
+
hide: (ev)=>setVisible(undefined, {
|
84
|
+
visible: false,
|
85
|
+
documentKeyboardEvent: ev
|
86
|
+
})
|
86
87
|
};
|
87
88
|
(_context_visibleTooltip = context.visibleTooltip) === null || _context_visibleTooltip === void 0 ? void 0 : _context_visibleTooltip.hide();
|
88
89
|
context.visibleTooltip = thisTooltip;
|
89
90
|
const onDocumentKeyDown = (ev)=>{
|
90
91
|
if (ev.key === _keyboardKeys.Escape) {
|
91
|
-
thisTooltip.hide();
|
92
|
+
thisTooltip.hide(ev);
|
92
93
|
// stop propagation to avoid conflicting with other elements that listen for `Escape`
|
93
94
|
// e,g: Dialog, Popover, Menu
|
94
95
|
ev.stopPropagation();
|
@@ -129,7 +130,9 @@ const useTooltip_unstable = (props)=>{
|
|
129
130
|
// Show immediately if another tooltip is already visible
|
130
131
|
const delay = context.visibleTooltip ? 0 : state.showDelay;
|
131
132
|
setDelayTimeout(()=>{
|
132
|
-
setVisible(
|
133
|
+
setVisible(ev, {
|
134
|
+
visible: true
|
135
|
+
});
|
133
136
|
}, delay);
|
134
137
|
ev.persist(); // Persist the event since the setVisible call will happen asynchronously
|
135
138
|
}, [
|
@@ -147,7 +150,9 @@ const useTooltip_unstable = (props)=>{
|
|
147
150
|
ignoreNextFocusEventRef.current = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) === ev.target;
|
148
151
|
}
|
149
152
|
setDelayTimeout(()=>{
|
150
|
-
setVisible(
|
153
|
+
setVisible(ev, {
|
154
|
+
visible: false
|
155
|
+
});
|
151
156
|
}, delay);
|
152
157
|
ev.persist(); // Persist the event since the setVisible call will happen asynchronously
|
153
158
|
}, [
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useTooltip.js"],"sourcesContent":["import * as React from 'react';\nimport { mergeArrowOffset, resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport { useTooltipVisibility_unstable as useTooltipVisibility, useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { applyTriggerPropsToChildren, useControllableState, useId, useIsomorphicLayoutEffect, useIsSSR, useMergedRefs, useTimeout, getTriggerChild, mergeCallbacks, useEventCallback, slot } from '@fluentui/react-utilities';\nimport { arrowHeight, tooltipBorderRadius } from './private/constants';\nimport { Escape } from '@fluentui/keyboard-keys';\n/**\n * Create the state required to render Tooltip.\n *\n * The returned state can be modified with hooks such as useTooltipStyles_unstable,\n * before being passed to renderTooltip_unstable.\n *\n * @param props - props from this instance of Tooltip\n */ export const useTooltip_unstable = (props)=>{\n var _child_props, _child_props1, _child_props2, _child_props3;\n const context = useTooltipVisibility();\n const isServerSideRender = useIsSSR();\n const { targetDocument } = useFluent();\n const [setDelayTimeout, clearDelayTimeout] = useTimeout();\n const { appearance ='normal' , children , content , withArrow =false , positioning ='above' , onVisibleChange , relationship , showDelay =250 , hideDelay =250 , mountNode } = props;\n const [visible, setVisibleInternal] = useControllableState({\n state: props.visible,\n initialState: false\n });\n const setVisible = React.useCallback((newVisible, ev)=>{\n clearDelayTimeout();\n setVisibleInternal((oldVisible)=>{\n if (newVisible !== oldVisible) {\n onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev, {\n visible: newVisible\n });\n }\n return newVisible;\n });\n }, [\n clearDelayTimeout,\n setVisibleInternal,\n onVisibleChange\n ]);\n const state = {\n withArrow,\n positioning,\n showDelay,\n hideDelay,\n relationship,\n visible,\n shouldRenderTooltip: visible,\n appearance,\n mountNode,\n // Slots\n components: {\n content: 'div'\n },\n content: slot.always(content, {\n defaultProps: {\n role: 'tooltip'\n },\n elementType: 'div'\n })\n };\n state.content.id = useId('tooltip-', state.content.id);\n const positioningOptions = {\n enabled: state.visible,\n arrowPadding: 2 * tooltipBorderRadius,\n position: 'above',\n align: 'center',\n offset: 4,\n ...resolvePositioningShorthand(state.positioning)\n };\n if (state.withArrow) {\n positioningOptions.offset = mergeArrowOffset(positioningOptions.offset, arrowHeight);\n }\n const { targetRef , containerRef , arrowRef } = usePositioning(positioningOptions);\n state.content.ref = useMergedRefs(state.content.ref, containerRef);\n state.arrowRef = arrowRef;\n // When this tooltip is visible, hide any other tooltips, and register it\n // as the visibleTooltip with the TooltipContext.\n // Also add a listener on document to hide the tooltip if Escape is pressed\n useIsomorphicLayoutEffect(()=>{\n if (visible) {\n var _context_visibleTooltip;\n const thisTooltip = {\n hide: ()=>setVisible(false)\n };\n (_context_visibleTooltip = context.visibleTooltip) === null || _context_visibleTooltip === void 0 ? void 0 : _context_visibleTooltip.hide();\n context.visibleTooltip = thisTooltip;\n const onDocumentKeyDown = (ev)=>{\n if (ev.key === Escape) {\n thisTooltip.hide();\n // stop propagation to avoid conflicting with other elements that listen for `Escape`\n // e,g: Dialog, Popover, Menu\n ev.stopPropagation();\n }\n };\n targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('keydown', onDocumentKeyDown, {\n // As this event is added at targeted document,\n // we need to capture the event to be sure keydown handling from tooltip happens first\n capture: true\n });\n return ()=>{\n if (context.visibleTooltip === thisTooltip) {\n context.visibleTooltip = undefined;\n }\n targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('keydown', onDocumentKeyDown, {\n capture: true\n });\n };\n }\n }, [\n context,\n targetDocument,\n visible,\n setVisible\n ]);\n // The focused element gets a blur event when the document loses focus\n // (e.g. switching tabs in the browser), but we don't want to show the\n // tooltip again when the document gets focus back. Handle this case by\n // checking if the blurred element is still the document's activeElement.\n // See https://github.com/microsoft/fluentui/issues/13541\n const ignoreNextFocusEventRef = React.useRef(false);\n // Listener for onPointerEnter and onFocus on the trigger element\n const onEnterTrigger = React.useCallback((ev)=>{\n if (ev.type === 'focus' && ignoreNextFocusEventRef.current) {\n ignoreNextFocusEventRef.current = false;\n return;\n }\n // Show immediately if another tooltip is already visible\n const delay = context.visibleTooltip ? 0 : state.showDelay;\n setDelayTimeout(()=>{\n setVisible(true, ev);\n }, delay);\n ev.persist(); // Persist the event since the setVisible call will happen asynchronously\n }, [\n setDelayTimeout,\n setVisible,\n state.showDelay,\n context\n ]);\n // Listener for onPointerLeave and onBlur on the trigger element\n const onLeaveTrigger = React.useCallback((ev)=>{\n let delay = state.hideDelay;\n if (ev.type === 'blur') {\n // Hide immediately when losing focus\n delay = 0;\n ignoreNextFocusEventRef.current = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) === ev.target;\n }\n setDelayTimeout(()=>{\n setVisible(false, ev);\n }, delay);\n ev.persist(); // Persist the event since the setVisible call will happen asynchronously\n }, [\n setDelayTimeout,\n setVisible,\n state.hideDelay,\n targetDocument\n ]);\n // Cancel the hide timer when the mouse or focus enters the tooltip, and restart it when the mouse or focus leaves.\n // This keeps the tooltip visible when the mouse is moved over it, or it has focus within.\n state.content.onPointerEnter = mergeCallbacks(state.content.onPointerEnter, clearDelayTimeout);\n state.content.onPointerLeave = mergeCallbacks(state.content.onPointerLeave, onLeaveTrigger);\n state.content.onFocus = mergeCallbacks(state.content.onFocus, clearDelayTimeout);\n state.content.onBlur = mergeCallbacks(state.content.onBlur, onLeaveTrigger);\n const child = getTriggerChild(children);\n const triggerAriaProps = {};\n if (relationship === 'label') {\n // aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.\n if (typeof state.content.children === 'string') {\n triggerAriaProps['aria-label'] = state.content.children;\n } else {\n triggerAriaProps['aria-labelledby'] = state.content.id;\n // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element\n state.shouldRenderTooltip = true;\n }\n } else if (relationship === 'description') {\n triggerAriaProps['aria-describedby'] = state.content.id;\n // Always render the tooltip even if hidden, so that aria-describedby refers to a valid element\n state.shouldRenderTooltip = true;\n }\n // Don't render the Tooltip in SSR to avoid hydration errors\n if (isServerSideRender) {\n state.shouldRenderTooltip = false;\n }\n const childTargetRef = useMergedRefs(child === null || child === void 0 ? void 0 : child.ref, targetRef);\n // Apply the trigger props to the child, either by calling the render function, or cloning with the new props\n state.children = applyTriggerPropsToChildren(children, {\n ...triggerAriaProps,\n ...child === null || child === void 0 ? void 0 : child.props,\n // If the target prop is not provided, attach targetRef to the trigger element's ref prop\n ref: positioningOptions.target === undefined ? childTargetRef : child === null || child === void 0 ? void 0 : child.ref,\n onPointerEnter: useEventCallback(mergeCallbacks(child === null || child === void 0 ? void 0 : (_child_props = child.props) === null || _child_props === void 0 ? void 0 : _child_props.onPointerEnter, onEnterTrigger)),\n onPointerLeave: useEventCallback(mergeCallbacks(child === null || child === void 0 ? void 0 : (_child_props1 = child.props) === null || _child_props1 === void 0 ? void 0 : _child_props1.onPointerLeave, onLeaveTrigger)),\n onFocus: useEventCallback(mergeCallbacks(child === null || child === void 0 ? void 0 : (_child_props2 = child.props) === null || _child_props2 === void 0 ? void 0 : _child_props2.onFocus, onEnterTrigger)),\n onBlur: useEventCallback(mergeCallbacks(child === null || child === void 0 ? void 0 : (_child_props3 = child.props) === null || _child_props3 === void 0 ? void 0 : _child_props3.onBlur, onLeaveTrigger))\n });\n return state;\n};\n"],"names":["useTooltip_unstable","props","_child_props","_child_props1","_child_props2","_child_props3","context","useTooltipVisibility","isServerSideRender","useIsSSR","targetDocument","useFluent","setDelayTimeout","clearDelayTimeout","useTimeout","appearance","children","content","withArrow","positioning","onVisibleChange","relationship","showDelay","hideDelay","mountNode","visible","setVisibleInternal","useControllableState","state","initialState","setVisible","React","useCallback","newVisible","ev","oldVisible","shouldRenderTooltip","components","slot","always","defaultProps","role","elementType","id","useId","positioningOptions","enabled","arrowPadding","tooltipBorderRadius","position","align","offset","resolvePositioningShorthand","mergeArrowOffset","arrowHeight","targetRef","containerRef","arrowRef","usePositioning","ref","useMergedRefs","useIsomorphicLayoutEffect","_context_visibleTooltip","thisTooltip","hide","visibleTooltip","onDocumentKeyDown","key","Escape","stopPropagation","addEventListener","capture","undefined","removeEventListener","ignoreNextFocusEventRef","useRef","onEnterTrigger","type","current","delay","persist","onLeaveTrigger","activeElement","target","onPointerEnter","mergeCallbacks","onPointerLeave","onFocus","onBlur","child","getTriggerChild","triggerAriaProps","childTargetRef","applyTriggerPropsToChildren","useEventCallback"],"mappings":";;;;+BAaiBA;;aAAAA;;;6DAbM;kCACuD;qCACyB;gCAC2F;2BACjJ;8BAC1B;AAQZ,MAAMA,sBAAsB,CAACC,QAAQ;IAC5C,IAAIC,cAAcC,eAAeC,eAAeC;IAChD,MAAMC,UAAUC,IAAAA,kDAAoB;IACpC,MAAMC,qBAAqBC,IAAAA,wBAAQ;IACnC,MAAM,EAAEC,eAAc,EAAG,GAAGC,IAAAA,uCAAS;IACrC,MAAM,CAACC,iBAAiBC,kBAAkB,GAAGC,IAAAA,0BAAU;IACvD,MAAM,EAAEC,YAAY,SAAQ,EAAGC,SAAQ,EAAGC,QAAO,EAAGC,WAAW,KAAK,CAAA,EAAGC,aAAa,QAAO,EAAGC,gBAAe,EAAGC,aAAY,EAAGC,WAAW,IAAG,EAAGC,WAAW,IAAG,EAAGC,UAAS,EAAG,GAAGvB;IAChL,MAAM,CAACwB,SAASC,mBAAmB,GAAGC,IAAAA,oCAAoB,EAAC;QACvDC,OAAO3B,MAAMwB,OAAO;QACpBI,cAAc,KAAK;IACvB;IACA,MAAMC,aAAaC,OAAMC,WAAW,CAAC,CAACC,YAAYC,KAAK;QACnDrB;QACAa,mBAAmB,CAACS,aAAa;YAC7B,IAAIF,eAAeE,YAAY;gBAC3Bf,oBAAoB,IAAI,IAAIA,oBAAoB,KAAK,IAAI,KAAK,IAAIA,gBAAgBc,IAAI;oBAClFT,SAASQ;gBACb,EAAE;YACN,CAAC;YACD,OAAOA;QACX;IACJ,GAAG;QACCpB;QACAa;QACAN;KACH;IACD,MAAMQ,QAAQ;QACVV;QACAC;QACAG;QACAC;QACAF;QACAI;QACAW,qBAAqBX;QACrBV;QACAS;QACA,QAAQ;QACRa,YAAY;YACRpB,SAAS;QACb;QACAA,SAASqB,oB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CAAgB,EAACT,IAAAA,8BAAc,EAACI,UAAU,IAAI,IAAIA,UAAU,KAAK,IAAI,KAAK,IAAI,AAACpF,CAAAA,gBAAgBoF,MAAMxF,KAAK,AAAD,MAAO,IAAI,IAAII,kBAAkB,KAAK,IAAI,KAAK,IAAIA,cAAcmF,MAAM,EAAEP;IAC9L;IACA,OAAOrD;AACX"}
|
1
|
+
{"version":3,"sources":["useTooltip.js"],"sourcesContent":["import * as React from 'react';\nimport { mergeArrowOffset, resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport { useTooltipVisibility_unstable as useTooltipVisibility, useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { applyTriggerPropsToChildren, useControllableState, useId, useIsomorphicLayoutEffect, useIsSSR, useMergedRefs, useTimeout, getTriggerChild, mergeCallbacks, useEventCallback, slot } from '@fluentui/react-utilities';\nimport { arrowHeight, tooltipBorderRadius } from './private/constants';\nimport { Escape } from '@fluentui/keyboard-keys';\n/**\n * Create the state required to render Tooltip.\n *\n * The returned state can be modified with hooks such as useTooltipStyles_unstable,\n * before being passed to renderTooltip_unstable.\n *\n * @param props - props from this instance of Tooltip\n */ export const useTooltip_unstable = (props)=>{\n var _child_props, _child_props1, _child_props2, _child_props3;\n const context = useTooltipVisibility();\n const isServerSideRender = useIsSSR();\n const { targetDocument } = useFluent();\n const [setDelayTimeout, clearDelayTimeout] = useTimeout();\n const { appearance ='normal' , children , content , withArrow =false , positioning ='above' , onVisibleChange , relationship , showDelay =250 , hideDelay =250 , mountNode } = props;\n const [visible, setVisibleInternal] = useControllableState({\n state: props.visible,\n initialState: false\n });\n const setVisible = React.useCallback((ev, data)=>{\n clearDelayTimeout();\n setVisibleInternal((oldVisible)=>{\n if (data.visible !== oldVisible) {\n onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev, data);\n }\n return data.visible;\n });\n }, [\n clearDelayTimeout,\n setVisibleInternal,\n onVisibleChange\n ]);\n const state = {\n withArrow,\n positioning,\n showDelay,\n hideDelay,\n relationship,\n visible,\n shouldRenderTooltip: visible,\n appearance,\n mountNode,\n // Slots\n components: {\n content: 'div'\n },\n content: slot.always(content, {\n defaultProps: {\n role: 'tooltip'\n },\n elementType: 'div'\n })\n };\n state.content.id = useId('tooltip-', state.content.id);\n const positioningOptions = {\n enabled: state.visible,\n arrowPadding: 2 * tooltipBorderRadius,\n position: 'above',\n align: 'center',\n offset: 4,\n ...resolvePositioningShorthand(state.positioning)\n };\n if (state.withArrow) {\n positioningOptions.offset = mergeArrowOffset(positioningOptions.offset, arrowHeight);\n }\n const { targetRef , containerRef , arrowRef } = usePositioning(positioningOptions);\n state.content.ref = useMergedRefs(state.content.ref, containerRef);\n state.arrowRef = arrowRef;\n // When this tooltip is visible, hide any other tooltips, and register it\n // as the visibleTooltip with the TooltipContext.\n // Also add a listener on document to hide the tooltip if Escape is pressed\n useIsomorphicLayoutEffect(()=>{\n if (visible) {\n var _context_visibleTooltip;\n const thisTooltip = {\n hide: (ev)=>setVisible(undefined, {\n visible: false,\n documentKeyboardEvent: ev\n })\n };\n (_context_visibleTooltip = context.visibleTooltip) === null || _context_visibleTooltip === void 0 ? void 0 : _context_visibleTooltip.hide();\n context.visibleTooltip = thisTooltip;\n const onDocumentKeyDown = (ev)=>{\n if (ev.key === Escape) {\n thisTooltip.hide(ev);\n // stop propagation to avoid conflicting with other elements that listen for `Escape`\n // e,g: Dialog, Popover, Menu\n ev.stopPropagation();\n }\n };\n targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('keydown', onDocumentKeyDown, {\n // As this event is added at targeted document,\n // we need to capture the event to be sure keydown handling from tooltip happens first\n capture: true\n });\n return ()=>{\n if (context.visibleTooltip === thisTooltip) {\n context.visibleTooltip = undefined;\n }\n targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('keydown', onDocumentKeyDown, {\n capture: true\n });\n };\n }\n }, [\n context,\n targetDocument,\n visible,\n setVisible\n ]);\n // The focused element gets a blur event when the document loses focus\n // (e.g. switching tabs in the browser), but we don't want to show the\n // tooltip again when the document gets focus back. Handle this case by\n // checking if the blurred element is still the document's activeElement.\n // See https://github.com/microsoft/fluentui/issues/13541\n const ignoreNextFocusEventRef = React.useRef(false);\n // Listener for onPointerEnter and onFocus on the trigger element\n const onEnterTrigger = React.useCallback((ev)=>{\n if (ev.type === 'focus' && ignoreNextFocusEventRef.current) {\n ignoreNextFocusEventRef.current = false;\n return;\n }\n // Show immediately if another tooltip is already visible\n const delay = context.visibleTooltip ? 0 : state.showDelay;\n setDelayTimeout(()=>{\n setVisible(ev, {\n visible: true\n });\n }, delay);\n ev.persist(); // Persist the event since the setVisible call will happen asynchronously\n }, [\n setDelayTimeout,\n setVisible,\n state.showDelay,\n context\n ]);\n // Listener for onPointerLeave and onBlur on the trigger element\n const onLeaveTrigger = React.useCallback((ev)=>{\n let delay = state.hideDelay;\n if (ev.type === 'blur') {\n // Hide immediately when losing focus\n delay = 0;\n ignoreNextFocusEventRef.current = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) === ev.target;\n }\n setDelayTimeout(()=>{\n setVisible(ev, {\n visible: false\n });\n }, delay);\n ev.persist(); // Persist the event since the setVisible call will happen asynchronously\n }, [\n setDelayTimeout,\n setVisible,\n state.hideDelay,\n targetDocument\n ]);\n // Cancel the hide timer when the mouse or focus enters the tooltip, and restart it when the mouse or focus leaves.\n // This keeps the tooltip visible when the mouse is moved over it, or it has focus within.\n state.content.onPointerEnter = mergeCallbacks(state.content.onPointerEnter, clearDelayTimeout);\n state.content.onPointerLeave = mergeCallbacks(state.content.onPointerLeave, onLeaveTrigger);\n state.content.onFocus = mergeCallbacks(state.content.onFocus, clearDelayTimeout);\n state.content.onBlur = mergeCallbacks(state.content.onBlur, onLeaveTrigger);\n const child = getTriggerChild(children);\n const triggerAriaProps = {};\n if (relationship === 'label') {\n // aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.\n if (typeof state.content.children === 'string') {\n triggerAriaProps['aria-label'] = state.content.children;\n } else {\n triggerAriaProps['aria-labelledby'] = state.content.id;\n // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element\n state.shouldRenderTooltip = true;\n }\n } else if (relationship === 'description') {\n triggerAriaProps['aria-describedby'] = state.content.id;\n // Always render the tooltip even if hidden, so that aria-describedby refers to a valid element\n state.shouldRenderTooltip = true;\n }\n // Don't render the Tooltip in SSR to avoid hydration errors\n if (isServerSideRender) {\n state.shouldRenderTooltip = false;\n }\n const childTargetRef = useMergedRefs(child === null || child === void 0 ? void 0 : child.ref, targetRef);\n // Apply the trigger props to the child, either by calling the render function, or cloning with the new props\n state.children = applyTriggerPropsToChildren(children, {\n ...triggerAriaProps,\n ...child === null || child === void 0 ? void 0 : child.props,\n // If the target prop is not provided, attach targetRef to the trigger element's ref prop\n ref: positioningOptions.target === undefined ? childTargetRef : child === null || child === void 0 ? void 0 : child.ref,\n onPointerEnter: useEventCallback(mergeCallbacks(child === null || child === void 0 ? void 0 : (_child_props = child.props) === null || _child_props === void 0 ? void 0 : _child_props.onPointerEnter, onEnterTrigger)),\n onPointerLeave: useEventCallback(mergeCallbacks(child === null || child === void 0 ? void 0 : (_child_props1 = child.props) === null || _child_props1 === void 0 ? void 0 : _child_props1.onPointerLeave, onLeaveTrigger)),\n onFocus: useEventCallback(mergeCallbacks(child === null || child === void 0 ? void 0 : (_child_props2 = child.props) === null || _child_props2 === void 0 ? void 0 : _child_props2.onFocus, onEnterTrigger)),\n onBlur: useEventCallback(mergeCallbacks(child === null || child === void 0 ? void 0 : (_child_props3 = child.props) === null || _child_props3 === void 0 ? void 0 : _child_props3.onBlur, onLeaveTrigger))\n });\n return state;\n};\n"],"names":["useTooltip_unstable","props","_child_props","_child_props1","_child_props2","_child_props3","context","useTooltipVisibility","isServerSideRender","useIsSSR","targetDocument","useFluent","setDelayTimeout","clearDelayTimeout","useTimeout","appearance","children","content","withArrow","positioning","onVisibleChange","relationship","showDelay","hideDelay","mountNode","visible","setVisibleInternal","useControllableState","state","initialState","setVisible","React","useCallback","ev","data","oldVisible","shouldRenderTooltip","components","slot","always","defaultProps","role","elementType","id","useId","positioningOptions","enabled","arrowPadding","tooltipBorderRadius","position","align","offset","resolvePositioningShorthand","mergeArrowOffset","arrowHeight","targetRef","containerRef","arrowRef","usePositioning","ref","useMergedRefs","useIsomorphicLayoutEffect","_context_visibleTooltip","thisTooltip","hide","undefined","documentKeyboardEvent","visibleTooltip","onDocumentKeyDown","key","Escape","stopPropagation","addEventListener","capture","removeEventListener","ignoreNextFocusEventRef","useRef","onEnterTrigger","type","current","delay","persist","onLeaveTrigger","activeElement","target","onPointerEnter","mergeCallbacks","onPointerLeave","onFocus","onBlur","child","getTriggerChild","triggerAriaProps","childTargetRef","applyTriggerPropsToChildren","useEventCallback"],"mappings":";;;;+BAaiBA;;aAAAA;;;6DAbM;kCACuD;qCACyB;gCAC2F;2BACjJ;8BAC1B;AAQZ,MAAMA,sBAAsB,CAACC,QAAQ;IAC5C,IAAIC,cAAcC,eAAeC,eAAeC;IAChD,MAAMC,UAAUC,IAAAA,kDAAoB;IACpC,MAAMC,qBAAqBC,IAAAA,wBAAQ;IACnC,MAAM,EAAEC,eAAc,EAAG,GAAGC,IAAAA,uCAAS;IACrC,MAAM,CAACC,iBAAiBC,kBAAkB,GAAGC,IAAAA,0BAAU;IACvD,MAAM,EAAEC,YAAY,SAAQ,EAAGC,SAAQ,EAAGC,QAAO,EAAGC,WAAW,KAAK,CAAA,EAAGC,aAAa,QAAO,EAAGC,gBAAe,EAAGC,aAAY,EAAGC,WAAW,IAAG,EAAGC,WAAW,IAAG,EAAGC,UAAS,EAAG,GAAGvB;IAChL,MAAM,CAACwB,SAASC,mBAAmB,GAAGC,IAAAA,oCAAoB,EAAC;QACvDC,OAAO3B,MAAMwB,OAAO;QACpBI,cAAc,KAAK;IACvB;IACA,MAAMC,aAAaC,OAAMC,WAAW,CAAC,CAACC,IAAIC,OAAO;QAC7CrB;QACAa,mBAAmB,CAACS,aAA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Q,IAAAA,gCAAgB,EAACT,IAAAA,8BAAc,EAACI,UAAU,IAAI,IAAIA,UAAU,KAAK,IAAI,KAAK,IAAI,AAACvF,CAAAA,gBAAgBuF,MAAMzF,KAAK,AAAD,MAAO,IAAI,IAAIE,kBAAkB,KAAK,IAAI,KAAK,IAAIA,cAAcoF,cAAc,EAAEL;QAC1MM,SAASO,IAAAA,gCAAgB,EAACT,IAAAA,8BAAc,EAACI,UAAU,IAAI,IAAIA,UAAU,KAAK,IAAI,KAAK,IAAI,AAACtF,CAAAA,gBAAgBsF,MAAMzF,KAAK,AAAD,MAAO,IAAI,IAAIG,kBAAkB,KAAK,IAAI,KAAK,IAAIA,cAAcoF,OAAO,EAAEX;QAC5LY,QAAQM,IAAAA,gCAAgB,EAACT,IAAAA,8BAAc,EAACI,UAAU,IAAI,IAAIA,UAAU,KAAK,IAAI,KAAK,IAAI,AAACrF,CAAAA,gBAAgBqF,MAAMzF,KAAK,AAAD,MAAO,IAAI,IAAII,kBAAkB,KAAK,IAAI,KAAK,IAAIA,cAAcoF,MAAM,EAAEP;IAC9L;IACA,OAAOtD;AACX"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-tooltip",
|
3
|
-
"version": "9.
|
3
|
+
"version": "9.3.0",
|
4
4
|
"description": "React components for building web experiences",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -34,12 +34,12 @@
|
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
36
|
"@fluentui/keyboard-keys": "^9.0.3",
|
37
|
-
"@fluentui/react-jsx-runtime": "^9.0.
|
38
|
-
"@fluentui/react-portal": "^9.3.
|
39
|
-
"@fluentui/react-positioning": "^9.9.
|
37
|
+
"@fluentui/react-jsx-runtime": "^9.0.2",
|
38
|
+
"@fluentui/react-portal": "^9.3.9",
|
39
|
+
"@fluentui/react-positioning": "^9.9.7",
|
40
40
|
"@fluentui/react-shared-contexts": "^9.7.2",
|
41
41
|
"@fluentui/react-theme": "^9.1.11",
|
42
|
-
"@fluentui/react-utilities": "^9.
|
42
|
+
"@fluentui/react-utilities": "^9.12.0",
|
43
43
|
"@griffel/react": "^1.5.14",
|
44
44
|
"@swc/helpers": "^0.4.14"
|
45
45
|
},
|