MCPcopy Create free account
hub / github.com/FeatureProbe/FeatureProbe / useFormErrorScrollIntoView

Function useFormErrorScrollIntoView

ui/src/hooks.ts:37–74  ·  view source on GitHub ↗
(errors?: FieldErrors)

Source from the content-addressed store, hash-verified

35};
36
37export const useFormErrorScrollIntoView = (errors?: FieldErrors) => {
38 const errorRef = useRef(errors);
39 const beforeScroll = useRef<(names: string[]) => void>();
40
41 useEffect(() => {
42 errorRef.current = errors;
43 }, [errors]);
44
45 const scrollToError = useCallback(() => {
46 if(errorRef.current) {
47 const names = Object.keys(errorRef.current);
48 if(beforeScroll.current) {
49 beforeScroll.current(names);
50 }
51 setTimeout(() => {
52 document.querySelector(`[name=${names[0]}]`)?.scrollIntoView({ behavior: 'smooth', block: 'center' });
53 });
54 }
55 }, [errorRef]);
56
57 const registerErrorName = useCallback((name: string) => {
58 return {
59 ref: (ref: unknown) => {
60 (ref as HTMLElement)?.setAttribute('name', name);
61 }
62 };
63 }, []);
64
65 const setBeforeScrollCallback = useCallback((fc: (names: string[]) => void) => {
66 beforeScroll.current = fc;
67 }, [beforeScroll]);
68
69 return {
70 scrollToError,
71 registerErrorName,
72 setBeforeScrollCallback,
73 };
74};
75
76export const useQuery = () => {
77 const { search } = useLocation();

Callers 6

VariationsFunction · 0.90
ServeFunction · 0.90
RuleContentFunction · 0.90
index.tsxFile · 0.90
InfoFunction · 0.90
DrawerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected