@fluentui/react-popover 0.0.0-nightlyff78d1e27a20220217.1 → 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +780 -20
- package/CHANGELOG.md +281 -82
- package/Spec.md +25 -5
- package/dist/{react-popover.d.ts → index.d.ts} +99 -53
- package/{lib → dist}/tsdoc-metadata.json +0 -0
- package/lib/components/Popover/Popover.js.map +1 -1
- package/lib/components/Popover/Popover.types.js.map +1 -1
- package/lib/components/Popover/constants.js +10 -0
- package/lib/components/Popover/constants.js.map +1 -0
- package/lib/components/Popover/renderPopover.js +23 -17
- package/lib/components/Popover/renderPopover.js.map +1 -1
- package/lib/components/Popover/usePopover.js +93 -18
- package/lib/components/Popover/usePopover.js.map +1 -1
- package/lib/components/PopoverSurface/PopoverSurface.js.map +1 -1
- package/lib/components/PopoverSurface/PopoverSurface.types.js.map +1 -1
- package/lib/components/PopoverSurface/renderPopoverSurface.js +9 -8
- package/lib/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
- package/lib/components/PopoverSurface/usePopoverSurface.js +8 -16
- package/lib/components/PopoverSurface/usePopoverSurface.js.map +1 -1
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js +24 -22
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
- package/lib/components/PopoverTrigger/PopoverTrigger.js.map +1 -1
- package/lib/components/PopoverTrigger/PopoverTrigger.types.js.map +1 -1
- package/lib/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -1
- package/lib/components/PopoverTrigger/usePopoverTrigger.js +4 -4
- package/lib/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/popoverContext.js +4 -1
- package/lib/popoverContext.js.map +1 -1
- package/lib-commonjs/components/Popover/Popover.js.map +1 -1
- package/lib-commonjs/components/Popover/constants.js +17 -0
- package/lib-commonjs/components/Popover/constants.js.map +1 -0
- package/lib-commonjs/components/Popover/renderPopover.js +23 -17
- package/lib-commonjs/components/Popover/renderPopover.js.map +1 -1
- package/lib-commonjs/components/Popover/usePopover.js +94 -17
- package/lib-commonjs/components/Popover/usePopover.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js +9 -8
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js +7 -16
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.js.map +1 -1
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js +25 -23
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.js.map +1 -1
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.js.map +1 -1
- package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.js.map +1 -1
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js +4 -4
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.js.map +1 -1
- package/lib-commonjs/index.js +92 -5
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/popoverContext.js +5 -2
- package/lib-commonjs/popoverContext.js.map +1 -1
- package/package.json +26 -28
- package/lib/Popover.d.ts +0 -1
- package/lib/PopoverSurface.d.ts +0 -1
- package/lib/PopoverTrigger.d.ts +0 -1
- package/lib/components/Popover/Popover.d.ts +0 -6
- package/lib/components/Popover/Popover.types.d.ts +0 -103
- package/lib/components/Popover/index.d.ts +0 -4
- package/lib/components/Popover/renderPopover.d.ts +0 -5
- package/lib/components/Popover/usePopover.d.ts +0 -10
- package/lib/components/PopoverSurface/PopoverSurface.d.ts +0 -6
- package/lib/components/PopoverSurface/PopoverSurface.types.d.ts +0 -21
- package/lib/components/PopoverSurface/index.d.ts +0 -5
- package/lib/components/PopoverSurface/renderPopoverSurface.d.ts +0 -5
- package/lib/components/PopoverSurface/usePopoverSurface.d.ts +0 -12
- package/lib/components/PopoverSurface/usePopoverSurfaceStyles.d.ts +0 -8
- package/lib/components/PopoverTrigger/PopoverTrigger.d.ts +0 -7
- package/lib/components/PopoverTrigger/PopoverTrigger.types.d.ts +0 -18
- package/lib/components/PopoverTrigger/index.d.ts +0 -4
- package/lib/components/PopoverTrigger/renderPopoverTrigger.d.ts +0 -5
- package/lib/components/PopoverTrigger/usePopoverTrigger.d.ts +0 -10
- package/lib/index.d.ts +0 -4
- package/lib/popoverContext.d.ts +0 -8
- package/lib-commonjs/Popover.d.ts +0 -1
- package/lib-commonjs/PopoverSurface.d.ts +0 -1
- package/lib-commonjs/PopoverTrigger.d.ts +0 -1
- package/lib-commonjs/components/Popover/Popover.d.ts +0 -6
- package/lib-commonjs/components/Popover/Popover.types.d.ts +0 -103
- package/lib-commonjs/components/Popover/index.d.ts +0 -4
- package/lib-commonjs/components/Popover/renderPopover.d.ts +0 -5
- package/lib-commonjs/components/Popover/usePopover.d.ts +0 -10
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.d.ts +0 -6
- package/lib-commonjs/components/PopoverSurface/PopoverSurface.types.d.ts +0 -21
- package/lib-commonjs/components/PopoverSurface/index.d.ts +0 -5
- package/lib-commonjs/components/PopoverSurface/renderPopoverSurface.d.ts +0 -5
- package/lib-commonjs/components/PopoverSurface/usePopoverSurface.d.ts +0 -12
- package/lib-commonjs/components/PopoverSurface/usePopoverSurfaceStyles.d.ts +0 -8
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.d.ts +0 -7
- package/lib-commonjs/components/PopoverTrigger/PopoverTrigger.types.d.ts +0 -18
- package/lib-commonjs/components/PopoverTrigger/index.d.ts +0 -4
- package/lib-commonjs/components/PopoverTrigger/renderPopoverTrigger.d.ts +0 -5
- package/lib-commonjs/components/PopoverTrigger/usePopoverTrigger.d.ts +0 -10
- package/lib-commonjs/index.d.ts +0 -4
- package/lib-commonjs/popoverContext.d.ts +0 -8
package/Spec.md
CHANGED
@@ -238,6 +238,11 @@ export type PopoverProps = {
|
|
238
238
|
*/
|
239
239
|
onOpenChange?: (e: OpenPopoverEvents, data: OpenEventData) => void;
|
240
240
|
|
241
|
+
/**
|
242
|
+
* Flag to open the Popover by hovering the trigger
|
243
|
+
*/
|
244
|
+
openOnHover?: boolean;
|
245
|
+
|
241
246
|
/**
|
242
247
|
* Anchor the popover to an element other than the trigger
|
243
248
|
*/
|
@@ -284,6 +289,16 @@ export type PopoverProps = {
|
|
284
289
|
* Do not render an arrow pointing to the target element. This is the `PopoverTrigger` unless `target` prop is used
|
285
290
|
*/
|
286
291
|
noArrow?: boolean;
|
292
|
+
|
293
|
+
/**
|
294
|
+
* Sets the delay for closing popover on mouse leave
|
295
|
+
*/
|
296
|
+
mouseLeaveDelay?: number;
|
297
|
+
|
298
|
+
/**
|
299
|
+
* Close when scrolling outside of it
|
300
|
+
*/
|
301
|
+
closeOnScroll?: boolean;
|
287
302
|
};
|
288
303
|
```
|
289
304
|
|
@@ -329,7 +344,7 @@ Default popover
|
|
329
344
|
|
330
345
|
// Expected Markup
|
331
346
|
<div id="container">
|
332
|
-
<button aria-
|
347
|
+
<button aria-expanded="false">Trigger</button>
|
333
348
|
</div>
|
334
349
|
|
335
350
|
// on document.body
|
@@ -355,7 +370,7 @@ Popover that traps focus
|
|
355
370
|
|
356
371
|
// Expected Markup
|
357
372
|
<div id="container">
|
358
|
-
<button aria-
|
373
|
+
<button aria-expanded="false">Trigger</button>
|
359
374
|
</div>
|
360
375
|
|
361
376
|
// on document.body
|
@@ -381,7 +396,7 @@ Inline popover
|
|
381
396
|
|
382
397
|
// Expected Markup
|
383
398
|
<div id="container">
|
384
|
-
<button aria-
|
399
|
+
<button aria-expanded="false">Trigger</button>
|
385
400
|
<div>
|
386
401
|
{/** content */}
|
387
402
|
</div>
|
@@ -445,6 +460,11 @@ The popover closes with the escape key when the trigger or popover content has f
|
|
445
460
|
|
446
461
|
The popover closes when a click happens outside the popover trigger or content.
|
447
462
|
|
463
|
+
#### Scroll outside
|
464
|
+
|
465
|
+
The context menu popover closes when scroll happens outside the popover trigger or content.
|
466
|
+
When popover is configured with `closeOnScroll`, popover closes when scroll happens outside the popover trigger or content.
|
467
|
+
|
448
468
|
### Focus trap
|
449
469
|
|
450
470
|
When the popover is configured to be a focus trap, focus the first focusable element inside the popover on open.
|
@@ -478,7 +498,7 @@ Accessible markup is divided into two scenarios:
|
|
478
498
|
|
479
499
|
```tsx
|
480
500
|
// Popover that does not trap focus
|
481
|
-
<button aria-
|
501
|
+
<button aria-expanded="false">Trigger</button>
|
482
502
|
<div role="complementary">
|
483
503
|
No focus trap
|
484
504
|
</div>
|
@@ -487,7 +507,7 @@ Accessible markup is divided into two scenarios:
|
|
487
507
|
<div aria-hidden="true" /> // other content
|
488
508
|
<div aria-hidden="true" /> // other content
|
489
509
|
<div aria-hidden="true" className='fui-provider'>
|
490
|
-
<button aria-
|
510
|
+
<button aria-expanded="false">Trigger</button>
|
491
511
|
</div>
|
492
512
|
|
493
513
|
<div role="dialog" aria-modal="true">
|
@@ -1,17 +1,21 @@
|
|
1
1
|
import type { ComponentProps } from '@fluentui/react-utilities';
|
2
2
|
import type { ComponentState } from '@fluentui/react-utilities';
|
3
|
-
import type { Context } from '@fluentui/react-context-selector';
|
4
3
|
import type { ContextSelector } from '@fluentui/react-context-selector';
|
4
|
+
import { FC } from 'react';
|
5
5
|
import type { FluentTriggerComponent } from '@fluentui/react-utilities';
|
6
6
|
import type { ForwardRefComponent } from '@fluentui/react-utilities';
|
7
7
|
import { JSXElementConstructor } from 'react';
|
8
|
-
import type { PopperVirtualElement } from '@fluentui/react-positioning';
|
9
8
|
import type { PortalProps } from '@fluentui/react-portal';
|
10
9
|
import type { PositioningShorthand } from '@fluentui/react-positioning';
|
10
|
+
import type { PositioningVirtualElement } from '@fluentui/react-positioning';
|
11
|
+
import { Provider } from 'react';
|
12
|
+
import { ProviderProps } from 'react';
|
11
13
|
import * as React_2 from 'react';
|
12
14
|
import { ReactElement } from 'react';
|
13
15
|
import type { Slot } from '@fluentui/react-utilities';
|
14
|
-
import type {
|
16
|
+
import type { SlotClassNames } from '@fluentui/react-utilities';
|
17
|
+
import type { UseModalAttributesOptions } from '@fluentui/react-tabster';
|
18
|
+
import type { usePositioningMouseTarget } from '@fluentui/react-positioning';
|
15
19
|
|
16
20
|
export declare const arrowHeights: Record<PopoverSize, number>;
|
17
21
|
|
@@ -25,76 +29,112 @@ export declare type OnOpenChangeData = {
|
|
25
29
|
/**
|
26
30
|
* The supported events that will trigger open/close of the menu
|
27
31
|
*/
|
28
|
-
export declare type OpenPopoverEvents = MouseEvent | TouchEvent | React_2.
|
32
|
+
export declare type OpenPopoverEvents = MouseEvent | TouchEvent | React_2.FocusEvent<HTMLElement> | React_2.KeyboardEvent<HTMLElement> | React_2.MouseEvent<HTMLElement>;
|
29
33
|
|
30
34
|
/**
|
31
35
|
* Wrapper component that manages state for a PopoverTrigger and a PopoverSurface components.
|
32
36
|
*/
|
33
37
|
export declare const Popover: React_2.FC<PopoverProps>;
|
34
38
|
|
35
|
-
|
39
|
+
/**
|
40
|
+
* Context shared between Popover and its children components
|
41
|
+
*/
|
42
|
+
export declare type PopoverContextValue = Pick<PopoverState, 'open' | 'toggleOpen' | 'setOpen' | 'triggerRef' | 'contentRef' | 'openOnHover' | 'openOnContext' | 'mountNode' | 'withArrow' | 'arrowRef' | 'size' | 'appearance' | 'trapFocus' | 'legacyTrapFocus' | 'inline'>;
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Popover Props
|
46
|
+
*/
|
47
|
+
export declare type PopoverProps = Pick<PortalProps, 'mountNode'> & {
|
36
48
|
/**
|
37
|
-
*
|
49
|
+
* A popover can appear styled with brand or inverted.
|
50
|
+
* When not specified, the default style is used.
|
38
51
|
*/
|
39
|
-
|
52
|
+
appearance?: 'brand' | 'inverted';
|
53
|
+
/**
|
54
|
+
* Can contain two children including {@link PopoverTrigger} and {@link PopoverSurface}.
|
55
|
+
* Alternatively can only contain {@link PopoverSurface} if using a custom `target`.
|
56
|
+
*/
|
57
|
+
children: [JSX.Element, JSX.Element] | JSX.Element;
|
58
|
+
/**
|
59
|
+
* Close when scroll outside of it
|
60
|
+
*
|
61
|
+
* @default false
|
62
|
+
*/
|
63
|
+
closeOnScroll?: boolean;
|
40
64
|
/**
|
41
65
|
* Used to set the initial open state of the Popover in uncontrolled mode
|
66
|
+
*
|
67
|
+
* @default false
|
42
68
|
*/
|
43
69
|
defaultOpen?: boolean;
|
70
|
+
/**
|
71
|
+
* Popovers are rendered out of DOM order on `document.body` by default, use this to render the popover in DOM order
|
72
|
+
*
|
73
|
+
* @default false
|
74
|
+
*/
|
75
|
+
inline?: boolean;
|
76
|
+
/**
|
77
|
+
* Sets the delay for closing popover on mouse leave
|
78
|
+
*/
|
79
|
+
mouseLeaveDelay?: number;
|
80
|
+
/**
|
81
|
+
* Display an arrow pointing to the target.
|
82
|
+
*
|
83
|
+
* @default false
|
84
|
+
*/
|
85
|
+
withArrow?: boolean;
|
44
86
|
/**
|
45
87
|
* Call back when the component requests to change value
|
46
88
|
* The `open` value is used as a hint when directly controlling the component
|
47
89
|
*/
|
48
90
|
onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void;
|
49
91
|
/**
|
50
|
-
*
|
92
|
+
* Controls the opening of the Popover
|
93
|
+
*
|
94
|
+
* @default false
|
51
95
|
*/
|
52
|
-
|
96
|
+
open?: boolean;
|
53
97
|
/**
|
54
98
|
* Flag to open the Popover as a context menu. Disables all other interactions
|
99
|
+
*
|
100
|
+
* @default false
|
55
101
|
*/
|
56
102
|
openOnContext?: boolean;
|
57
103
|
/**
|
58
|
-
*
|
104
|
+
* Flag to open the Popover by hovering the trigger
|
105
|
+
*
|
106
|
+
* @default false
|
59
107
|
*/
|
60
|
-
|
108
|
+
openOnHover?: boolean;
|
109
|
+
/**
|
110
|
+
* Configures the position of the Popover
|
111
|
+
*/
|
112
|
+
positioning?: PositioningShorthand;
|
61
113
|
/**
|
62
114
|
* Determines popover padding and arrow size
|
115
|
+
*
|
63
116
|
* @default medium
|
64
117
|
*/
|
65
118
|
size?: PopoverSize;
|
66
|
-
/**
|
67
|
-
* A popover can appear styled with brand or inverted.
|
68
|
-
* When not specified, the default style is used.
|
69
|
-
*/
|
70
|
-
appearance?: 'brand' | 'inverted';
|
71
119
|
/**
|
72
120
|
* Should trap focus
|
121
|
+
*
|
122
|
+
* @default false
|
73
123
|
*/
|
74
|
-
trapFocus?:
|
124
|
+
trapFocus?: UseModalAttributesOptions['trapFocus'];
|
75
125
|
/**
|
76
|
-
*
|
126
|
+
* Must be used with the `trapFocus` prop
|
127
|
+
* Enables older Fluent UI focus trap behavior where the user
|
128
|
+
* cannot tab into the window outside of the document. This is now
|
129
|
+
* non-standard behavior according to the [HTML dialog spec](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/showModal)
|
130
|
+
* where the focus trap involves setting outside elements inert.
|
131
|
+
*
|
132
|
+
* @default false
|
77
133
|
*/
|
78
|
-
|
134
|
+
legacyTrapFocus?: UseModalAttributesOptions['legacyTrapFocus'];
|
79
135
|
};
|
80
136
|
|
81
|
-
export declare const
|
82
|
-
|
83
|
-
/**
|
84
|
-
* Context shared between Popover and its children components
|
85
|
-
*/
|
86
|
-
export declare type PopoverContextValue = Pick<PopoverState, 'open' | 'setOpen' | 'triggerRef' | 'contentRef' | 'openOnHover' | 'openOnContext' | 'mountNode' | 'noArrow' | 'arrowRef' | 'size' | 'appearance' | 'trapFocus'>;
|
87
|
-
|
88
|
-
/**
|
89
|
-
* Popover Props
|
90
|
-
*/
|
91
|
-
export declare type PopoverProps = Partial<PopoverCommons> & {
|
92
|
-
/**
|
93
|
-
* Can contain two children including {@link PopoverTrigger} and {@link PopoverSurface}.
|
94
|
-
* Alternatively can only contain {@link PopoverSurface} if using a custom `target`.
|
95
|
-
*/
|
96
|
-
children: [JSX.Element, JSX.Element] | JSX.Element;
|
97
|
-
};
|
137
|
+
export declare const PopoverProvider: Provider<PopoverContextValue> & FC<ProviderProps<PopoverContextValue>>;
|
98
138
|
|
99
139
|
/**
|
100
140
|
* Determines popover padding and arrow size
|
@@ -104,32 +144,38 @@ export declare type PopoverSize = 'small' | 'medium' | 'large';
|
|
104
144
|
/**
|
105
145
|
* Popover State
|
106
146
|
*/
|
107
|
-
export declare type PopoverState =
|
108
|
-
/**
|
109
|
-
* Callback to open/close the Popover
|
110
|
-
*/
|
111
|
-
setOpen: (e: OpenPopoverEvents, open: boolean) => void;
|
147
|
+
export declare type PopoverState = Pick<PopoverProps, 'appearance' | 'mountNode' | 'onOpenChange' | 'openOnContext' | 'openOnHover' | 'trapFocus' | 'withArrow' | 'legacyTrapFocus'> & Required<Pick<PopoverProps, 'inline' | 'open'>> & Pick<PopoverProps, 'children'> & {
|
112
148
|
/**
|
113
|
-
* Ref of the
|
149
|
+
* Ref of the pointing arrow
|
114
150
|
*/
|
115
|
-
|
151
|
+
arrowRef: React_2.MutableRefObject<HTMLDivElement | null>;
|
116
152
|
/**
|
117
153
|
* Ref of the PopoverSurface
|
118
154
|
*/
|
119
155
|
contentRef: React_2.MutableRefObject<HTMLElement | null>;
|
120
|
-
/**
|
121
|
-
* Ref of the pointing arrow
|
122
|
-
*/
|
123
|
-
arrowRef: React_2.MutableRefObject<HTMLDivElement | null>;
|
124
156
|
/**
|
125
157
|
* Anchors the popper to the mouse click for context events
|
126
158
|
*/
|
127
|
-
contextTarget:
|
159
|
+
contextTarget: PositioningVirtualElement | undefined;
|
160
|
+
popoverSurface: React_2.ReactElement | undefined;
|
161
|
+
popoverTrigger: React_2.ReactElement | undefined;
|
128
162
|
/**
|
129
163
|
* A callback to set the target of the popper to the mouse click for context events
|
130
164
|
*/
|
131
|
-
setContextTarget: ReturnType<typeof
|
165
|
+
setContextTarget: ReturnType<typeof usePositioningMouseTarget>[1];
|
166
|
+
/**
|
167
|
+
* Callback to open/close the Popover
|
168
|
+
*/
|
169
|
+
setOpen: (e: OpenPopoverEvents, open: boolean) => void;
|
132
170
|
size: NonNullable<PopoverProps['size']>;
|
171
|
+
/**
|
172
|
+
* Callback to toggle the open state of the Popover
|
173
|
+
*/
|
174
|
+
toggleOpen: (e: OpenPopoverEvents) => void;
|
175
|
+
/**
|
176
|
+
* Ref of the PopoverTrigger
|
177
|
+
*/
|
178
|
+
triggerRef: React_2.MutableRefObject<HTMLElement | null>;
|
133
179
|
};
|
134
180
|
|
135
181
|
/**
|
@@ -137,7 +183,7 @@ export declare type PopoverState = PopoverCommons & Pick<PopoverProps, 'children
|
|
137
183
|
*/
|
138
184
|
export declare const PopoverSurface: ForwardRefComponent<PopoverSurfaceProps>;
|
139
185
|
|
140
|
-
export declare const
|
186
|
+
export declare const popoverSurfaceClassNames: SlotClassNames<PopoverSurfaceSlots>;
|
141
187
|
|
142
188
|
/**
|
143
189
|
* PopoverSurface Props
|
@@ -154,7 +200,7 @@ export declare type PopoverSurfaceSlots = {
|
|
154
200
|
/**
|
155
201
|
* PopoverSurface State
|
156
202
|
*/
|
157
|
-
export declare type PopoverSurfaceState = ComponentState<PopoverSurfaceSlots> & Pick<PopoverContextValue, '
|
203
|
+
export declare type PopoverSurfaceState = ComponentState<PopoverSurfaceSlots> & Pick<PopoverContextValue, 'appearance' | 'arrowRef' | 'inline' | 'mountNode' | 'size' | 'withArrow'> & {
|
158
204
|
/**
|
159
205
|
* CSS class for the arrow element
|
160
206
|
*/
|
@@ -168,7 +214,7 @@ export declare const PopoverTrigger: React_2.FC<PopoverTriggerProps> & FluentTri
|
|
168
214
|
|
169
215
|
export declare type PopoverTriggerChildProps = {
|
170
216
|
ref?: React_2.Ref<never>;
|
171
|
-
} & Pick<React_2.HTMLAttributes<HTMLElement>, 'aria-
|
217
|
+
} & Pick<React_2.HTMLAttributes<HTMLElement>, 'aria-expanded' | 'onClick' | 'onContextMenu' | 'onKeyDown' | 'onMouseEnter' | 'onMouseLeave'>;
|
172
218
|
|
173
219
|
/**
|
174
220
|
* PopoverTrigger Props
|
@@ -194,7 +240,7 @@ export declare const renderPopover_unstable: (state: PopoverState) => JSX.Elemen
|
|
194
240
|
/**
|
195
241
|
* Render the final JSX of PopoverSurface
|
196
242
|
*/
|
197
|
-
export declare const renderPopoverSurface_unstable: (state: PopoverSurfaceState) => JSX.Element
|
243
|
+
export declare const renderPopoverSurface_unstable: (state: PopoverSurfaceState) => JSX.Element;
|
198
244
|
|
199
245
|
/**
|
200
246
|
* Render the final JSX of PopoverTrigger
|
File without changes
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["components/Popover/Popover.tsx"],"names":[],"mappings":"AACA,SAAS,mBAAT,QAAoC,cAApC;AACA,SAAS,sBAAT,QAAuC,iBAAvC;AAGA;;AAEG;;AACH,OAAO,MAAM,OAAO,GAA2B,KAAK,IAAG;
|
1
|
+
{"version":3,"sources":["components/Popover/Popover.tsx"],"names":[],"mappings":"AACA,SAAS,mBAAT,QAAoC,cAApC;AACA,SAAS,sBAAT,QAAuC,iBAAvC;AAGA;;AAEG;;AACH,OAAO,MAAM,OAAO,GAA2B,KAAK,IAAG;EACrD,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAD,CAAjC;EAEA,OAAO,sBAAsB,CAAC,KAAD,CAA7B;AACD,CAJM;AAMP,OAAO,CAAC,WAAR,GAAsB,SAAtB","sourcesContent":["import * as React from 'react';\nimport { usePopover_unstable } from './usePopover';\nimport { renderPopover_unstable } from './renderPopover';\nimport type { PopoverProps } from './Popover.types';\n\n/**\n * Wrapper component that manages state for a PopoverTrigger and a PopoverSurface components.\n */\nexport const Popover: React.FC<PopoverProps> = props => {\n const state = usePopover_unstable(props);\n\n return renderPopover_unstable(state);\n};\n\nPopover.displayName = 'Popover';\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Popover.types.js","sourceRoot":"../src/","sources":["components/Popover/Popover.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type {
|
1
|
+
{"version":3,"file":"Popover.types.js","sourceRoot":"../src/","sources":["components/Popover/Popover.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type {\n PositioningVirtualElement,\n PositioningShorthand,\n usePositioningMouseTarget,\n} from '@fluentui/react-positioning';\nimport type { PortalProps } from '@fluentui/react-portal';\nimport type { UseModalAttributesOptions } from '@fluentui/react-tabster';\n\n/**\n * Determines popover padding and arrow size\n */\nexport type PopoverSize = 'small' | 'medium' | 'large';\n\n/**\n * Popover Props\n */\nexport type PopoverProps = Pick<PortalProps, 'mountNode'> & {\n /**\n * A popover can appear styled with brand or inverted.\n * When not specified, the default style is used.\n */\n appearance?: 'brand' | 'inverted';\n\n /**\n * Can contain two children including {@link PopoverTrigger} and {@link PopoverSurface}.\n * Alternatively can only contain {@link PopoverSurface} if using a custom `target`.\n */\n children: [JSX.Element, JSX.Element] | JSX.Element;\n\n /**\n * Close when scroll outside of it\n *\n * @default false\n */\n closeOnScroll?: boolean;\n\n /**\n * Used to set the initial open state of the Popover in uncontrolled mode\n *\n * @default false\n */\n defaultOpen?: boolean;\n\n /**\n * Popovers are rendered out of DOM order on `document.body` by default, use this to render the popover in DOM order\n *\n * @default false\n */\n inline?: boolean;\n\n /**\n * Sets the delay for closing popover on mouse leave\n */\n mouseLeaveDelay?: number;\n\n /**\n * Display an arrow pointing to the target.\n *\n * @default false\n */\n withArrow?: boolean;\n\n /**\n * Call back when the component requests to change value\n * The `open` value is used as a hint when directly controlling the component\n */\n onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void;\n\n /**\n * Controls the opening of the Popover\n *\n * @default false\n */\n open?: boolean;\n\n /**\n * Flag to open the Popover as a context menu. Disables all other interactions\n *\n * @default false\n */\n openOnContext?: boolean;\n\n /**\n * Flag to open the Popover by hovering the trigger\n *\n * @default false\n */\n openOnHover?: boolean;\n\n /**\n * Configures the position of the Popover\n */\n positioning?: PositioningShorthand;\n\n /**\n * Determines popover padding and arrow size\n *\n * @default medium\n */\n size?: PopoverSize;\n\n /**\n * Should trap focus\n *\n * @default false\n */\n trapFocus?: UseModalAttributesOptions['trapFocus'];\n\n /**\n * Must be used with the `trapFocus` prop\n * Enables older Fluent UI focus trap behavior where the user\n * cannot tab into the window outside of the document. This is now\n * non-standard behavior according to the [HTML dialog spec](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/showModal)\n * where the focus trap involves setting outside elements inert.\n *\n * @default false\n */\n legacyTrapFocus?: UseModalAttributesOptions['legacyTrapFocus'];\n};\n\n/**\n * Popover State\n */\nexport type PopoverState = Pick<\n PopoverProps,\n | 'appearance'\n | 'mountNode'\n | 'onOpenChange'\n | 'openOnContext'\n | 'openOnHover'\n | 'trapFocus'\n | 'withArrow'\n | 'legacyTrapFocus'\n> &\n Required<Pick<PopoverProps, 'inline' | 'open'>> &\n Pick<PopoverProps, 'children'> & {\n /**\n * Ref of the pointing arrow\n */\n arrowRef: React.MutableRefObject<HTMLDivElement | null>;\n\n /**\n * Ref of the PopoverSurface\n */\n contentRef: React.MutableRefObject<HTMLElement | null>;\n\n /**\n * Anchors the popper to the mouse click for context events\n */\n contextTarget: PositioningVirtualElement | undefined;\n\n popoverSurface: React.ReactElement | undefined;\n\n popoverTrigger: React.ReactElement | undefined;\n\n /**\n * A callback to set the target of the popper to the mouse click for context events\n */\n setContextTarget: ReturnType<typeof usePositioningMouseTarget>[1];\n\n /**\n * Callback to open/close the Popover\n */\n setOpen: (e: OpenPopoverEvents, open: boolean) => void;\n\n size: NonNullable<PopoverProps['size']>;\n\n /**\n * Callback to toggle the open state of the Popover\n */\n toggleOpen: (e: OpenPopoverEvents) => void;\n\n /**\n * Ref of the PopoverTrigger\n */\n triggerRef: React.MutableRefObject<HTMLElement | null>;\n };\n\n/**\n * Data attached to open/close events\n */\nexport type OnOpenChangeData = { open: boolean };\n\n/**\n * The supported events that will trigger open/close of the menu\n */\nexport type OpenPopoverEvents =\n | MouseEvent\n | TouchEvent\n | React.FocusEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.MouseEvent<HTMLElement>;\n"]}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* @internal
|
3
|
+
* The default value of the tooltip's border radius (borderRadiusMedium).
|
4
|
+
*
|
5
|
+
* Unfortunately, Popper requires it to be specified as a variable instead of using CSS.
|
6
|
+
* While we could use getComputedStyle, that adds a performance penalty for something that
|
7
|
+
* will likely never change.
|
8
|
+
*/
|
9
|
+
export const popoverSurfaceBorderRadius = 4;
|
10
|
+
//# sourceMappingURL=constants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"../src/","sources":["components/Popover/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC","sourcesContent":["/**\n * @internal\n * The default value of the tooltip's border radius (borderRadiusMedium).\n *\n * Unfortunately, Popper requires it to be specified as a variable instead of using CSS.\n * While we could use getComputedStyle, that adds a performance penalty for something that\n * will likely never change.\n */\nexport const popoverSurfaceBorderRadius = 4;\n"]}
|
@@ -6,34 +6,40 @@ import { PopoverContext } from '../../popoverContext';
|
|
6
6
|
|
7
7
|
export const renderPopover_unstable = state => {
|
8
8
|
const {
|
9
|
-
|
10
|
-
|
11
|
-
triggerRef,
|
9
|
+
appearance,
|
10
|
+
arrowRef,
|
12
11
|
contentRef,
|
12
|
+
inline,
|
13
|
+
mountNode,
|
14
|
+
open,
|
13
15
|
openOnContext,
|
14
16
|
openOnHover,
|
15
|
-
|
16
|
-
arrowRef,
|
17
|
+
setOpen,
|
17
18
|
size,
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
toggleOpen,
|
20
|
+
trapFocus,
|
21
|
+
triggerRef,
|
22
|
+
withArrow,
|
23
|
+
legacyTrapFocus
|
21
24
|
} = state;
|
22
25
|
return /*#__PURE__*/React.createElement(PopoverContext.Provider, {
|
23
26
|
value: {
|
27
|
+
appearance,
|
28
|
+
arrowRef,
|
29
|
+
contentRef,
|
30
|
+
inline,
|
31
|
+
mountNode,
|
24
32
|
open,
|
33
|
+
openOnContext,
|
34
|
+
openOnHover,
|
25
35
|
setOpen,
|
36
|
+
toggleOpen,
|
26
37
|
triggerRef,
|
27
|
-
contentRef,
|
28
|
-
openOnHover,
|
29
|
-
openOnContext,
|
30
|
-
mountNode,
|
31
|
-
arrowRef,
|
32
38
|
size,
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
trapFocus,
|
40
|
+
legacyTrapFocus,
|
41
|
+
withArrow
|
36
42
|
}
|
37
|
-
}, state.
|
43
|
+
}, state.popoverTrigger, state.open && state.popoverSurface);
|
38
44
|
};
|
39
45
|
//# sourceMappingURL=renderPopover.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["components/Popover/renderPopover.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,cAAT,QAA+B,sBAA/B;AAGA;;AAEG;;AACH,OAAO,MAAM,sBAAsB,GAAI,KAAD,IAAwB;
|
1
|
+
{"version":3,"sources":["components/Popover/renderPopover.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,cAAT,QAA+B,sBAA/B;AAGA;;AAEG;;AACH,OAAO,MAAM,sBAAsB,GAAI,KAAD,IAAwB;EAC5D,MAAM;IACJ,UADI;IAEJ,QAFI;IAGJ,UAHI;IAIJ,MAJI;IAKJ,SALI;IAMJ,IANI;IAOJ,aAPI;IAQJ,WARI;IASJ,OATI;IAUJ,IAVI;IAWJ,UAXI;IAYJ,SAZI;IAaJ,UAbI;IAcJ,SAdI;IAeJ;EAfI,IAgBF,KAhBJ;EAkBA,oBACE,KAAA,CAAA,aAAA,CAAC,cAAc,CAAC,QAAhB,EAAwB;IACtB,KAAK,EAAE;MACL,UADK;MAEL,QAFK;MAGL,UAHK;MAIL,MAJK;MAKL,SALK;MAML,IANK;MAOL,aAPK;MAQL,WARK;MASL,OATK;MAUL,UAVK;MAWL,UAXK;MAYL,IAZK;MAaL,SAbK;MAcL,eAdK;MAeL;IAfK;EADe,CAAxB,EAmBG,KAAK,CAAC,cAnBT,EAoBG,KAAK,CAAC,IAAN,IAAc,KAAK,CAAC,cApBvB,CADF;AAwBD,CA3CM","sourcesContent":["import * as React from 'react';\nimport { PopoverContext } from '../../popoverContext';\nimport type { PopoverState } from './Popover.types';\n\n/**\n * Render the final JSX of Popover\n */\nexport const renderPopover_unstable = (state: PopoverState) => {\n const {\n appearance,\n arrowRef,\n contentRef,\n inline,\n mountNode,\n open,\n openOnContext,\n openOnHover,\n setOpen,\n size,\n toggleOpen,\n trapFocus,\n triggerRef,\n withArrow,\n legacyTrapFocus,\n } = state;\n\n return (\n <PopoverContext.Provider\n value={{\n appearance,\n arrowRef,\n contentRef,\n inline,\n mountNode,\n open,\n openOnContext,\n openOnHover,\n setOpen,\n toggleOpen,\n triggerRef,\n size,\n trapFocus,\n legacyTrapFocus,\n withArrow,\n }}\n >\n {state.popoverTrigger}\n {state.open && state.popoverSurface}\n </PopoverContext.Provider>\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -1,9 +1,11 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { useControllableState, useEventCallback, useOnClickOutside, useOnScrollOutside } from '@fluentui/react-utilities';
|
3
|
-
import { useFluent } from '@fluentui/react-shared-contexts';
|
4
|
-
import {
|
3
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
4
|
+
import { usePositioning, resolvePositioningShorthand, mergeArrowOffset, usePositioningMouseTarget } from '@fluentui/react-positioning';
|
5
5
|
import { elementContains } from '@fluentui/react-portal';
|
6
|
+
import { useFocusFinders } from '@fluentui/react-tabster';
|
6
7
|
import { arrowHeights } from '../PopoverSurface/index';
|
8
|
+
import { popoverSurfaceBorderRadius } from './constants';
|
7
9
|
/**
|
8
10
|
* Create the state required to render Popover.
|
9
11
|
*
|
@@ -14,15 +16,73 @@ import { arrowHeights } from '../PopoverSurface/index';
|
|
14
16
|
*/
|
15
17
|
|
16
18
|
export const usePopover_unstable = props => {
|
17
|
-
|
19
|
+
var _a;
|
20
|
+
|
21
|
+
const [contextTarget, setContextTarget] = usePositioningMouseTarget();
|
18
22
|
const initialState = {
|
19
23
|
size: 'medium',
|
20
24
|
contextTarget,
|
21
25
|
setContextTarget,
|
22
26
|
...props
|
23
27
|
};
|
24
|
-
const
|
25
|
-
|
28
|
+
const children = React.Children.toArray(props.children);
|
29
|
+
|
30
|
+
if (process.env.NODE_ENV !== 'production') {
|
31
|
+
if (children.length === 0) {
|
32
|
+
// eslint-disable-next-line no-console
|
33
|
+
console.warn('Popover must contain at least one child');
|
34
|
+
}
|
35
|
+
|
36
|
+
if (children.length > 2) {
|
37
|
+
// eslint-disable-next-line no-console
|
38
|
+
console.warn('Popover must contain at most two children');
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
let popoverTrigger = undefined;
|
43
|
+
let popoverSurface = undefined;
|
44
|
+
|
45
|
+
if (children.length === 2) {
|
46
|
+
popoverTrigger = children[0];
|
47
|
+
popoverSurface = children[1];
|
48
|
+
} else if (children.length === 1) {
|
49
|
+
popoverSurface = children[0];
|
50
|
+
}
|
51
|
+
|
52
|
+
const [open, setOpenState] = useOpenState(initialState);
|
53
|
+
const setOpenTimeoutRef = React.useRef(0);
|
54
|
+
const setOpen = useEventCallback((e, shouldOpen) => {
|
55
|
+
var _a;
|
56
|
+
|
57
|
+
clearTimeout(setOpenTimeoutRef.current);
|
58
|
+
|
59
|
+
if (!(e instanceof Event) && e.persist) {
|
60
|
+
// < React 17 still uses pooled synthetic events
|
61
|
+
e.persist();
|
62
|
+
}
|
63
|
+
|
64
|
+
if (e.type === 'mouseleave') {
|
65
|
+
// FIXME leaking Node timeout type
|
66
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
67
|
+
// @ts-ignore
|
68
|
+
setOpenTimeoutRef.current = setTimeout(() => {
|
69
|
+
setOpenState(e, shouldOpen);
|
70
|
+
}, (_a = props.mouseLeaveDelay) !== null && _a !== void 0 ? _a : 500);
|
71
|
+
} else {
|
72
|
+
setOpenState(e, shouldOpen);
|
73
|
+
}
|
74
|
+
}); // Clear timeout on unmount
|
75
|
+
// Setting state after a component unmounts can cause memory leaks
|
76
|
+
|
77
|
+
React.useEffect(() => {
|
78
|
+
return () => {
|
79
|
+
clearTimeout(setOpenTimeoutRef.current);
|
80
|
+
};
|
81
|
+
}, []);
|
82
|
+
const toggleOpen = React.useCallback(e => {
|
83
|
+
setOpen(e, !open);
|
84
|
+
}, [setOpen, open]);
|
85
|
+
const positioningRefs = usePopoverRefs(initialState);
|
26
86
|
const {
|
27
87
|
targetDocument
|
28
88
|
} = useFluent();
|
@@ -30,23 +90,37 @@ export const usePopover_unstable = props => {
|
|
30
90
|
contains: elementContains,
|
31
91
|
element: targetDocument,
|
32
92
|
callback: ev => setOpen(ev, false),
|
33
|
-
refs: [
|
93
|
+
refs: [positioningRefs.triggerRef, positioningRefs.contentRef],
|
34
94
|
disabled: !open
|
35
|
-
});
|
95
|
+
}); // only close on scroll for context, or when closeOnScroll is specified
|
96
|
+
|
97
|
+
const closeOnScroll = initialState.openOnContext || initialState.closeOnScroll;
|
36
98
|
useOnScrollOutside({
|
37
99
|
contains: elementContains,
|
38
100
|
element: targetDocument,
|
39
101
|
callback: ev => setOpen(ev, false),
|
40
|
-
refs: [
|
41
|
-
disabled: !open || !
|
42
|
-
|
102
|
+
refs: [positioningRefs.triggerRef, positioningRefs.contentRef],
|
103
|
+
disabled: !open || !closeOnScroll
|
43
104
|
});
|
105
|
+
const {
|
106
|
+
findFirstFocusable
|
107
|
+
} = useFocusFinders();
|
108
|
+
React.useEffect(() => {
|
109
|
+
if (open && positioningRefs.contentRef.current) {
|
110
|
+
const firstFocusable = findFirstFocusable(positioningRefs.contentRef.current);
|
111
|
+
firstFocusable === null || firstFocusable === void 0 ? void 0 : firstFocusable.focus();
|
112
|
+
}
|
113
|
+
}, [findFirstFocusable, open, positioningRefs.contentRef]);
|
44
114
|
return { ...initialState,
|
45
|
-
...
|
115
|
+
...positioningRefs,
|
116
|
+
popoverTrigger,
|
117
|
+
popoverSurface,
|
46
118
|
open,
|
47
119
|
setOpen,
|
120
|
+
toggleOpen,
|
48
121
|
setContextTarget,
|
49
|
-
contextTarget
|
122
|
+
contextTarget,
|
123
|
+
inline: (_a = props.inline) !== null && _a !== void 0 ? _a : false
|
50
124
|
};
|
51
125
|
};
|
52
126
|
/**
|
@@ -95,26 +169,27 @@ function useOpenState(state) {
|
|
95
169
|
|
96
170
|
|
97
171
|
function usePopoverRefs(state) {
|
98
|
-
const
|
172
|
+
const positioningOptions = {
|
99
173
|
position: 'above',
|
100
174
|
align: 'center',
|
175
|
+
arrowPadding: 2 * popoverSurfaceBorderRadius,
|
101
176
|
target: state.openOnContext ? state.contextTarget : undefined,
|
102
177
|
...resolvePositioningShorthand(state.positioning)
|
103
178
|
}; // no reason to render arrow when covering the target
|
104
179
|
|
105
|
-
if (
|
106
|
-
state.
|
180
|
+
if (positioningOptions.coverTarget) {
|
181
|
+
state.withArrow = false;
|
107
182
|
}
|
108
183
|
|
109
|
-
if (
|
110
|
-
|
184
|
+
if (state.withArrow) {
|
185
|
+
positioningOptions.offset = mergeArrowOffset(positioningOptions.offset, arrowHeights[state.size]);
|
111
186
|
}
|
112
187
|
|
113
188
|
const {
|
114
189
|
targetRef: triggerRef,
|
115
190
|
containerRef: contentRef,
|
116
191
|
arrowRef
|
117
|
-
} =
|
192
|
+
} = usePositioning(positioningOptions);
|
118
193
|
return {
|
119
194
|
triggerRef,
|
120
195
|
contentRef,
|