@oxy.so/bloom 21.5.0 → 21.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/adoption-matrix.mdx +3 -3
- package/docs/dropdown-menu.mdx +11 -0
- package/docs/task-catalog.json +1 -1
- package/docs/task-catalog.mdx +1 -1
- package/lib/commonjs/dropdown-menu/DropdownMenu.js +86 -6
- package/lib/commonjs/dropdown-menu/DropdownMenu.js.map +1 -1
- package/lib/commonjs/dropdown-menu/context.js.map +1 -1
- package/lib/commonjs/floating/PopupPanel.js +17 -1
- package/lib/commonjs/floating/PopupPanel.js.map +1 -1
- package/lib/commonjs/floating/TriggerSlot.js +4 -0
- package/lib/commonjs/floating/TriggerSlot.js.map +1 -1
- package/lib/module/dropdown-menu/DropdownMenu.js +88 -6
- package/lib/module/dropdown-menu/DropdownMenu.js.map +1 -1
- package/lib/module/dropdown-menu/context.js.map +1 -1
- package/lib/module/floating/PopupPanel.js +17 -1
- package/lib/module/floating/PopupPanel.js.map +1 -1
- package/lib/module/floating/TriggerSlot.js +4 -0
- package/lib/module/floating/TriggerSlot.js.map +1 -1
- package/lib/typescript/commonjs/dropdown-menu/DropdownMenu.d.ts +7 -1
- package/lib/typescript/commonjs/dropdown-menu/DropdownMenu.d.ts.map +1 -1
- package/lib/typescript/commonjs/dropdown-menu/context.d.ts +2 -0
- package/lib/typescript/commonjs/dropdown-menu/context.d.ts.map +1 -1
- package/lib/typescript/commonjs/floating/PopupPanel.d.ts +17 -4
- package/lib/typescript/commonjs/floating/PopupPanel.d.ts.map +1 -1
- package/lib/typescript/commonjs/floating/TriggerSlot.d.ts +7 -1
- package/lib/typescript/commonjs/floating/TriggerSlot.d.ts.map +1 -1
- package/lib/typescript/module/dropdown-menu/DropdownMenu.d.ts +7 -1
- package/lib/typescript/module/dropdown-menu/DropdownMenu.d.ts.map +1 -1
- package/lib/typescript/module/dropdown-menu/context.d.ts +2 -0
- package/lib/typescript/module/dropdown-menu/context.d.ts.map +1 -1
- package/lib/typescript/module/floating/PopupPanel.d.ts +17 -4
- package/lib/typescript/module/floating/PopupPanel.d.ts.map +1 -1
- package/lib/typescript/module/floating/TriggerSlot.d.ts +7 -1
- package/lib/typescript/module/floating/TriggerSlot.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/dropdown-menu/DropdownMenu.tsx +94 -6
- package/src/dropdown-menu/context.ts +2 -0
- package/src/floating/PopupPanel.tsx +41 -2
- package/src/floating/TriggerSlot.tsx +10 -0
|
@@ -18,9 +18,15 @@ import { BloomScope } from '../appearance';
|
|
|
18
18
|
*
|
|
19
19
|
* The rows come from `floating/menu-rows`, the same set `ContextMenu` and
|
|
20
20
|
* `Menubar` publish under their own prefixes.
|
|
21
|
+
*
|
|
22
|
+
* `activation="hover"` in a platform popup (a desktop with a pointer): the pointer resting on
|
|
23
|
+
* the trigger for `openDelay` opens the menu, as a long press does; leaving the trigger and the
|
|
24
|
+
* panel closes it after `closeDelay`, unless it is back on either by then or a key was used in the
|
|
25
|
+
* panel (the keyboard then has it, as on the web). The popup goes on tracking the pointer over
|
|
26
|
+
* the trigger while it holds its grab (`trackingRef`). The trigger's own press is unchanged.
|
|
21
27
|
*/
|
|
22
28
|
import React, { useCallback, useMemo, useRef, type ComponentRef } from 'react';
|
|
23
|
-
import type { View } from 'react-native';
|
|
29
|
+
import type { PointerEvent, View } from 'react-native';
|
|
24
30
|
|
|
25
31
|
import { SheetShell } from '../dialog/SheetShell';
|
|
26
32
|
import { PopupPanel } from '../floating/PopupPanel';
|
|
@@ -34,6 +40,8 @@ import { TriggerSlot } from '../floating/TriggerSlot';
|
|
|
34
40
|
import { useMenuFocusIntent, useOpenFocus } from '../floating/menu-keyboard';
|
|
35
41
|
import { useSheetOpenBridge } from '../floating/use-sheet-open-bridge';
|
|
36
42
|
import { useControllableState } from '../hooks/use-controllable-state';
|
|
43
|
+
import { HOVER_CARD_CLOSE_DELAY, HOVER_CARD_OPEN_DELAY } from '../hover-card/constants';
|
|
44
|
+
import { useHoverIntent } from '../hover-card/use-hover-intent';
|
|
37
45
|
import { DropdownMenuProvider, useDropdownMenu } from './context';
|
|
38
46
|
import type {
|
|
39
47
|
DropdownMenuContentProps,
|
|
@@ -41,6 +49,11 @@ import type {
|
|
|
41
49
|
DropdownMenuTriggerProps,
|
|
42
50
|
} from './types';
|
|
43
51
|
import { useCommonMessages } from '../locale/common-messages';
|
|
52
|
+
import { CONTEXT_MENU_MESSAGES } from '../context-menu/messages';
|
|
53
|
+
import { useMessages } from '../locale/messages';
|
|
54
|
+
|
|
55
|
+
/** React Native's standard accessibility action for a long press (TalkBack's, a reader's). */
|
|
56
|
+
const LONG_PRESS_ACTION = 'longpress';
|
|
44
57
|
|
|
45
58
|
export function DropdownMenu({
|
|
46
59
|
children,
|
|
@@ -48,6 +61,8 @@ export function DropdownMenu({
|
|
|
48
61
|
defaultOpen = false,
|
|
49
62
|
onOpenChange,
|
|
50
63
|
activation = 'click',
|
|
64
|
+
openDelay = HOVER_CARD_OPEN_DELAY,
|
|
65
|
+
closeDelay = HOVER_CARD_CLOSE_DELAY,
|
|
51
66
|
openFocus,
|
|
52
67
|
}: DropdownMenuProps) {
|
|
53
68
|
const [isOpen, setOpen] = useControllableState<boolean>({
|
|
@@ -59,19 +74,51 @@ export function DropdownMenu({
|
|
|
59
74
|
// An open from the owner's keys starts with a row active in a platform popup, as on a Mac.
|
|
60
75
|
const focusIntent = useMenuFocusIntent();
|
|
61
76
|
useOpenFocus(focusIntent, isOpen, openFocus);
|
|
77
|
+
const intent = useHoverIntent(isOpen, setOpen, openDelay, closeDelay);
|
|
78
|
+
// Opened by the pointer resting on the trigger, and none of its keys used since: the pointer
|
|
79
|
+
// leaving closes it. Opened any other way, only a choice, Escape or a press outside does.
|
|
80
|
+
const byHover = useRef(false);
|
|
81
|
+
const latestOpen = useRef(isOpen);
|
|
82
|
+
latestOpen.current = isOpen;
|
|
62
83
|
const primaryOpen = useRef(false);
|
|
63
84
|
const setMenuOpen = useCallback(
|
|
64
85
|
(next: boolean) => {
|
|
65
|
-
if (
|
|
86
|
+
if (next && primaryOpen.current) return;
|
|
87
|
+
intent.hold();
|
|
88
|
+
byHover.current = false;
|
|
89
|
+
setOpen(next);
|
|
66
90
|
},
|
|
67
|
-
[setOpen],
|
|
91
|
+
[intent, setOpen],
|
|
68
92
|
);
|
|
69
93
|
const onPrimaryOpenChange = useCallback(
|
|
70
94
|
(next: boolean) => {
|
|
71
95
|
primaryOpen.current = next;
|
|
72
|
-
if (next)
|
|
96
|
+
if (next) setMenuOpen(false);
|
|
73
97
|
},
|
|
74
|
-
[
|
|
98
|
+
[setMenuOpen],
|
|
99
|
+
);
|
|
100
|
+
const hover = useMemo(
|
|
101
|
+
() => ({
|
|
102
|
+
enter: () => {
|
|
103
|
+
if (primaryOpen.current) return;
|
|
104
|
+
if (!latestOpen.current) byHover.current = true;
|
|
105
|
+
intent.show();
|
|
106
|
+
},
|
|
107
|
+
show: () => {
|
|
108
|
+
if (!primaryOpen.current) intent.show();
|
|
109
|
+
},
|
|
110
|
+
hide: () => {
|
|
111
|
+
// A pending open is dropped; an open menu closes only if hover opened it.
|
|
112
|
+
if (!latestOpen.current || byHover.current) intent.hide();
|
|
113
|
+
},
|
|
114
|
+
hold: intent.hold,
|
|
115
|
+
dismiss: () => setMenuOpen(false),
|
|
116
|
+
key: () => {
|
|
117
|
+
byHover.current = false;
|
|
118
|
+
intent.hold();
|
|
119
|
+
},
|
|
120
|
+
}),
|
|
121
|
+
[intent, setMenuOpen],
|
|
75
122
|
);
|
|
76
123
|
const value = useMemo(
|
|
77
124
|
() => ({
|
|
@@ -80,9 +127,10 @@ export function DropdownMenu({
|
|
|
80
127
|
anchorRef,
|
|
81
128
|
focusIntent,
|
|
82
129
|
activation,
|
|
130
|
+
...(activation === 'hover' ? { hover } : null),
|
|
83
131
|
onPrimaryOpenChange,
|
|
84
132
|
}),
|
|
85
|
-
[isOpen, setMenuOpen, focusIntent, activation, onPrimaryOpenChange],
|
|
133
|
+
[isOpen, setMenuOpen, focusIntent, activation, hover, onPrimaryOpenChange],
|
|
86
134
|
);
|
|
87
135
|
|
|
88
136
|
return <DropdownMenuProvider value={value}>{children}</DropdownMenuProvider>;
|
|
@@ -100,6 +148,20 @@ export function DropdownMenuTrigger({
|
|
|
100
148
|
restoreFocus,
|
|
101
149
|
}: DropdownMenuTriggerProps) {
|
|
102
150
|
const menu = useDropdownMenu();
|
|
151
|
+
// Hover opens it only where it is a desktop's popup: never a phone's sheet.
|
|
152
|
+
const hover = usePopupSurface() ? menu.hover : undefined;
|
|
153
|
+
// A menu that opens on hover opens from the screen reader as a long press opens it, by the
|
|
154
|
+
// trigger's `longpress` action ("Show menu"), as `ContextMenu`'s does.
|
|
155
|
+
const { messages } = useMessages(CONTEXT_MENU_MESSAGES);
|
|
156
|
+
const showMenu =
|
|
157
|
+
menu.activation === 'hover' && !disabled
|
|
158
|
+
? {
|
|
159
|
+
accessibilityActions: [{ name: LONG_PRESS_ACTION, label: messages.showMenu }],
|
|
160
|
+
onAccessibilityAction: (event: { nativeEvent: { actionName: string } }) => {
|
|
161
|
+
if (event.nativeEvent.actionName === LONG_PRESS_ACTION) menu.setOpen(true);
|
|
162
|
+
},
|
|
163
|
+
}
|
|
164
|
+
: null;
|
|
103
165
|
const primaryAction =
|
|
104
166
|
pressTrigger != null ||
|
|
105
167
|
(React.isValidElement<{ onPress?: unknown; href?: string }>(children) &&
|
|
@@ -112,12 +174,27 @@ export function DropdownMenuTrigger({
|
|
|
112
174
|
onPrimaryOpenChange={menu.onPrimaryOpenChange}
|
|
113
175
|
anchorRef={menu.anchorRef}
|
|
114
176
|
restoreFocus={restoreFocus}
|
|
177
|
+
onPointerEnter={
|
|
178
|
+
hover
|
|
179
|
+
? (event: PointerEvent) => {
|
|
180
|
+
if (pointerTypeOf(event) !== 'touch') hover.enter();
|
|
181
|
+
}
|
|
182
|
+
: undefined
|
|
183
|
+
}
|
|
184
|
+
onPointerLeave={
|
|
185
|
+
hover
|
|
186
|
+
? (event: PointerEvent) => {
|
|
187
|
+
if (pointerTypeOf(event) !== 'touch') hover.hide();
|
|
188
|
+
}
|
|
189
|
+
: undefined
|
|
190
|
+
}
|
|
115
191
|
className={className}
|
|
116
192
|
style={style}
|
|
117
193
|
testID={testID}
|
|
118
194
|
handle={{
|
|
119
195
|
onPress: () => menu.setOpen(menu.activation !== 'hover' || !primaryAction),
|
|
120
196
|
onLongPress: menu.activation === 'hover' ? () => menu.setOpen(true) : undefined,
|
|
197
|
+
...showMenu,
|
|
121
198
|
disabled,
|
|
122
199
|
accessibilityLabel: label,
|
|
123
200
|
accessibilityRole: menu.activation === 'hover' && asChild ? undefined : 'button',
|
|
@@ -174,6 +251,12 @@ export function DropdownMenuContent({
|
|
|
174
251
|
focusIntent={menu.focusIntent}
|
|
175
252
|
onDismiss={() => menu.setOpen(false)}
|
|
176
253
|
onClose={() => menu.setOpen(false)}
|
|
254
|
+
// Hover: the pointer over the trigger goes on reaching it while the popup is open, and
|
|
255
|
+
// the pointer on the panel or a key in it keeps the menu open.
|
|
256
|
+
trackingRef={menu.hover ? menu.anchorRef : undefined}
|
|
257
|
+
onPointerEnter={menu.hover?.hold}
|
|
258
|
+
onPointerLeave={menu.hover?.hide}
|
|
259
|
+
onKey={menu.hover?.key}
|
|
177
260
|
minWidth={minWidth}
|
|
178
261
|
maxWidth={maxWidth}
|
|
179
262
|
maxHeight={maxHeight}
|
|
@@ -208,6 +291,11 @@ export function DropdownMenuContent({
|
|
|
208
291
|
);
|
|
209
292
|
}
|
|
210
293
|
|
|
294
|
+
/** A pointer event's kind (`mouse`, `pen`, `touch`). */
|
|
295
|
+
function pointerTypeOf(event: PointerEvent): string | undefined {
|
|
296
|
+
return event.nativeEvent?.pointerType;
|
|
297
|
+
}
|
|
298
|
+
|
|
211
299
|
const rows = createMenuRows('DropdownMenu', createInlineMenuSub);
|
|
212
300
|
|
|
213
301
|
export const DropdownMenuItem = rows.Item;
|
|
@@ -20,6 +20,8 @@ export interface DropdownMenuContextValue extends OverlayShellContextValue {
|
|
|
20
20
|
hide: () => void;
|
|
21
21
|
hold: () => void;
|
|
22
22
|
dismiss: () => void;
|
|
23
|
+
/** A key used in the open panel (native): a menu opened by hover then stays open. */
|
|
24
|
+
key?: () => void;
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -17,7 +17,13 @@
|
|
|
17
17
|
import type React from 'react';
|
|
18
18
|
import { createContext, useContext, useEffect, useRef, useState } from 'react';
|
|
19
19
|
import type { ComponentRef, ComponentType, RefObject } from 'react';
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
type PointerEvent,
|
|
22
|
+
StyleSheet,
|
|
23
|
+
type View,
|
|
24
|
+
type StyleProp,
|
|
25
|
+
type ViewStyle,
|
|
26
|
+
} from 'react-native';
|
|
21
27
|
import { StyledView } from '../styles/styled-primitives';
|
|
22
28
|
import { SurfacePaint } from '../surface/SurfacePaint';
|
|
23
29
|
import type { PopupDismissReason, PopupSurfaceProps } from '../platform-surface/types';
|
|
@@ -71,12 +77,17 @@ export function PopupPanelSurface({
|
|
|
71
77
|
style,
|
|
72
78
|
panelRef,
|
|
73
79
|
edge = POPUP_PANEL_BORDER,
|
|
80
|
+
onPointerEnter,
|
|
81
|
+
onPointerLeave,
|
|
74
82
|
children,
|
|
75
83
|
}: {
|
|
76
84
|
className?: string;
|
|
77
85
|
style?: StyleProp<ViewStyle>;
|
|
78
86
|
panelRef?: React.Ref<ComponentRef<typeof View>>;
|
|
79
87
|
edge?: number;
|
|
88
|
+
/** The pointer coming onto the panel and leaving it: a hover menu stays open while it is on it. */
|
|
89
|
+
onPointerEnter?: (event: PointerEvent) => void;
|
|
90
|
+
onPointerLeave?: (event: PointerEvent) => void;
|
|
80
91
|
children?: React.ReactNode;
|
|
81
92
|
}) {
|
|
82
93
|
const palette = useMenuPalette();
|
|
@@ -86,6 +97,8 @@ export function PopupPanelSurface({
|
|
|
86
97
|
<StyledView
|
|
87
98
|
ref={panelRef}
|
|
88
99
|
className={className}
|
|
100
|
+
onPointerEnter={onPointerEnter}
|
|
101
|
+
onPointerLeave={onPointerLeave}
|
|
89
102
|
style={[
|
|
90
103
|
styles.panel,
|
|
91
104
|
{ borderWidth: edge, boxShadow: palette.shadow },
|
|
@@ -120,6 +133,8 @@ export function PopupPanelChrome({
|
|
|
120
133
|
className,
|
|
121
134
|
style,
|
|
122
135
|
panelRef,
|
|
136
|
+
onPointerEnter,
|
|
137
|
+
onPointerLeave,
|
|
123
138
|
children,
|
|
124
139
|
}: {
|
|
125
140
|
minWidth?: number;
|
|
@@ -128,12 +143,16 @@ export function PopupPanelChrome({
|
|
|
128
143
|
className?: string;
|
|
129
144
|
style?: StyleProp<ViewStyle>;
|
|
130
145
|
panelRef?: React.Ref<ComponentRef<typeof View>>;
|
|
146
|
+
onPointerEnter?: (event: PointerEvent) => void;
|
|
147
|
+
onPointerLeave?: (event: PointerEvent) => void;
|
|
131
148
|
children?: React.ReactNode;
|
|
132
149
|
}) {
|
|
133
150
|
const density = useMenuDensity();
|
|
134
151
|
return (
|
|
135
152
|
<PopupPanelSurface
|
|
136
153
|
panelRef={panelRef}
|
|
154
|
+
onPointerEnter={onPointerEnter}
|
|
155
|
+
onPointerLeave={onPointerLeave}
|
|
137
156
|
className={className}
|
|
138
157
|
style={[
|
|
139
158
|
// `MENU_WIDTH`, or a desktop's floor: there a menu is as wide as its widest row.
|
|
@@ -168,6 +187,14 @@ export interface PopupPanelProps extends FloatingPositionProps {
|
|
|
168
187
|
focusIntent?: MenuFocusIntent;
|
|
169
188
|
/** Given the panel's keyboard navigation (a menu bar asks it which arrows it takes). */
|
|
170
189
|
navigationRef?: React.MutableRefObject<PopupNavigation | null>;
|
|
190
|
+
/**
|
|
191
|
+
* The pointer coming onto the panel and leaving it, and a key pressed in it before its rows
|
|
192
|
+
* take it: a menu opened by hover stays open while the pointer is on it, and once its keys
|
|
193
|
+
* are used.
|
|
194
|
+
*/
|
|
195
|
+
onPointerEnter?: (event: PointerEvent) => void;
|
|
196
|
+
onPointerLeave?: (event: PointerEvent) => void;
|
|
197
|
+
onKey?: (key: string) => void;
|
|
171
198
|
minWidth?: number;
|
|
172
199
|
maxWidth?: number;
|
|
173
200
|
maxHeight?: number;
|
|
@@ -192,6 +219,9 @@ export function PopupPanel({
|
|
|
192
219
|
onClose,
|
|
193
220
|
focusIntent,
|
|
194
221
|
navigationRef,
|
|
222
|
+
onPointerEnter,
|
|
223
|
+
onPointerLeave,
|
|
224
|
+
onKey,
|
|
195
225
|
minWidth,
|
|
196
226
|
maxWidth,
|
|
197
227
|
maxHeight,
|
|
@@ -235,13 +265,22 @@ export function PopupPanel({
|
|
|
235
265
|
role={role}
|
|
236
266
|
label={label}
|
|
237
267
|
onDismiss={onDismiss}
|
|
238
|
-
onKey={
|
|
268
|
+
onKey={
|
|
269
|
+
onKey
|
|
270
|
+
? (key) => {
|
|
271
|
+
onKey(key);
|
|
272
|
+
navigation.onKey(key);
|
|
273
|
+
}
|
|
274
|
+
: navigation.onKey
|
|
275
|
+
}
|
|
239
276
|
testID={testID}
|
|
240
277
|
>
|
|
241
278
|
{/* The popup surface carries the content's role and label; labelling the panel too
|
|
242
279
|
would announce the menu's name twice. */}
|
|
243
280
|
<PopupPanelChrome
|
|
244
281
|
panelRef={panelRef}
|
|
282
|
+
onPointerEnter={onPointerEnter}
|
|
283
|
+
onPointerLeave={onPointerLeave}
|
|
245
284
|
minWidth={minWidth}
|
|
246
285
|
maxWidth={maxWidth}
|
|
247
286
|
maxHeight={maxHeight}
|
|
@@ -71,6 +71,12 @@ export interface TriggerSlotProps {
|
|
|
71
71
|
* while another of the bar's menus is open.
|
|
72
72
|
*/
|
|
73
73
|
onPointerMove?: (event: PointerEvent) => void;
|
|
74
|
+
/**
|
|
75
|
+
* The pointer coming onto the trigger and leaving it, heard on the wrapper: a menu that opens on
|
|
76
|
+
* hover (`DropdownMenu`'s `activation="hover"`) opens as the pointer rests on its trigger.
|
|
77
|
+
*/
|
|
78
|
+
onPointerEnter?: (event: PointerEvent) => void;
|
|
79
|
+
onPointerLeave?: (event: PointerEvent) => void;
|
|
74
80
|
/**
|
|
75
81
|
* Whether the trigger's surface is open, when the trigger does not say so
|
|
76
82
|
* itself through `aria-expanded`: a context menu's area is no disclosure, and
|
|
@@ -220,6 +226,8 @@ export function TriggerSlot({
|
|
|
220
226
|
anchorRef,
|
|
221
227
|
onPointerDown,
|
|
222
228
|
onPointerMove,
|
|
229
|
+
onPointerEnter,
|
|
230
|
+
onPointerLeave,
|
|
223
231
|
open,
|
|
224
232
|
restoreFocus = true,
|
|
225
233
|
className,
|
|
@@ -251,6 +259,8 @@ export function TriggerSlot({
|
|
|
251
259
|
collapsable={false}
|
|
252
260
|
onPointerDown={onPointerDown}
|
|
253
261
|
onPointerMove={onPointerMove}
|
|
262
|
+
onPointerEnter={onPointerEnter}
|
|
263
|
+
onPointerLeave={onPointerLeave}
|
|
254
264
|
className={className}
|
|
255
265
|
style={[styles.wrap, style]}
|
|
256
266
|
testID={testID}
|