@terreno/ui 57.6.1 → 57.8.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.
Files changed (77) hide show
  1. package/dist/Avatar.js +2 -2
  2. package/dist/Avatar.js.map +1 -1
  3. package/dist/Button.js +2 -2
  4. package/dist/Button.js.map +1 -1
  5. package/dist/Common.d.ts +93 -5
  6. package/dist/Common.d.ts.map +1 -1
  7. package/dist/Common.js.map +1 -1
  8. package/dist/DateTimeActionSheet.js +2 -2
  9. package/dist/DateTimeActionSheet.js.map +1 -1
  10. package/dist/DateTimeField.js +3 -3
  11. package/dist/DateTimeField.js.map +1 -1
  12. package/dist/DropdownPanel.d.ts +24 -0
  13. package/dist/DropdownPanel.d.ts.map +1 -0
  14. package/dist/DropdownPanel.js +186 -0
  15. package/dist/DropdownPanel.js.map +1 -0
  16. package/dist/HeightField.js +2 -2
  17. package/dist/HeightField.js.map +1 -1
  18. package/dist/IconButton.d.ts.map +1 -1
  19. package/dist/IconButton.js +9 -6
  20. package/dist/IconButton.js.map +1 -1
  21. package/dist/MediaQuery.d.ts +10 -0
  22. package/dist/MediaQuery.d.ts.map +1 -1
  23. package/dist/MediaQuery.js +13 -1
  24. package/dist/MediaQuery.js.map +1 -1
  25. package/dist/MultiselectField.js +2 -2
  26. package/dist/MultiselectField.js.map +1 -1
  27. package/dist/RadioField.js +2 -2
  28. package/dist/RadioField.js.map +1 -1
  29. package/dist/SplitPage.d.ts +1 -1
  30. package/dist/SplitPage.d.ts.map +1 -1
  31. package/dist/SplitPage.js +126 -21
  32. package/dist/SplitPage.js.map +1 -1
  33. package/dist/UnifiedAddressAutoComplete.js +2 -2
  34. package/dist/UnifiedAddressAutoComplete.js.map +1 -1
  35. package/dist/dataTableFilters.js +3 -3
  36. package/dist/dataTableFilters.js.map +1 -1
  37. package/dist/dropdownPanelLayout.d.ts +59 -0
  38. package/dist/dropdownPanelLayout.d.ts.map +1 -0
  39. package/dist/dropdownPanelLayout.js +57 -0
  40. package/dist/dropdownPanelLayout.js.map +1 -0
  41. package/dist/fieldElements/FieldTitle.js +2 -2
  42. package/dist/fieldElements/FieldTitle.js.map +1 -1
  43. package/dist/index.d.ts +2 -1
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +2 -1
  46. package/dist/index.js.map +1 -1
  47. package/package.json +1 -1
  48. package/src/Avatar.tsx +2 -2
  49. package/src/Button.test.tsx +7 -7
  50. package/src/Button.tsx +2 -2
  51. package/src/Common.ts +93 -5
  52. package/src/DateTimeActionSheet.tsx +4 -4
  53. package/src/DateTimeField.test.tsx +5 -4
  54. package/src/DateTimeField.tsx +3 -3
  55. package/src/{Filter.test.tsx → DropdownPanel.test.tsx} +141 -43
  56. package/src/{Filter.tsx → DropdownPanel.tsx} +145 -74
  57. package/src/HeightField.tsx +2 -2
  58. package/src/IconButton.test.tsx +63 -0
  59. package/src/IconButton.tsx +10 -5
  60. package/src/MediaQuery.ts +14 -1
  61. package/src/MultiselectField.tsx +2 -2
  62. package/src/RadioField.tsx +2 -2
  63. package/src/SplitPage.test.tsx +449 -11
  64. package/src/SplitPage.tsx +255 -21
  65. package/src/UnifiedAddressAutoComplete.test.tsx +4 -4
  66. package/src/UnifiedAddressAutoComplete.tsx +2 -2
  67. package/src/__snapshots__/{Filter.test.tsx.snap → DropdownPanel.test.tsx.snap} +6 -2
  68. package/src/bunSetup.ts +8 -1
  69. package/src/dataTableFilters.tsx +5 -5
  70. package/src/dropdownPanelLayout.test.ts +140 -0
  71. package/src/dropdownPanelLayout.ts +131 -0
  72. package/src/fieldElements/FieldTitle.tsx +2 -2
  73. package/src/index.tsx +2 -1
  74. package/dist/Filter.d.ts +0 -14
  75. package/dist/Filter.d.ts.map +0 -1
  76. package/dist/Filter.js +0 -145
  77. package/dist/Filter.js.map +0 -1
package/src/SplitPage.tsx CHANGED
@@ -1,18 +1,35 @@
1
- import {Children, type ComponentProps, useCallback, useEffect, useState} from "react";
2
- import {Dimensions, type ListRenderItemInfo, ScrollView, View} from "react-native";
1
+ import {
2
+ Children,
3
+ type ComponentProps,
4
+ type ElementRef,
5
+ useCallback,
6
+ useEffect,
7
+ useRef,
8
+ useState,
9
+ } from "react";
10
+ import {
11
+ type LayoutChangeEvent,
12
+ type ListRenderItemInfo,
13
+ ScrollView,
14
+ useWindowDimensions,
15
+ View,
16
+ } from "react-native";
3
17
  import {SwiperFlatList} from "react-native-swiper-flatlist";
4
18
 
5
19
  import {Box} from "./Box";
6
20
  import type {SplitPageListItem, SplitPageProps} from "./Common";
7
21
  import {FlatList} from "./FlatList";
8
22
  import {IconButton} from "./IconButton";
9
- import {isMobileDevice} from "./MediaQuery";
23
+ import {isNarrowViewport} from "./MediaQuery";
10
24
  import {SegmentedControl} from "./SegmentedControl";
11
25
  import {Spinner} from "./Spinner";
12
26
  import {useTheme} from "./Theme";
13
27
 
14
28
  // A component for rendering a list on one side and a details view on the right for large screens,
15
29
  // and a scrollable list where clicking an item takes you the details view.
30
+ // On web, opt in to minimum widths for the desktop side-by-side children, or a labeled pager
31
+ // on the narrow viewport. `narrowBelowWidth` chooses that viewport from the window width;
32
+ // otherwise it follows `isNarrowViewport()`. The native SplitPage ignores those props.
16
33
  export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
17
34
  children,
18
35
  tabs = [],
@@ -28,14 +45,28 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
28
45
  listViewWidth,
29
46
  listViewMaxWidth,
30
47
  bottomNavBarHeight,
48
+ desktopChildrenMinWidth,
49
+ narrowBelowWidth,
50
+ narrowViewportChildLabels,
51
+ narrowViewportListButtonLabel,
52
+ narrowViewportSelectionActive,
53
+ narrowViewportSelectionKey,
31
54
  showItemList,
32
55
  }: SplitPageProps<TItem>) => {
33
56
  const {theme} = useTheme();
57
+ const {width: windowWidth} = useWindowDimensions();
34
58
  const [selectedId, setSelectedId] = useState<number | undefined>(undefined);
35
59
  const [activeTabs, setActiveTabs] = useState<number[]>([0, 1]);
36
- const {width} = Dimensions.get("window");
60
+ const [activeChildIndex, setActiveChildIndex] = useState(0);
61
+ const activeChildIndexRef = useRef(activeChildIndex);
62
+ activeChildIndexRef.current = activeChildIndex;
63
+ const swiperRef = useRef<ElementRef<typeof SwiperFlatList> | null>(null);
64
+ const [desktopScrollWidth, setDesktopScrollWidth] = useState(0);
65
+ const [measuredPageWidth, setMeasuredPageWidth] = useState(0);
37
66
 
38
- const isMobileLayout = isMobileDevice();
67
+ const isNarrowLayout =
68
+ narrowBelowWidth === undefined ? isNarrowViewport() : windowWidth <= narrowBelowWidth;
69
+ const isDetailActive = selectedId !== undefined || narrowViewportSelectionActive === true;
39
70
 
40
71
  const elementArray = Children.toArray(children).filter((c) => c !== null);
41
72
 
@@ -59,6 +90,23 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
59
90
  }
60
91
  }, [showItemList, onItemDeselect]);
61
92
 
93
+ // Reset the narrow pager when the selected record changes. Width changes stay out of this effect
94
+ // so a resize does not jump back to the first child.
95
+ // biome-ignore lint/correctness/useExhaustiveDependencies: these values are the reset triggers.
96
+ useEffect(() => {
97
+ setActiveChildIndex(0);
98
+ swiperRef.current?.scrollToIndex({animated: false, index: 0});
99
+ }, [isDetailActive, isNarrowLayout, narrowViewportSelectionKey, selectedId]);
100
+
101
+ // Keep the current child aligned after the page width changes, without snapping over a chevron animation.
102
+ // biome-ignore lint/correctness/useExhaustiveDependencies: widths are the realign triggers; the index is read from a ref.
103
+ useEffect(() => {
104
+ swiperRef.current?.scrollToIndex({
105
+ animated: false,
106
+ index: activeChildIndexRef.current,
107
+ });
108
+ }, [measuredPageWidth, windowWidth]);
109
+
62
110
  if (!children && !renderContent) {
63
111
  console.warn("A child node is required");
64
112
  return null;
@@ -69,6 +117,19 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
69
117
  return null;
70
118
  }
71
119
 
120
+ if (desktopChildrenMinWidth !== undefined && elementArray.length > 2) {
121
+ console.warn("desktopChildrenMinWidth applies only when SplitPage has two or fewer children.");
122
+ }
123
+
124
+ if (
125
+ narrowViewportChildLabels !== undefined &&
126
+ narrowViewportChildLabels.length !== elementArray.length
127
+ ) {
128
+ console.warn(
129
+ "narrowViewportChildLabels must have one entry per child. Falling back to the default narrow pager."
130
+ );
131
+ }
132
+
72
133
  const renderItem = (itemInfo: ListRenderItemInfo<TItem>) => {
73
134
  return (
74
135
  <Box
@@ -163,33 +224,82 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
163
224
  </Box>
164
225
  </View>
165
226
  );
166
- } else {
227
+ }
228
+
229
+ if (
230
+ desktopChildrenMinWidth !== undefined &&
231
+ elementArray.length >= 1 &&
232
+ elementArray.length <= 2
233
+ ) {
234
+ const childCount = elementArray.length;
235
+ const childWidth =
236
+ desktopScrollWidth > 0
237
+ ? Math.max(desktopChildrenMinWidth, desktopScrollWidth / childCount)
238
+ : desktopChildrenMinWidth;
239
+ const rowWidth = Math.max(
240
+ desktopScrollWidth,
241
+ desktopChildrenMinWidth * childCount,
242
+ childWidth * childCount
243
+ );
167
244
  return (
168
- <Box alignItems="center" direction="row" flex="grow" justifyContent="center" paddingX={2}>
245
+ <ScrollView
246
+ contentContainerStyle={{flexDirection: "row", width: rowWidth}}
247
+ horizontal
248
+ nestedScrollEnabled
249
+ onLayout={(event: LayoutChangeEvent) => {
250
+ const nextWidth = event.nativeEvent.layout.width;
251
+ setDesktopScrollWidth((current) => (current === nextWidth ? current : nextWidth));
252
+ }}
253
+ style={{flex: 1, height: "100%"}}
254
+ testID="split-page-desktop-children-scroll"
255
+ >
169
256
  {elementArray.map((element, index) => {
170
257
  return (
171
258
  <ScrollView
172
- contentContainerStyle={{
173
- flex: 1,
174
- }}
259
+ contentContainerStyle={{flexGrow: 1}}
175
260
  key={index}
176
261
  style={{
177
- flex: 1,
262
+ flexGrow: 0,
263
+ flexShrink: 0,
178
264
  height: "100%",
179
- width: "60%",
265
+ maxWidth: childWidth,
266
+ width: childWidth,
180
267
  }}
268
+ testID={`split-page-desktop-child-${index}`}
181
269
  >
182
270
  {element}
183
271
  </ScrollView>
184
272
  );
185
273
  })}
186
- </Box>
274
+ </ScrollView>
187
275
  );
188
276
  }
277
+
278
+ return (
279
+ <Box alignItems="center" direction="row" flex="grow" justifyContent="center" paddingX={2}>
280
+ {elementArray.map((element, index) => {
281
+ return (
282
+ <ScrollView
283
+ contentContainerStyle={{
284
+ flex: 1,
285
+ }}
286
+ key={index}
287
+ style={{
288
+ flex: 1,
289
+ height: "100%",
290
+ width: "60%",
291
+ }}
292
+ >
293
+ {element}
294
+ </ScrollView>
295
+ );
296
+ })}
297
+ </Box>
298
+ );
189
299
  };
190
300
 
191
301
  const renderMobileList = () => {
192
- if (isMobileLayout && selectedId !== undefined) {
302
+ if (isNarrowLayout && isDetailActive) {
193
303
  return null;
194
304
  }
195
305
 
@@ -218,13 +328,13 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
218
328
  };
219
329
 
220
330
  const renderMobileListContent = () => {
221
- if (isMobileLayout && selectedId === undefined) {
331
+ if (isNarrowLayout && !isDetailActive) {
222
332
  return null;
223
333
  }
224
334
 
225
335
  return (
226
336
  <Box flex="grow" padding={2}>
227
- {isMobileLayout && (
337
+ {isNarrowLayout && (
228
338
  <Box width="100%">
229
339
  <IconButton
230
340
  accessibilityHint="close split page"
@@ -239,10 +349,126 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
239
349
  );
240
350
  };
241
351
 
352
+ const showMobileChild = (destination: number): void => {
353
+ setActiveChildIndex(destination);
354
+ swiperRef.current?.scrollToIndex({animated: true, index: destination});
355
+ };
356
+
357
+ const renderLabeledMobilePager = (labels: string[]) => {
358
+ const pageWidth = measuredPageWidth > 0 ? measuredPageWidth : windowWidth;
359
+ const lastIndex = elementArray.length - 1;
360
+ const controlBottom = (bottomNavBarHeight ?? 0) + 8;
361
+ return (
362
+ <View
363
+ onLayout={(event: LayoutChangeEvent) => {
364
+ const nextWidth = event.nativeEvent.layout.width;
365
+ setMeasuredPageWidth((current) => (current === nextWidth ? current : nextWidth));
366
+ }}
367
+ style={{flex: 1, width: "100%"}}
368
+ testID="split-page-mobile-children"
369
+ >
370
+ <SwiperFlatList
371
+ getItemLayout={(_data, index) => ({
372
+ index,
373
+ length: pageWidth,
374
+ offset: pageWidth * index,
375
+ })}
376
+ nestedScrollEnabled
377
+ onChangeIndex={({index}) => {
378
+ setActiveChildIndex(index);
379
+ }}
380
+ ref={swiperRef}
381
+ renderAll
382
+ style={{width: "100%"}}
383
+ >
384
+ {elementArray.map((element, index) => {
385
+ return (
386
+ <View
387
+ key={index}
388
+ style={{
389
+ height: "100%",
390
+ padding: 0,
391
+ paddingBottom: bottomNavBarHeight,
392
+ width: pageWidth,
393
+ }}
394
+ testID={`split-page-mobile-child-${index}`}
395
+ >
396
+ {element}
397
+ </View>
398
+ );
399
+ })}
400
+ </SwiperFlatList>
401
+ {narrowViewportListButtonLabel ? (
402
+ <View
403
+ style={{
404
+ bottom: controlBottom,
405
+ left: 16,
406
+ position: "absolute",
407
+ zIndex: 1,
408
+ }}
409
+ >
410
+ <IconButton
411
+ accessibilityHint={narrowViewportListButtonLabel}
412
+ accessibilityLabel={narrowViewportListButtonLabel}
413
+ backgroundOpacity={0.88}
414
+ iconName="arrow-left"
415
+ onClick={() => onItemDeselect()}
416
+ testID="split-page-back-to-list"
417
+ variant="muted"
418
+ />
419
+ </View>
420
+ ) : null}
421
+ <View
422
+ style={{
423
+ bottom: controlBottom,
424
+ flexDirection: "row",
425
+ gap: 8,
426
+ position: "absolute",
427
+ right: 16,
428
+ zIndex: 1,
429
+ }}
430
+ >
431
+ {activeChildIndex > 0 ? (
432
+ <IconButton
433
+ accessibilityLabel={`Show previous column: ${labels[activeChildIndex - 1]}`}
434
+ backgroundOpacity={0.88}
435
+ iconName="chevron-left"
436
+ onClick={() => {
437
+ showMobileChild(activeChildIndex - 1);
438
+ }}
439
+ testID="split-page-column-previous"
440
+ variant="muted"
441
+ />
442
+ ) : null}
443
+ {activeChildIndex < lastIndex ? (
444
+ <IconButton
445
+ accessibilityLabel={`Show next column: ${labels[activeChildIndex + 1]}`}
446
+ backgroundOpacity={0.88}
447
+ iconName="chevron-right"
448
+ onClick={() => {
449
+ showMobileChild(activeChildIndex + 1);
450
+ }}
451
+ testID="split-page-column-next"
452
+ variant="muted"
453
+ />
454
+ ) : null}
455
+ </View>
456
+ </View>
457
+ );
458
+ };
459
+
242
460
  const renderMobileChildrenContent = () => {
243
- if (selectedId === undefined) {
461
+ if (!isDetailActive) {
244
462
  return null;
245
463
  }
464
+ if (
465
+ isNarrowLayout &&
466
+ elementArray.length > 1 &&
467
+ narrowViewportChildLabels !== undefined &&
468
+ narrowViewportChildLabels.length === elementArray.length
469
+ ) {
470
+ return renderLabeledMobilePager(narrowViewportChildLabels);
471
+ }
246
472
  return (
247
473
  <SwiperFlatList
248
474
  nestedScrollEnabled
@@ -259,7 +485,7 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
259
485
  height: elementArray.length > 1 ? "90%" : "100%",
260
486
  padding: 4,
261
487
  paddingBottom: bottomNavBarHeight,
262
- width: width - 8,
488
+ width: windowWidth - 8,
263
489
  }}
264
490
  >
265
491
  {element}
@@ -283,9 +509,17 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
283
509
  const renderMainContent = renderContent
284
510
  ? renderMobileListContent()
285
511
  : renderMobileChildrenContent();
286
- return selectedId === undefined ? renderMobileList() : renderMainContent;
512
+ return isDetailActive ? renderMainContent : renderMobileList();
287
513
  };
288
514
 
515
+ const isLabeledPagerBody =
516
+ isNarrowLayout &&
517
+ isDetailActive &&
518
+ !renderContent &&
519
+ elementArray.length > 1 &&
520
+ narrowViewportChildLabels !== undefined &&
521
+ narrowViewportChildLabels.length === elementArray.length;
522
+
289
523
  return (
290
524
  <Box
291
525
  avoidKeyboard
@@ -294,7 +528,7 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
294
528
  display="flex"
295
529
  height="100%"
296
530
  keyboardOffset={keyboardOffset}
297
- padding={2}
531
+ padding={isLabeledPagerBody ? 0 : 2}
298
532
  width="100%"
299
533
  >
300
534
  {loading === true && (
@@ -303,7 +537,7 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
303
537
  size="md"
304
538
  />
305
539
  )}
306
- {isMobileLayout ? renderMobileSplitPage() : renderSplitPage()}
540
+ {isNarrowLayout ? renderMobileSplitPage() : renderSplitPage()}
307
541
  </Box>
308
542
  );
309
543
  };
@@ -3,7 +3,7 @@ import {fireEvent} from "@testing-library/react-native";
3
3
  import {forwardRef} from "react";
4
4
  import {Text, View} from "react-native";
5
5
 
6
- import {isMobileDevice} from "./MediaQuery";
6
+ import {isNarrowViewport} from "./MediaQuery";
7
7
  import {renderWithTheme} from "./test-utils";
8
8
  import {UnifiedAddressAutoCompleteField} from "./UnifiedAddressAutoComplete";
9
9
 
@@ -136,11 +136,11 @@ describe("UnifiedAddressAutoCompleteField", () => {
136
136
 
137
137
  describe("mobile/native branch", () => {
138
138
  afterEach(() => {
139
- (isMobileDevice as ReturnType<typeof mock>).mockImplementation(() => false);
139
+ (isNarrowViewport as ReturnType<typeof mock>).mockImplementation(() => false);
140
140
  });
141
141
 
142
- it("renders MobileAddressAutocomplete when isMobileDevice + isNative + valid key", () => {
143
- (isMobileDevice as ReturnType<typeof mock>).mockImplementation(() => true);
142
+ it("renders MobileAddressAutocomplete when isNarrowViewport + isNative + valid key", () => {
143
+ (isNarrowViewport as ReturnType<typeof mock>).mockImplementation(() => true);
144
144
  const {getByTestId} = renderWithTheme(
145
145
  <UnifiedAddressAutoCompleteField
146
146
  {...defaultProps}
@@ -1,7 +1,7 @@
1
1
  import {useMemo} from "react";
2
2
 
3
3
  import type {AddressAutocompleteProps} from "./Common";
4
- import {isMobileDevice} from "./MediaQuery";
4
+ import {isNarrowViewport} from "./MediaQuery";
5
5
  import {MobileAddressAutocomplete} from "./MobileAddressAutoComplete";
6
6
  import {TextField} from "./TextField";
7
7
  import {isNative, isValidGoogleApiKey} from "./Utilities";
@@ -35,7 +35,7 @@ export const UnifiedAddressAutoCompleteField = ({
35
35
  testID={testID}
36
36
  />
37
37
  );
38
- } else if (isMobileDevice() && isNative() && isValidatedGoogleApiKey) {
38
+ } else if (isNarrowViewport() && isNative() && isValidatedGoogleApiKey) {
39
39
  return (
40
40
  <MobileAddressAutocomplete
41
41
  disabled={disabled}
@@ -1,6 +1,6 @@
1
1
  // Bun Snapshot v1, https://bun.sh/docs/test/snapshots
2
2
 
3
- exports[`Filter renders correctly with default props 1`] = `
3
+ exports[`DropdownPanel renders correctly with default props 1`] = `
4
4
  {
5
5
  "$$typeof": Symbol(react.test.json),
6
6
  "children": [
@@ -141,10 +141,13 @@ exports[`Filter renders correctly with default props 1`] = `
141
141
  },
142
142
  ],
143
143
  "props": {
144
+ "collapsable": false,
144
145
  "ref": {
145
146
  "current": null,
146
147
  },
147
- "style": undefined,
148
+ "style": {
149
+ "alignSelf": "flex-start",
150
+ },
148
151
  "testID": undefined,
149
152
  },
150
153
  "type": "View",
@@ -153,6 +156,7 @@ exports[`Filter renders correctly with default props 1`] = `
153
156
  "props": {
154
157
  "style": {
155
158
  "position": "relative",
159
+ "width": undefined,
156
160
  },
157
161
  "testID": undefined,
158
162
  },
package/src/bunSetup.ts CHANGED
@@ -727,6 +727,8 @@ mock.module("@react-native-async-storage/async-storage", () => ({
727
727
  setItem: mock(() => Promise.resolve()),
728
728
  }));
729
729
 
730
+ const mockPortalContext = React.createContext<unknown>(null);
731
+
730
732
  // Mock the portal host. The real `Host` wraps children in an extra View
731
733
  // whose presence makes snapshots brittle, and individual tests already mock
732
734
  // this to render inline; hoisting the mock to setup keeps test ordering from
@@ -737,6 +739,10 @@ mock.module("./PortalHost", () => ({
737
739
  React.createElement("View", {testID: "portal-host"}, children),
738
740
  Portal: ({children}: MockComponentProps) =>
739
741
  React.createElement("View", {testID: "portal"}, children),
742
+ // Components that only portal when a host is mounted read this context. It defaults to
743
+ // null (no host) so they keep rendering inline; tests that want the portal path wrap the
744
+ // tree in `PortalContext.Provider`.
745
+ PortalContext: mockPortalContext,
740
746
  }));
741
747
 
742
748
  // Mock IconButton component
@@ -844,8 +850,9 @@ mock.module("react-native-actions-sheet", () => ({
844
850
 
845
851
  // Mock MediaQuery
846
852
  mock.module("./MediaQuery", () => ({
847
- isMobileDevice: mock(() => false),
853
+ isNarrowViewport: mock(() => false),
848
854
  mediaQueryLargerThan: mock(() => false),
855
+ mediaQuerySmallerThan: mock(() => false),
849
856
  }));
850
857
 
851
858
  // Mock expo-image-manipulator
@@ -7,13 +7,13 @@ import {Box} from "./Box";
7
7
  import {Button} from "./Button";
8
8
  import type {DataTableColumnFilter} from "./Common";
9
9
  import {DateTimeField} from "./DateTimeField";
10
+ import {DropdownPanel} from "./DropdownPanel";
10
11
  import {
11
12
  DATA_TABLE_CHOICE_EMPTY_LABEL,
12
13
  DATA_TABLE_CHOICE_EMPTY_VALUE,
13
14
  endOfUtcDay,
14
15
  startOfUtcDay,
15
16
  } from "./dataTableListQuery";
16
- import {Filter} from "./Filter";
17
17
  import {MultiselectField} from "./MultiselectField";
18
18
  import {NumberField} from "./NumberField";
19
19
  import {TextField} from "./TextField";
@@ -333,7 +333,7 @@ export const DataTableColumnFilterWeb: FC<DataTableColumnFilterWebProps> = ({
333
333
  }
334
334
 
335
335
  return (
336
- <Filter
336
+ <DropdownPanel
337
337
  iconName="filter"
338
338
  iconOnly
339
339
  isOpen={isOpen}
@@ -351,7 +351,7 @@ export const DataTableColumnFilterWeb: FC<DataTableColumnFilterWebProps> = ({
351
351
  filters={[filter]}
352
352
  onDraftChange={setDraftValuesSync}
353
353
  />
354
- </Filter>
354
+ </DropdownPanel>
355
355
  );
356
356
  };
357
357
 
@@ -419,7 +419,7 @@ export const DataTableAdditionalFiltersWeb: FC<DataTableAdditionalFiltersWebProp
419
419
  }
420
420
 
421
421
  return (
422
- <Filter
422
+ <DropdownPanel
423
423
  iconName="filter"
424
424
  isOpen={isOpen}
425
425
  label="More filters"
@@ -436,6 +436,6 @@ export const DataTableAdditionalFiltersWeb: FC<DataTableAdditionalFiltersWebProp
436
436
  onDraftChange={setDraftValuesSync}
437
437
  showFieldClear
438
438
  />
439
- </Filter>
439
+ </DropdownPanel>
440
440
  );
441
441
  };
@@ -0,0 +1,140 @@
1
+ import {describe, expect, it} from "bun:test";
2
+
3
+ import {
4
+ computeDropdownPanelLayout,
5
+ DROPDOWN_PANEL_MIN_HEIGHT,
6
+ DROPDOWN_PANEL_SCREEN_MARGIN,
7
+ } from "./dropdownPanelLayout";
8
+
9
+ const viewport = {viewportHeight: 800, viewportWidth: 1200};
10
+
11
+ describe("computeDropdownPanelLayout", () => {
12
+ it("left-aligns to the trigger when the panel fits", () => {
13
+ const layout = computeDropdownPanelLayout({
14
+ anchor: {height: 40, width: 100, x: 100, y: 60},
15
+ panelWidth: 320,
16
+ ...viewport,
17
+ });
18
+ expect(layout.left).toBe(100);
19
+ expect(layout.top).toBe(104);
20
+ expect(layout.placement).toBe("below");
21
+ });
22
+
23
+ it("right-aligns to the trigger when a left-aligned panel would overflow", () => {
24
+ // The To Do's filter button sits at the right edge of the action row, where a
25
+ // left-aligned panel ran off screen.
26
+ const layout = computeDropdownPanelLayout({
27
+ anchor: {height: 40, width: 120, x: 1040, y: 60},
28
+ panelWidth: 340,
29
+ ...viewport,
30
+ });
31
+ // Right edge of the panel lines up with the right edge of the trigger.
32
+ expect(layout.left).toBe(1040 + 120 - 340);
33
+ });
34
+
35
+ it("clamps a right-aligned panel to the left screen margin", () => {
36
+ const layout = computeDropdownPanelLayout({
37
+ anchor: {height: 40, width: 60, x: 100, y: 60},
38
+ panelWidth: 340,
39
+ viewportHeight: 800,
40
+ viewportWidth: 360,
41
+ });
42
+ expect(layout.left).toBe(DROPDOWN_PANEL_SCREEN_MARGIN);
43
+ });
44
+
45
+ it("narrows a panel wider than the viewport so both edges stay inside the margins", () => {
46
+ const layout = computeDropdownPanelLayout({
47
+ anchor: {height: 40, width: 60, x: 120, y: 60},
48
+ panelWidth: 400,
49
+ viewportHeight: 800,
50
+ viewportWidth: 320,
51
+ });
52
+ expect(layout.left).toBe(DROPDOWN_PANEL_SCREEN_MARGIN);
53
+ // Moving the panel cannot keep a 400px panel on a 320px screen, so it shrinks.
54
+ expect(layout.width).toBe(320 - DROPDOWN_PANEL_SCREEN_MARGIN * 2);
55
+ expect(layout.left + layout.width).toBe(320 - DROPDOWN_PANEL_SCREEN_MARGIN);
56
+ });
57
+
58
+ it("leaves the requested width alone when it fits", () => {
59
+ const layout = computeDropdownPanelLayout({
60
+ anchor: {height: 40, width: 100, x: 100, y: 60},
61
+ panelWidth: 320,
62
+ ...viewport,
63
+ });
64
+ expect(layout.width).toBe(320);
65
+ });
66
+
67
+ it("right-aligns against the narrowed width on a cramped viewport", () => {
68
+ // A trigger near the right edge of a small phone: the panel narrows first, then the
69
+ // right-align uses that narrowed width so it still lines up with the trigger.
70
+ const layout = computeDropdownPanelLayout({
71
+ anchor: {height: 40, width: 80, x: 240, y: 60},
72
+ panelWidth: 340,
73
+ viewportHeight: 800,
74
+ viewportWidth: 320,
75
+ });
76
+ expect(layout.width).toBe(304);
77
+ expect(layout.left).toBe(DROPDOWN_PANEL_SCREEN_MARGIN);
78
+ expect(layout.left + layout.width).toBeLessThanOrEqual(320 - DROPDOWN_PANEL_SCREEN_MARGIN);
79
+ });
80
+
81
+ it("honours an explicit alignment over the auto behaviour", () => {
82
+ const anchor = {height: 40, width: 120, x: 400, y: 60};
83
+ expect(
84
+ computeDropdownPanelLayout({align: "end", anchor, panelWidth: 320, ...viewport}).left
85
+ ).toBe(200);
86
+ expect(
87
+ computeDropdownPanelLayout({align: "start", anchor, panelWidth: 320, ...viewport}).left
88
+ ).toBe(400);
89
+ });
90
+
91
+ it("flips above the trigger when there is no usable room below", () => {
92
+ const layout = computeDropdownPanelLayout({
93
+ anchor: {height: 40, width: 120, x: 100, y: 720},
94
+ panelWidth: 320,
95
+ ...viewport,
96
+ });
97
+ expect(layout.placement).toBe("above");
98
+ expect(layout.top).toBeUndefined();
99
+ expect(layout.bottom).toBe(800 - 720 + 4);
100
+ });
101
+
102
+ it("stays below the trigger when the space above is even smaller", () => {
103
+ const layout = computeDropdownPanelLayout({
104
+ anchor: {height: 40, width: 120, x: 100, y: 10},
105
+ panelWidth: 320,
106
+ viewportHeight: 220,
107
+ viewportWidth: 1200,
108
+ });
109
+ expect(layout.placement).toBe("below");
110
+ });
111
+
112
+ it("caps the panel height to the space available and scrolls the rest", () => {
113
+ const layout = computeDropdownPanelLayout({
114
+ anchor: {height: 40, width: 120, x: 100, y: 60},
115
+ panelWidth: 320,
116
+ ...viewport,
117
+ });
118
+ expect(layout.maxHeight).toBe(800 - 104 - DROPDOWN_PANEL_SCREEN_MARGIN);
119
+ });
120
+
121
+ it("never shrinks below the minimum usable height", () => {
122
+ const layout = computeDropdownPanelLayout({
123
+ anchor: {height: 40, width: 120, x: 100, y: 120},
124
+ panelWidth: 320,
125
+ viewportHeight: 300,
126
+ viewportWidth: 1200,
127
+ });
128
+ expect(layout.maxHeight).toBe(DROPDOWN_PANEL_MIN_HEIGHT);
129
+ });
130
+
131
+ it("applies a caller-supplied height ceiling", () => {
132
+ const layout = computeDropdownPanelLayout({
133
+ anchor: {height: 40, width: 120, x: 100, y: 60},
134
+ maxPanelHeight: 240,
135
+ panelWidth: 320,
136
+ ...viewport,
137
+ });
138
+ expect(layout.maxHeight).toBe(240);
139
+ });
140
+ });