@dloizides/ui-layout 1.8.0 → 1.9.1
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/CHANGELOG.md +24 -0
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +25 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.9.1
|
|
4
|
+
|
|
5
|
+
- **Fix (keyboard a11y, affects every consumer): Enter CLOSED the inline menu instead of SELECTING
|
|
6
|
+
the highlighted option.** The trigger keeps DOM focus while the menu is open, and react-native-web
|
|
7
|
+
maps Enter on a focused Touchable to `onPress`. React dispatches that from its ROOT container
|
|
8
|
+
listener — an ancestor of the trigger, but a *descendant* of `document` — so the menu's BUBBLING
|
|
9
|
+
`document` keydown listener ran second: the trigger toggled the menu shut, React unmounted the
|
|
10
|
+
popover, the effect cleanup removed the very listener the event was still travelling toward, and
|
|
11
|
+
`document` never saw the Enter. Keyboard users could open a dropdown and arrow through it but
|
|
12
|
+
could never CHOOSE with the keyboard (mouse selection was unaffected, which is why it went
|
|
13
|
+
unnoticed).
|
|
14
|
+
- **Fix:** the menu's key handler now runs in the **capture** phase and `stopPropagation`s the keys
|
|
15
|
+
an open menu owns (↑/↓/Home/End/Enter/Escape), so it runs ahead of React's listener and the
|
|
16
|
+
trigger cannot re-toggle behind it. Found while browser-verifying the AML v2 topbar dropdowns.
|
|
17
|
+
|
|
18
|
+
## 1.9.0
|
|
19
|
+
|
|
20
|
+
- **`ModalDropdown`: `menuMinWidth` — a width FLOOR for the open inline menu (additive, optional).**
|
|
21
|
+
The menu matches the TRIGGER's width, which is right for a full-width field but leaves a compact
|
|
22
|
+
anchor (the 1.8.0 `renderTrigger` case: a locale pill, an avatar chip, an icon button) with a menu
|
|
23
|
+
too narrow to read its own option labels — a 52px "EN ▾" pill produced a 52px menu whose rows were
|
|
24
|
+
clipped to a dark strip. `menuMinWidth` floors it; a wider trigger still wins.
|
|
25
|
+
- **Backward-compatible:** omitted, the width is the trigger's, exactly as before.
|
|
26
|
+
|
|
3
27
|
## 1.8.0
|
|
4
28
|
|
|
5
29
|
- **`ModalDropdown`: `renderTrigger` — a custom ANCHOR slot (additive, optional).** The dropdown's
|
package/dist/index.d.mts
CHANGED
|
@@ -162,8 +162,15 @@ interface ModalDropdownProps<T> {
|
|
|
162
162
|
* a dropdown.
|
|
163
163
|
*/
|
|
164
164
|
optionTestID?: (value: T) => string;
|
|
165
|
+
/**
|
|
166
|
+
* Minimum width of the open inline menu. The menu otherwise matches the TRIGGER's width, which
|
|
167
|
+
* is right for a full-width field but leaves a COMPACT anchor (a locale pill, an avatar chip, an
|
|
168
|
+
* icon button — see `renderTrigger`) with a menu too narrow to read its own option labels. It is
|
|
169
|
+
* a floor only: a wider trigger still wins. Omit to keep the trigger-width behaviour.
|
|
170
|
+
*/
|
|
171
|
+
menuMinWidth?: number;
|
|
165
172
|
}
|
|
166
|
-
declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, renderTrigger, optionTestID, }: ModalDropdownProps<T>) => React.ReactElement;
|
|
173
|
+
declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, renderTrigger, optionTestID, menuMinWidth, }: ModalDropdownProps<T>) => React.ReactElement;
|
|
167
174
|
|
|
168
175
|
/**
|
|
169
176
|
* ModalShell — a slide-up full-screen modal with a themed header (title + close button)
|
package/dist/index.d.ts
CHANGED
|
@@ -162,8 +162,15 @@ interface ModalDropdownProps<T> {
|
|
|
162
162
|
* a dropdown.
|
|
163
163
|
*/
|
|
164
164
|
optionTestID?: (value: T) => string;
|
|
165
|
+
/**
|
|
166
|
+
* Minimum width of the open inline menu. The menu otherwise matches the TRIGGER's width, which
|
|
167
|
+
* is right for a full-width field but leaves a COMPACT anchor (a locale pill, an avatar chip, an
|
|
168
|
+
* icon button — see `renderTrigger`) with a menu too narrow to read its own option labels. It is
|
|
169
|
+
* a floor only: a wider trigger still wins. Omit to keep the trigger-width behaviour.
|
|
170
|
+
*/
|
|
171
|
+
menuMinWidth?: number;
|
|
165
172
|
}
|
|
166
|
-
declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, renderTrigger, optionTestID, }: ModalDropdownProps<T>) => React.ReactElement;
|
|
173
|
+
declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, renderTrigger, optionTestID, menuMinWidth, }: ModalDropdownProps<T>) => React.ReactElement;
|
|
167
174
|
|
|
168
175
|
/**
|
|
169
176
|
* ModalShell — a slide-up full-screen modal with a themed header (title + close button)
|
package/dist/index.js
CHANGED
|
@@ -323,14 +323,14 @@ var BORDER_RADIUS = 8;
|
|
|
323
323
|
var BORDER_WIDTH2 = 1;
|
|
324
324
|
var MENU_PADDING = 4;
|
|
325
325
|
var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
|
|
326
|
-
function buildPortalPopoverStyle(rect) {
|
|
326
|
+
function buildPortalPopoverStyle(rect, minWidth = 0) {
|
|
327
327
|
return {
|
|
328
328
|
// RN's ViewStyle union omits 'fixed', but react-native-web honours it at runtime.
|
|
329
329
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- web-only position value
|
|
330
330
|
position: "fixed",
|
|
331
331
|
top: rect.bottom + MENU_TOP_GAP,
|
|
332
332
|
left: rect.left,
|
|
333
|
-
width: rect.width,
|
|
333
|
+
width: Math.max(rect.width, minWidth),
|
|
334
334
|
zIndex: MENU_Z_INDEX,
|
|
335
335
|
borderWidth: BORDER_WIDTH2,
|
|
336
336
|
borderRadius: BORDER_RADIUS,
|
|
@@ -397,32 +397,36 @@ var clampIndex = (index, itemCount) => {
|
|
|
397
397
|
const lastIndex = itemCount - 1;
|
|
398
398
|
return index > lastIndex ? lastIndex : index;
|
|
399
399
|
};
|
|
400
|
+
function claimKey(event) {
|
|
401
|
+
event.preventDefault();
|
|
402
|
+
event.stopPropagation();
|
|
403
|
+
}
|
|
400
404
|
function buildKeyHandler(params) {
|
|
401
405
|
const { itemCount, onHighlightChange, onSelectHighlighted, onClose } = params;
|
|
402
406
|
return (event) => {
|
|
403
407
|
switch (event.key) {
|
|
404
408
|
case "ArrowDown":
|
|
405
|
-
event
|
|
409
|
+
claimKey(event);
|
|
406
410
|
onHighlightChange((prev) => clampIndex(prev + 1, itemCount));
|
|
407
411
|
return;
|
|
408
412
|
case "ArrowUp":
|
|
409
|
-
event
|
|
413
|
+
claimKey(event);
|
|
410
414
|
onHighlightChange((prev) => clampIndex(prev - 1, itemCount));
|
|
411
415
|
return;
|
|
412
416
|
case "Home":
|
|
413
|
-
event
|
|
417
|
+
claimKey(event);
|
|
414
418
|
onHighlightChange(() => 0);
|
|
415
419
|
return;
|
|
416
420
|
case "End":
|
|
417
|
-
event
|
|
421
|
+
claimKey(event);
|
|
418
422
|
onHighlightChange(() => clampIndex(itemCount - 1, itemCount));
|
|
419
423
|
return;
|
|
420
424
|
case "Enter":
|
|
421
|
-
event
|
|
425
|
+
claimKey(event);
|
|
422
426
|
onSelectHighlighted();
|
|
423
427
|
return;
|
|
424
428
|
case "Escape":
|
|
425
|
-
event
|
|
429
|
+
claimKey(event);
|
|
426
430
|
onClose();
|
|
427
431
|
return;
|
|
428
432
|
}
|
|
@@ -439,10 +443,10 @@ function useMenuKeyboard(params) {
|
|
|
439
443
|
const insideMenu = refContains(menuRef, target);
|
|
440
444
|
if (!insideAnchor && !insideMenu) onClose();
|
|
441
445
|
};
|
|
442
|
-
document.addEventListener("keydown", onKeyDown);
|
|
446
|
+
document.addEventListener("keydown", onKeyDown, true);
|
|
443
447
|
document.addEventListener("mousedown", onMouseDown);
|
|
444
448
|
return () => {
|
|
445
|
-
document.removeEventListener("keydown", onKeyDown);
|
|
449
|
+
document.removeEventListener("keydown", onKeyDown, true);
|
|
446
450
|
document.removeEventListener("mousedown", onMouseDown);
|
|
447
451
|
};
|
|
448
452
|
}, [containerRef, menuRef, enabled, onClose, params]);
|
|
@@ -499,6 +503,7 @@ var InlineMenu = ({
|
|
|
499
503
|
options,
|
|
500
504
|
containerRef,
|
|
501
505
|
optionTestID,
|
|
506
|
+
menuMinWidth = 0,
|
|
502
507
|
onSelect,
|
|
503
508
|
onClose
|
|
504
509
|
}) => {
|
|
@@ -535,9 +540,13 @@ var InlineMenu = ({
|
|
|
535
540
|
});
|
|
536
541
|
const popoverStyle = React8.useMemo(() => {
|
|
537
542
|
const themed = { borderColor: colors.border, backgroundColor: colors.surface };
|
|
538
|
-
if (IS_WEB)
|
|
539
|
-
|
|
540
|
-
|
|
543
|
+
if (IS_WEB)
|
|
544
|
+
return [
|
|
545
|
+
buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth),
|
|
546
|
+
themed
|
|
547
|
+
];
|
|
548
|
+
return [styles7.popover, { minWidth: menuMinWidth }, themed];
|
|
549
|
+
}, [colors.border, colors.surface, menuMinWidth, rect]);
|
|
541
550
|
const menu = /* @__PURE__ */ jsxRuntime.jsx(
|
|
542
551
|
reactNative.View,
|
|
543
552
|
{
|
|
@@ -612,7 +621,8 @@ var ModalDropdown = ({
|
|
|
612
621
|
onChange,
|
|
613
622
|
variant,
|
|
614
623
|
renderTrigger,
|
|
615
|
-
optionTestID
|
|
624
|
+
optionTestID,
|
|
625
|
+
menuMinWidth
|
|
616
626
|
}) => {
|
|
617
627
|
const { theme, t } = uiFeedback.useUi();
|
|
618
628
|
const { colors } = theme;
|
|
@@ -689,6 +699,7 @@ var ModalDropdown = ({
|
|
|
689
699
|
{
|
|
690
700
|
accessibilityLabel,
|
|
691
701
|
containerRef: anchorRef,
|
|
702
|
+
menuMinWidth,
|
|
692
703
|
optionTestID: optionTestIDFor,
|
|
693
704
|
options,
|
|
694
705
|
testID,
|