@brightlocal/ui-components 1.2.1 → 1.2.2
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/component-meta.json +112 -474
- package/dist/centred-layout.d.ts +1 -1
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.d.ts +2 -2
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +177 -150
- package/package.json +1 -1
- package/src/components/centred-layout.tsx +1 -1
- package/src/components/combobox.tsx +97 -4
|
@@ -330,8 +330,8 @@ export interface ComboboxContentProps {
|
|
|
330
330
|
children: React.ReactNode;
|
|
331
331
|
/** Alignment of the popover relative to trigger */
|
|
332
332
|
align?: "start" | "center" | "end";
|
|
333
|
-
/** Which side of the trigger to render the popover. @default "bottom" */
|
|
334
|
-
side?: "top" | "
|
|
333
|
+
/** Which side of the trigger to render the popover. Only vertical positioning is supported — the dropdown spans the full trigger width. @default "bottom" */
|
|
334
|
+
side?: "top" | "bottom";
|
|
335
335
|
/** Distance in px between the trigger and the popover. @default 4 */
|
|
336
336
|
sideOffset?: number;
|
|
337
337
|
/**
|
|
@@ -358,7 +358,99 @@ function ComboboxContent({
|
|
|
358
358
|
avoidCollisions,
|
|
359
359
|
hideList = false,
|
|
360
360
|
}: ComboboxContentProps) {
|
|
361
|
-
const { shouldFilter, itemToStringValue } = useComboboxContext();
|
|
361
|
+
const { open, shouldFilter, itemToStringValue } = useComboboxContext();
|
|
362
|
+
|
|
363
|
+
// TODO: This is a workaround for floating-ui re-flipping on content resize.
|
|
364
|
+
// The root cause is that Radix Popper's autoUpdate watches elementResize and
|
|
365
|
+
// re-runs the full middleware pipeline (including flip) every time the list
|
|
366
|
+
// shrinks during filtering. Ideally this would be solved at a lower level:
|
|
367
|
+
//
|
|
368
|
+
// 1. Radix exposes `updatePositionStrategy` but not fine-grained autoUpdate
|
|
369
|
+
// options (e.g. disabling `elementResize` or `layoutShift` listeners).
|
|
370
|
+
// If Radix adds this, we can disable elementResize and remove this hack.
|
|
371
|
+
// Track: https://github.com/radix-ui/primitives/issues
|
|
372
|
+
//
|
|
373
|
+
// 2. Build a base-ui / headless Combobox with floating-ui directly, where
|
|
374
|
+
// we control the autoUpdate config and middleware pipeline. This would
|
|
375
|
+
// let us disable flip after initial placement or use a custom middleware
|
|
376
|
+
// that only flips on scroll/viewport changes, not content resize.
|
|
377
|
+
//
|
|
378
|
+
// 3. Use Radix's `updatePositionStrategy="optimized"` — but this only
|
|
379
|
+
// throttles updates, it doesn't prevent flip on resize specifically.
|
|
380
|
+
//
|
|
381
|
+
// Current workaround: lock the resolved `data-side` after initial open via
|
|
382
|
+
// MutationObserver + double-rAF, then force that side on subsequent renders.
|
|
383
|
+
// Works but adds complexity. Remove when a proper upstream fix is available.
|
|
384
|
+
//
|
|
385
|
+
// Lock the resolved side after initial open so that content resizes
|
|
386
|
+
// (e.g. filtering the list) don't cause the dropdown to flip.
|
|
387
|
+
// Scroll repositioning and shift still work because avoidCollisions
|
|
388
|
+
// stays enabled — only the preferred `side` is locked.
|
|
389
|
+
const [lockedSide, setLockedSide] = React.useState<"top" | "bottom" | null>(
|
|
390
|
+
null
|
|
391
|
+
);
|
|
392
|
+
const cleanupRef = React.useRef<(() => void) | null>(null);
|
|
393
|
+
|
|
394
|
+
// When the popover content mounts, detect the resolved side via two
|
|
395
|
+
// complementary strategies and lock it:
|
|
396
|
+
// 1. MutationObserver — catches the flip (data-side changes from the
|
|
397
|
+
// initial preferred side to the resolved side after computePosition).
|
|
398
|
+
// 2. Double rAF fallback — if no flip occurs, data-side never changes,
|
|
399
|
+
// so we read it after two animation frames when positioning is done.
|
|
400
|
+
// Note: safe under React StrictMode — the triple ref-callback invocation
|
|
401
|
+
// (node → null → node) is handled by the cleanup/done guard pattern.
|
|
402
|
+
const handleContentRef = React.useCallback((node: HTMLDivElement | null) => {
|
|
403
|
+
// Cleanup previous observer/timers
|
|
404
|
+
cleanupRef.current?.();
|
|
405
|
+
cleanupRef.current = null;
|
|
406
|
+
|
|
407
|
+
if (!node) return;
|
|
408
|
+
|
|
409
|
+
let done = false;
|
|
410
|
+
const lock = (attr: string | null) => {
|
|
411
|
+
if (done) return;
|
|
412
|
+
if (attr === "top" || attr === "bottom") {
|
|
413
|
+
done = true;
|
|
414
|
+
observer.disconnect();
|
|
415
|
+
setLockedSide(attr);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
// Strategy 1: observe data-side attribute mutations (catches flip)
|
|
420
|
+
const observer = new MutationObserver(() => {
|
|
421
|
+
lock(node.getAttribute("data-side"));
|
|
422
|
+
});
|
|
423
|
+
observer.observe(node, {
|
|
424
|
+
attributes: true,
|
|
425
|
+
attributeFilter: ["data-side"],
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
// Strategy 2: double rAF fallback (catches no-flip case where
|
|
429
|
+
// data-side is set during initial render and never changes)
|
|
430
|
+
let rafOuter = 0;
|
|
431
|
+
let rafInner = 0;
|
|
432
|
+
rafOuter = requestAnimationFrame(() => {
|
|
433
|
+
rafInner = requestAnimationFrame(() => {
|
|
434
|
+
lock(node.getAttribute("data-side"));
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
cleanupRef.current = () => {
|
|
439
|
+
done = true;
|
|
440
|
+
observer.disconnect();
|
|
441
|
+
cancelAnimationFrame(rafOuter);
|
|
442
|
+
cancelAnimationFrame(rafInner);
|
|
443
|
+
};
|
|
444
|
+
}, []);
|
|
445
|
+
|
|
446
|
+
// Reset locked side when popover closes
|
|
447
|
+
React.useEffect(() => {
|
|
448
|
+
if (!open) {
|
|
449
|
+
cleanupRef.current?.();
|
|
450
|
+
cleanupRef.current = null;
|
|
451
|
+
setLockedSide(null);
|
|
452
|
+
}
|
|
453
|
+
}, [open]);
|
|
362
454
|
|
|
363
455
|
const filter = React.useMemo(() => {
|
|
364
456
|
if (!itemToStringValue) return undefined;
|
|
@@ -368,12 +460,13 @@ function ComboboxContent({
|
|
|
368
460
|
|
|
369
461
|
return (
|
|
370
462
|
<PopoverContent
|
|
463
|
+
ref={handleContentRef}
|
|
371
464
|
align={align}
|
|
372
465
|
aria-label="Options"
|
|
373
466
|
avoidCollisions={avoidCollisions}
|
|
374
467
|
className={cn("w-[var(--radix-popover-trigger-width)] p-0", className)}
|
|
375
468
|
data-slot="combobox-popover"
|
|
376
|
-
side={side}
|
|
469
|
+
side={lockedSide ?? side}
|
|
377
470
|
sideOffset={sideOffset}
|
|
378
471
|
>
|
|
379
472
|
<Command
|