@spaced-out/ui-design-system 0.6.33 → 0.6.35-beta.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/.cspell/custom-words.txt +9 -0
- package/CHANGELOG.md +14 -0
- package/lib/components/Menu/Menu.d.ts +71 -0
- package/lib/components/Menu/Menu.d.ts.map +1 -1
- package/lib/components/Menu/Menu.js +1028 -185
- package/lib/components/Menu/Menu.module.css +148 -27
- package/lib/components/Menu/MenuOptionButton.d.ts +23 -2
- package/lib/components/Menu/MenuOptionButton.d.ts.map +1 -1
- package/lib/components/Menu/MenuOptionButton.js +87 -38
- package/lib/components/Menu/index.d.ts +2 -0
- package/lib/components/Menu/index.d.ts.map +1 -1
- package/lib/components/Menu/index.js +22 -0
- package/lib/components/Menu/menuOptionId.d.ts +12 -0
- package/lib/components/Menu/menuOptionId.d.ts.map +1 -0
- package/lib/components/Menu/menuOptionId.js +18 -0
- package/lib/components/Menu/useMenuKeyboardNavigation.d.ts +93 -0
- package/lib/components/Menu/useMenuKeyboardNavigation.d.ts.map +1 -0
- package/lib/components/Menu/useMenuKeyboardNavigation.js +471 -0
- package/lib/components/Menu/useMenuTrigger.d.ts +183 -0
- package/lib/components/Menu/useMenuTrigger.d.ts.map +1 -0
- package/lib/components/Menu/useMenuTrigger.js +347 -0
- package/lib/components/TruncatedTextWithTooltip/TruncatedTextWithTooltip.d.ts.map +1 -1
- package/lib/components/TruncatedTextWithTooltip/TruncatedTextWithTooltip.js +66 -53
- package/lib/components/TruncatedTextWithTooltip/TruncatedTextWithTooltip.module.css +0 -3
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.d.ts.map +1 -1
- package/lib/hooks/index.js +11 -0
- package/lib/hooks/useInteractionModality/index.d.ts +2 -0
- package/lib/hooks/useInteractionModality/index.d.ts.map +1 -0
- package/lib/hooks/useInteractionModality/index.js +16 -0
- package/lib/hooks/useInteractionModality/useInteractionModality.d.ts +15 -0
- package/lib/hooks/useInteractionModality/useInteractionModality.d.ts.map +1 -0
- package/lib/hooks/useInteractionModality/useInteractionModality.js +103 -0
- package/lib/utils/click-away/click-away.d.ts +3 -0
- package/lib/utils/click-away/click-away.d.ts.map +1 -1
- package/lib/utils/click-away/click-away.js +49 -0
- package/mcp/package.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useMenuTrigger = exports.useComboboxMenuTrigger = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _Menu = require("./Menu");
|
|
9
|
+
var _menuOptionId = require("./menuOptionId");
|
|
10
|
+
var _useMenuKeyboardNavigation = require("./useMenuKeyboardNavigation");
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
|
+
/**
|
|
13
|
+
* Drop undefined-valued keys. The props these hooks return are spread AFTER the
|
|
14
|
+
* consumer's own `menu` props, and an own property holding `undefined` would
|
|
15
|
+
* erase a value the consumer set — `{...menu, ...{ariaLabel: undefined}}` has no
|
|
16
|
+
* label at all.
|
|
17
|
+
*/
|
|
18
|
+
const compact = obj => Object.fromEntries(Object.entries(obj).filter(_ref => {
|
|
19
|
+
let [, value] = _ref;
|
|
20
|
+
return value !== undefined;
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Wires a trigger to the Menu it opens.
|
|
25
|
+
*
|
|
26
|
+
* Three things have to live on the trigger rather than in Menu, because they
|
|
27
|
+
* exist while the menu does NOT: `aria-haspopup`, `aria-expanded="false"`, and
|
|
28
|
+
* the ArrowDown/ArrowUp that opens the popup in the first place. That is the
|
|
29
|
+
* floor — no Menu prop can supply them — so these hooks hand them over as props
|
|
30
|
+
* to spread instead, and own everything else: the ids, the tie between the
|
|
31
|
+
* trigger's name and the listbox, and the ref Menu focuses into on open.
|
|
32
|
+
*
|
|
33
|
+
* `useMenuTrigger` is for triggers whose popup options own focus — a button, a
|
|
34
|
+
* tab overflow chevron, an inline label — so arrows move real DOM focus.
|
|
35
|
+
* `useComboboxMenuTrigger` is for triggers that are text inputs, where focus
|
|
36
|
+
* stays put and the highlight is virtual (`aria-activedescendant`).
|
|
37
|
+
*
|
|
38
|
+
* `getTriggerProps` is a getter rather than a static object because open state
|
|
39
|
+
* belongs to the consumer's `ClickAway`, which exposes it through a render
|
|
40
|
+
* callback — where a hook cannot be called.
|
|
41
|
+
*
|
|
42
|
+
* const menuTrigger = useMenuTrigger({id: props.id, ariaLabel: menu?.ariaLabel});
|
|
43
|
+
* <ClickAway>
|
|
44
|
+
* {({isOpen, onOpen, clickAway}) => (
|
|
45
|
+
* <>
|
|
46
|
+
* <Button {...props} {...menuTrigger.getTriggerProps({isOpen, onOpen})} />
|
|
47
|
+
* {isOpen && <Menu {...menu} {...menuTrigger.menuProps} onTabOut={clickAway} />}
|
|
48
|
+
* </>
|
|
49
|
+
* )}
|
|
50
|
+
* </ClickAway>
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Generic in the trigger element so the returned handler matches whatever it is
|
|
55
|
+
* spread onto — inferred from the trigger's own `onKeyDown` where it has one.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
const useMenuTrigger = function () {
|
|
59
|
+
let {
|
|
60
|
+
id,
|
|
61
|
+
menuId: consumerMenuId,
|
|
62
|
+
ariaLabel,
|
|
63
|
+
ariaLabelledBy
|
|
64
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
65
|
+
const generatedMenuId = React.useId();
|
|
66
|
+
const generatedTriggerId = React.useId();
|
|
67
|
+
const menuId = consumerMenuId ?? generatedMenuId;
|
|
68
|
+
const triggerId = id ?? generatedTriggerId;
|
|
69
|
+
const initialFocusRef = React.useRef(null);
|
|
70
|
+
const getTriggerProps = _ref2 => {
|
|
71
|
+
let {
|
|
72
|
+
isOpen,
|
|
73
|
+
onOpen,
|
|
74
|
+
onKeyDown
|
|
75
|
+
} = _ref2;
|
|
76
|
+
return {
|
|
77
|
+
id: triggerId,
|
|
78
|
+
'aria-haspopup': 'listbox',
|
|
79
|
+
'aria-expanded': isOpen,
|
|
80
|
+
// Only while the listbox is actually rendered: an IDREF that resolves to
|
|
81
|
+
// nothing is an invalid value, not an empty one.
|
|
82
|
+
'aria-controls': isOpen ? menuId : undefined,
|
|
83
|
+
onKeyDown: event => {
|
|
84
|
+
onKeyDown?.(event);
|
|
85
|
+
// Opening on an arrow key is the trigger's job precisely because the menu
|
|
86
|
+
// does not exist yet to handle it. Leave the key alone if the trigger's
|
|
87
|
+
// own handler already claimed it.
|
|
88
|
+
if (event.defaultPrevented || isOpen) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
onOpen();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
getTriggerProps,
|
|
100
|
+
menuProps: compact({
|
|
101
|
+
menuId,
|
|
102
|
+
// An explicit label suppresses the idref, so the two never compete.
|
|
103
|
+
ariaLabelledBy: ariaLabel ? undefined : ariaLabelledBy ?? triggerId,
|
|
104
|
+
ariaLabel,
|
|
105
|
+
initialFocusRef
|
|
106
|
+
})
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Which of ARIA's two combobox patterns the trigger implements.
|
|
112
|
+
*
|
|
113
|
+
* - `select` — a read-only field standing in for a `<select>`. An option is
|
|
114
|
+
* highlighted as soon as the list opens, Space selects it (the field has no
|
|
115
|
+
* typing role), and Enter or Space opens the list in the first place.
|
|
116
|
+
* - `autocomplete` — an editable field that filters the list as you type.
|
|
117
|
+
* Nothing is highlighted until the user arrows to it (APG calls this manual
|
|
118
|
+
* selection: auto-highlighting would let Enter select something they never
|
|
119
|
+
* chose), Space types a space, and only the arrow keys open the list.
|
|
120
|
+
*/
|
|
121
|
+
exports.useMenuTrigger = useMenuTrigger;
|
|
122
|
+
/**
|
|
123
|
+
* Wires a COMBOBOX trigger — a text input — to the Menu it opens. Focus stays
|
|
124
|
+
* on the input and the highlight is virtual, reported through
|
|
125
|
+
* `aria-activedescendant`, because the input has to keep receiving the keys it
|
|
126
|
+
* filters with.
|
|
127
|
+
*
|
|
128
|
+
* Driving the highlight from outside Menu means owning the active option as
|
|
129
|
+
* state, and owning it means deriving the same option list, initial highlight
|
|
130
|
+
* and navigation list that Menu derives internally. Both combobox consumers had
|
|
131
|
+
* grown their own copies of all three; they come from Menu itself now.
|
|
132
|
+
*
|
|
133
|
+
* A menu that carries its own filter field (`menu.allowSearch`) inverts the
|
|
134
|
+
* model: navigation lives inside Menu, so the trigger stops driving it and
|
|
135
|
+
* hands over an `initialFocusRef` instead. Both shapes come out of this hook.
|
|
136
|
+
*/
|
|
137
|
+
const useComboboxMenuTrigger = _ref3 => {
|
|
138
|
+
let {
|
|
139
|
+
pattern = 'select',
|
|
140
|
+
menu,
|
|
141
|
+
options,
|
|
142
|
+
canOpen,
|
|
143
|
+
menuRef,
|
|
144
|
+
isOpen,
|
|
145
|
+
onSelectOption,
|
|
146
|
+
onClose,
|
|
147
|
+
focusTrigger,
|
|
148
|
+
triggerAriaLabelledBy,
|
|
149
|
+
triggerAriaLabel,
|
|
150
|
+
defaultAriaLabel = 'Options'
|
|
151
|
+
} = _ref3;
|
|
152
|
+
const generatedMenuId = React.useId();
|
|
153
|
+
// The consumer's own id wins: it is what their `aria-controls` elsewhere, or
|
|
154
|
+
// their tests, already point at.
|
|
155
|
+
const menuId = menu?.menuId ?? generatedMenuId;
|
|
156
|
+
const initialFocusRef = React.useRef(null);
|
|
157
|
+
const [activeOptionKey, setActiveOptionKey] = React.useState(null);
|
|
158
|
+
const isAutocomplete = pattern === 'autocomplete';
|
|
159
|
+
|
|
160
|
+
// A searchable menu drives navigation internally from its own filter field; a
|
|
161
|
+
// select-only menu is driven by this trigger instead, with focus never
|
|
162
|
+
// entering the listbox. An autocomplete trigger IS the filter field, so it
|
|
163
|
+
// always drives navigation itself.
|
|
164
|
+
const usesExternalNav = isAutocomplete || !menu?.allowSearch;
|
|
165
|
+
|
|
166
|
+
/** The options the keyboard navigates, whatever supplied them. */
|
|
167
|
+
const optionSource = React.useMemo(() => options ?? (menu ? (0, _Menu.getFlatOptions)(menu) : []), [options, menu]);
|
|
168
|
+
|
|
169
|
+
/*
|
|
170
|
+
* `listbox` is an accessible-name-required role, so the popup must be named.
|
|
171
|
+
* Best name first:
|
|
172
|
+
* 1. what the consumer said (`menu.ariaLabelledBy` / `menu.ariaLabel`),
|
|
173
|
+
* 2. whatever already labels the trigger — a field label is the most useful
|
|
174
|
+
* name there is,
|
|
175
|
+
* 3. a literal fallback. Deliberately NOT the placeholder: echoing
|
|
176
|
+
* "Select..." names the list after an instruction, not its contents.
|
|
177
|
+
* An explicit label suppresses the idref, since a listbox drops `aria-label`
|
|
178
|
+
* whenever `aria-labelledby` is present.
|
|
179
|
+
*/
|
|
180
|
+
const menuAriaLabelledBy = menu?.ariaLabelledBy ?? (menu?.ariaLabel ? undefined : triggerAriaLabelledBy);
|
|
181
|
+
const menuAriaLabel = menu?.ariaLabel ?? (menuAriaLabelledBy ? undefined : triggerAriaLabel ?? defaultAriaLabel);
|
|
182
|
+
const selectByKey = key => {
|
|
183
|
+
const option = optionSource.find(opt => opt.key === key);
|
|
184
|
+
if (option) {
|
|
185
|
+
onSelectOption(option);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/*
|
|
190
|
+
* A virtualized menu keeps only a window of rows in the DOM, so the keyboard
|
|
191
|
+
* hook would otherwise clamp End / PageDown / wrap-around / type-ahead to that
|
|
192
|
+
* window. Hand it the real option list in that case — whichever source it came
|
|
193
|
+
* from, and flat or grouped alike, since Menu handles both — and Menu
|
|
194
|
+
* scrolls the active row into view. Plain menus stay on the DOM-driven path,
|
|
195
|
+
* which keeps grouped layouts and `resolveLabel` type-ahead working off the
|
|
196
|
+
* rendered text.
|
|
197
|
+
*/
|
|
198
|
+
const resolveLabel = menu?.resolveLabel;
|
|
199
|
+
const navigationOptions = React.useMemo(() => {
|
|
200
|
+
// A wholly disabled menu has no navigable options at all.
|
|
201
|
+
if (!menu?.virtualization?.enable || menu.menuDisabled) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
return optionSource.filter(option => !option.disabled).map(option => {
|
|
205
|
+
// Type-ahead must match the text the user can actually read.
|
|
206
|
+
const resolved = resolveLabel?.(option);
|
|
207
|
+
return {
|
|
208
|
+
key: option.key,
|
|
209
|
+
label: typeof resolved === 'string' ? resolved : option.label ?? ''
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
}, [menu?.virtualization?.enable, menu?.menuDisabled, resolveLabel, optionSource]);
|
|
213
|
+
const {
|
|
214
|
+
onKeyDown: onComboboxKeyDown
|
|
215
|
+
} = (0, _useMenuKeyboardNavigation.useMenuKeyboardNavigation)({
|
|
216
|
+
containerRef: menuRef,
|
|
217
|
+
enabled: isOpen && usesExternalNav && !menu?.menuDisabled,
|
|
218
|
+
// An editable trigger keeps printable keys for filtering; a read-only one
|
|
219
|
+
// spends them on type-ahead.
|
|
220
|
+
mode: isAutocomplete ? 'search' : 'activedescendant',
|
|
221
|
+
activeOptionKey,
|
|
222
|
+
onSelectKey: selectByKey,
|
|
223
|
+
setActiveOptionKey,
|
|
224
|
+
options: navigationOptions
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
/*
|
|
228
|
+
* Seed the highlight when the menu opens, drop it when it closes, and keep it
|
|
229
|
+
* valid while the option set changes underneath it (async or cascading
|
|
230
|
+
* options). Menu skips its own re-validation under `externalKeyboardNav`, so
|
|
231
|
+
* the trigger owns it — without this, `aria-activedescendant` could point at
|
|
232
|
+
* the id of an option that no longer exists. A layout effect, so the id is in
|
|
233
|
+
* place before the browser paints the open menu.
|
|
234
|
+
*/
|
|
235
|
+
const selectedKeys = menu?.selectedKeys;
|
|
236
|
+
const selectedOption = menu?.selectedOption;
|
|
237
|
+
React.useLayoutEffect(() => {
|
|
238
|
+
// A closed list has no active option, whichever pattern this is.
|
|
239
|
+
if (!isOpen) {
|
|
240
|
+
setActiveOptionKey(null);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const enabledKeys = optionSource.filter(option => !option.disabled).map(option => option.key);
|
|
244
|
+
const surviving = prev => prev && enabledKeys.includes(prev) ? prev : null;
|
|
245
|
+
if (isAutocomplete) {
|
|
246
|
+
// Manual selection: never highlight anything on the user's behalf, only
|
|
247
|
+
// drop a highlight that the filtering has removed under them.
|
|
248
|
+
setActiveOptionKey(surviving);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (!usesExternalNav) {
|
|
252
|
+
setActiveOptionKey(null);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
setActiveOptionKey(prev => surviving(prev) ?? (0, _Menu.getInitialActiveOptionKey)({
|
|
256
|
+
options: optionSource,
|
|
257
|
+
selectedKeys,
|
|
258
|
+
selectedOption
|
|
259
|
+
}));
|
|
260
|
+
}, [isAutocomplete, isOpen, usesExternalNav, optionSource, selectedKeys, selectedOption]);
|
|
261
|
+
const getTriggerProps = _ref4 => {
|
|
262
|
+
let {
|
|
263
|
+
isOpen: triggerIsOpen,
|
|
264
|
+
isExpanded,
|
|
265
|
+
onOpen,
|
|
266
|
+
onKeyDown
|
|
267
|
+
} = _ref4;
|
|
268
|
+
const expanded = isExpanded ?? triggerIsOpen;
|
|
269
|
+
return {
|
|
270
|
+
// The one combobox for both shapes: the menu's own filter field is a
|
|
271
|
+
// `searchbox`, so nothing competes for the listbox. Keeping the role
|
|
272
|
+
// unconditional also keeps `aria-expanded` valid — it is not an allowed
|
|
273
|
+
// attribute on a plain textbox.
|
|
274
|
+
role: 'combobox',
|
|
275
|
+
'aria-haspopup': 'listbox',
|
|
276
|
+
'aria-expanded': expanded,
|
|
277
|
+
// Only reference the listbox while it is actually rendered. The hook always
|
|
278
|
+
// hands `menuId` to Menu, so the element exists whenever `expanded` says so,
|
|
279
|
+
// whichever option source was supplied.
|
|
280
|
+
'aria-controls': expanded ? menuId : undefined,
|
|
281
|
+
// 'list' whenever typing narrows the list: the autocomplete pattern, or a
|
|
282
|
+
// menu carrying its own filter field.
|
|
283
|
+
'aria-autocomplete': isAutocomplete || !usesExternalNav ? 'list' : 'none',
|
|
284
|
+
'aria-activedescendant': expanded && usesExternalNav && activeOptionKey ? (0, _menuOptionId.menuOptionId)(menuId, activeOptionKey) : undefined,
|
|
285
|
+
onKeyDown: event => {
|
|
286
|
+
onKeyDown?.(event);
|
|
287
|
+
if (event.defaultPrevented) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (!triggerIsOpen) {
|
|
291
|
+
// Closed: the arrow keys open the list, and a read-only trigger takes
|
|
292
|
+
// Enter and Space for it too — a typed space belongs to an editable
|
|
293
|
+
// one. This is the part no Menu prop can supply: the menu does not
|
|
294
|
+
// exist yet.
|
|
295
|
+
const opensList = event.key === 'ArrowDown' || event.key === 'ArrowUp' || !isAutocomplete && (event.key === 'Enter' || event.key === ' ');
|
|
296
|
+
if (opensList && (canOpen?.() ?? true)) {
|
|
297
|
+
event.preventDefault();
|
|
298
|
+
onOpen();
|
|
299
|
+
}
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
// Open + searchable: focus is in the menu's own filter field, which owns
|
|
303
|
+
// navigation — nothing to do here.
|
|
304
|
+
if (!usesExternalNav) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
// Tab moves into the menu's footer, Shift+Tab into its header, when that
|
|
308
|
+
// region has focusable controls. With none there, the listbox closes
|
|
309
|
+
// (APG: the popup closes when the combobox loses focus) and focus moves
|
|
310
|
+
// on.
|
|
311
|
+
if (event.key === 'Tab') {
|
|
312
|
+
if ((0, _useMenuKeyboardNavigation.moveFocusToMenuChrome)(menuRef.current, event.shiftKey)) {
|
|
313
|
+
event.preventDefault();
|
|
314
|
+
} else {
|
|
315
|
+
onClose();
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
// Space selects the active option — only where it has no typing role.
|
|
320
|
+
if (!isAutocomplete && event.key === ' ') {
|
|
321
|
+
event.preventDefault();
|
|
322
|
+
if (activeOptionKey) {
|
|
323
|
+
selectByKey(activeOptionKey);
|
|
324
|
+
}
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
// Arrows / Home / End / Enter / type-ahead.
|
|
328
|
+
onComboboxKeyDown(event);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
return {
|
|
333
|
+
getTriggerProps,
|
|
334
|
+
menuProps: compact({
|
|
335
|
+
menuId,
|
|
336
|
+
ariaLabelledBy: menuAriaLabelledBy,
|
|
337
|
+
ariaLabel: menuAriaLabel,
|
|
338
|
+
externalKeyboardNav: usesExternalNav,
|
|
339
|
+
activeOptionKey: usesExternalNav ? activeOptionKey : undefined,
|
|
340
|
+
onActiveOptionKeyChange: usesExternalNav ? setActiveOptionKey : undefined,
|
|
341
|
+
onReturnFocusToInput: usesExternalNav ? focusTrigger : undefined,
|
|
342
|
+
initialFocusRef: usesExternalNav ? undefined : initialFocusRef
|
|
343
|
+
}),
|
|
344
|
+
activeOptionKey
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
exports.useComboboxMenuTrigger = useComboboxMenuTrigger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TruncatedTextWithTooltip.d.ts","sourceRoot":"","sources":["../../../src/components/TruncatedTextWithTooltip/TruncatedTextWithTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"TruncatedTextWithTooltip.d.ts","sourceRoot":"","sources":["../../../src/components/TruncatedTextWithTooltip/TruncatedTextWithTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,wBAAwB,CAAC;AAM7D,KAAK,UAAU,GAAG,QAAQ,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC,CAAC;AAEH,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,wBAAwB,GAAI,uEAQtC,6BAA6B,sBAiH/B,CAAC"}
|
|
@@ -8,16 +8,11 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
9
9
|
var _classify = _interopRequireDefault(require("../../utils/classify"));
|
|
10
10
|
var _qa = require("../../utils/qa");
|
|
11
|
-
var _ConditionalWrapper = require("../ConditionalWrapper");
|
|
12
11
|
var _Tooltip = require("../Tooltip");
|
|
13
12
|
var _TruncatedTextWithTooltipModule = _interopRequireDefault(require("./TruncatedTextWithTooltip.module.css"));
|
|
14
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
15
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
17
|
-
// Define the expected props for the child element that can be cloned
|
|
18
|
-
|
|
19
|
-
// Type for a child element that can be cloned
|
|
20
|
-
|
|
21
16
|
const TruncatedTextWithTooltip = _ref => {
|
|
22
17
|
let {
|
|
23
18
|
classNames,
|
|
@@ -41,6 +36,15 @@ const TruncatedTextWithTooltip = _ref => {
|
|
|
41
36
|
}), [truncatedNode, wrapText]);
|
|
42
37
|
React.useEffect(() => {
|
|
43
38
|
checkIfTextOverflowing();
|
|
39
|
+
// Cancel the outgoing debounce instance's pending trailing-edge call.
|
|
40
|
+
// checkIfTextOverflowing is recreated whenever truncatedNode changes
|
|
41
|
+
// (e.g. once on mount, null -> real node). Without this cancel, the
|
|
42
|
+
// stale instance's trailing call still fires ~200ms later using its
|
|
43
|
+
// frozen closure (truncatedNode as it was when THAT instance was
|
|
44
|
+
// created) and can stomp a correct value the new instance already set.
|
|
45
|
+
return () => {
|
|
46
|
+
checkIfTextOverflowing.cancel();
|
|
47
|
+
};
|
|
44
48
|
}, [line, children, wrapText, checkIfTextOverflowing]);
|
|
45
49
|
React.useEffect(() => {
|
|
46
50
|
if (!truncatedNode) {
|
|
@@ -58,57 +62,66 @@ const TruncatedTextWithTooltip = _ref => {
|
|
|
58
62
|
'--line-clamp': wrapText ? 'unset' : line,
|
|
59
63
|
'--word-break': wordBreak
|
|
60
64
|
};
|
|
61
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ConditionalWrapper.ConditionalWrapper, {
|
|
62
|
-
condition: Boolean(showMouseTip),
|
|
63
|
-
wrapper: children => {
|
|
64
|
-
const child = React.Children.only(children);
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
// Always render the same <span>, always wrapped in the same <Tooltip>,
|
|
67
|
+
// toggling only Tooltip's `hidden` prop. Previously a ConditionalWrapper
|
|
68
|
+
// swapped between a bare <span> and <Tooltip><div>{span}</div></Tooltip>
|
|
69
|
+
// based on showMouseTip — changing the element type at this tree position
|
|
70
|
+
// forces React to unmount/remount the span every time showMouseTip
|
|
71
|
+
// toggles. The remounted span (now a flex child of an extra wrapper div)
|
|
72
|
+
// measures different scrollHeight/clientHeight than the bare span, so the
|
|
73
|
+
// ResizeObserver above sees its own self-inflicted resize and flips
|
|
74
|
+
// showMouseTip again — an infinite loop where the tooltip never
|
|
75
|
+
// stabilizes. Tooltip clones its trigger prop onto the same element (no
|
|
76
|
+
// wrapper element inserted), so keeping the span's identity stable here
|
|
77
|
+
// means toggling showMouseTip no longer causes a remount.
|
|
78
|
+
const truncatedSpan = /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
79
|
+
className: (0, _classify.default)(_TruncatedTextWithTooltipModule.default.truncateLineClamp, classNames?.wrapper),
|
|
80
|
+
style: styles,
|
|
81
|
+
ref: setTruncatedNode,
|
|
82
|
+
"data-testid": (0, _qa.generateTestId)({
|
|
83
|
+
base: testId,
|
|
84
|
+
slot: 'text'
|
|
85
|
+
}),
|
|
86
|
+
children: children
|
|
87
|
+
});
|
|
74
88
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
})
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
103
|
-
className: (0, _classify.default)(_TruncatedTextWithTooltipModule.default.truncateLineClamp, classNames?.wrapper),
|
|
104
|
-
style: styles,
|
|
105
|
-
ref: setTruncatedNode,
|
|
106
|
-
"data-testid": (0, _qa.generateTestId)({
|
|
107
|
-
base: testId,
|
|
108
|
-
slot: 'text'
|
|
109
|
-
}),
|
|
110
|
-
children: children
|
|
89
|
+
// `ref: null` is required here: React.cloneElement inherits the source
|
|
90
|
+
// element's ref unless explicitly overridden. Without this, this
|
|
91
|
+
// body-only clone (rendered separately inside Tooltip's floating panel,
|
|
92
|
+
// gated by `hidden`) would share the trigger span's ref. Mounting/
|
|
93
|
+
// unmounting this clone as `hidden` toggles would hijack truncatedNode
|
|
94
|
+
// away from the actual trigger, eventually losing the ref to the real
|
|
95
|
+
// trigger permanently once this clone unmounts.
|
|
96
|
+
//
|
|
97
|
+
// No className/style here (rather than trying to override --line-clamp):
|
|
98
|
+
// Tooltip already wraps body in <Truncate line={bodyMaxLines}>, which puts
|
|
99
|
+
// its own webkit-box line-clamp on the containing div. Keeping
|
|
100
|
+
// css.truncateLineClamp on this span would make it a second, nested
|
|
101
|
+
// webkit-box with its own --word-break (this component's `wordBreak` prop,
|
|
102
|
+
// meant for the single-line trigger) — since that inner box is what
|
|
103
|
+
// actually renders the text, it silently wins over the outer div's
|
|
104
|
+
// word-break even when both clamp to the same line count. Dropping the
|
|
105
|
+
// class/style lets the outer div be the only clamp in the chain.
|
|
106
|
+
const modifiedChild = /*#__PURE__*/React.cloneElement(truncatedSpan, {
|
|
107
|
+
ref: null,
|
|
108
|
+
className: undefined,
|
|
109
|
+
style: undefined,
|
|
110
|
+
'data-testid': (0, _qa.generateTestId)({
|
|
111
|
+
base: testId,
|
|
112
|
+
slot: 'body-text'
|
|
111
113
|
})
|
|
112
114
|
});
|
|
115
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.Tooltip, {
|
|
116
|
+
...tooltip,
|
|
117
|
+
hidden: tooltip?.hidden ?? !showMouseTip,
|
|
118
|
+
body: tooltip?.body || modifiedChild,
|
|
119
|
+
elevation: tooltip?.elevation ?? 'toast',
|
|
120
|
+
testId: (0, _qa.generateTestId)({
|
|
121
|
+
base: testId,
|
|
122
|
+
slot: 'tooltip'
|
|
123
|
+
}),
|
|
124
|
+
children: truncatedSpan
|
|
125
|
+
});
|
|
113
126
|
};
|
|
114
127
|
exports.TruncatedTextWithTooltip = TruncatedTextWithTooltip;
|
package/lib/hooks/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from '../hooks/useDebounce';
|
|
|
4
4
|
export * from '../hooks/useFileUpload';
|
|
5
5
|
export * from '../hooks/useFilteredOptions';
|
|
6
6
|
export * from '../hooks/useInfiniteScroll';
|
|
7
|
+
export * from '../hooks/useInteractionModality';
|
|
7
8
|
export * from '../hooks/useInputState';
|
|
8
9
|
export * from '../hooks/useLockedBody';
|
|
9
10
|
export * from '../hooks/useModal';
|
package/lib/hooks/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC;AACrD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC;AACrD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC"}
|
package/lib/hooks/index.js
CHANGED
|
@@ -69,6 +69,17 @@ Object.keys(_useInfiniteScroll).forEach(function (key) {
|
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
|
+
var _useInteractionModality = require("./useInteractionModality");
|
|
73
|
+
Object.keys(_useInteractionModality).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _useInteractionModality[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _useInteractionModality[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
72
83
|
var _useInputState = require("./useInputState");
|
|
73
84
|
Object.keys(_useInputState).forEach(function (key) {
|
|
74
85
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useInteractionModality/index.ts"],"names":[],"mappings":"AAAA,cAAc,yDAAyD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _useInteractionModality = require("./useInteractionModality");
|
|
7
|
+
Object.keys(_useInteractionModality).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _useInteractionModality[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _useInteractionModality[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type InteractionModality = 'keyboard' | 'pointer';
|
|
2
|
+
/**
|
|
3
|
+
* How the user last interacted with the page, read imperatively.
|
|
4
|
+
*
|
|
5
|
+
* Use this when the answer is needed during render or in an effect rather than
|
|
6
|
+
* as reactive state — for example a popup deciding on mount whether it was opened
|
|
7
|
+
* by keyboard, where re-rendering on later modality changes would be wrong.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getInteractionModality: () => InteractionModality;
|
|
10
|
+
/**
|
|
11
|
+
* How the user last interacted with the page, as reactive state. Re-renders the
|
|
12
|
+
* caller when the user switches between keyboard and pointer.
|
|
13
|
+
*/
|
|
14
|
+
export declare const useInteractionModality: () => InteractionModality;
|
|
15
|
+
//# sourceMappingURL=useInteractionModality.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInteractionModality.d.ts","sourceRoot":"","sources":["../../../src/hooks/useInteractionModality/useInteractionModality.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,SAAS,CAAC;AA6FzD;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,QAAO,mBAGzC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,QAAO,mBAMzC,CAAC"}
|