Fix layout shift on controls search
Signed-off-by: Bryan Frimin <bryan@getprobo.com> Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
committed by
Sacha Al Himdani
parent
b841e86964
commit
f22eb86196
@@ -14,6 +14,7 @@ import {
|
|||||||
Suspense,
|
Suspense,
|
||||||
useMemo,
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
|
useState,
|
||||||
type ReactNode,
|
type ReactNode,
|
||||||
type RefObject,
|
type RefObject,
|
||||||
} from "react";
|
} from "react";
|
||||||
@@ -82,7 +83,10 @@ type SearchRef = RefObject<{ search: (v: string) => void } | null>;
|
|||||||
export function LinkedControlsDialog(props: Props) {
|
export function LinkedControlsDialog(props: Props) {
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
const searchRef: SearchRef = useRef(null);
|
const searchRef: SearchRef = useRef(null);
|
||||||
|
const contentRef = useRef<HTMLDivElement>(null);
|
||||||
|
const [minHeight, setMinHeight] = useState(0);
|
||||||
const onSearch = (v: string) => {
|
const onSearch = (v: string) => {
|
||||||
|
setMinHeight(contentRef.current?.clientHeight ?? 0);
|
||||||
searchRef.current?.search(v);
|
searchRef.current?.search(v);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
@@ -95,9 +99,17 @@ export function LinkedControlsDialog(props: Props) {
|
|||||||
onValueChange={onSearch}
|
onValueChange={onSearch}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Suspense fallback={<Spinner centered />}>
|
<div ref={contentRef}>
|
||||||
|
<Suspense
|
||||||
|
fallback={
|
||||||
|
<div style={{ minHeight }}>
|
||||||
|
<Spinner centered />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
<LinkedControlsDialogContent {...props} ref={searchRef} />
|
<LinkedControlsDialogContent {...props} ref={searchRef} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user