@cdx-ui/utils 0.0.1-beta.7 → 0.0.1-beta.70

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 (33) hide show
  1. package/README.md +45 -22
  2. package/lib/commonjs/common/mergeRefs.js +39 -1
  3. package/lib/commonjs/common/mergeRefs.js.map +1 -1
  4. package/lib/commonjs/form-control/index.js +6 -0
  5. package/lib/commonjs/form-control/index.js.map +1 -1
  6. package/lib/commonjs/form-control/useFormControl.js +33 -0
  7. package/lib/commonjs/form-control/useFormControl.js.map +1 -1
  8. package/lib/module/common/mergeRefs.js +39 -1
  9. package/lib/module/common/mergeRefs.js.map +1 -1
  10. package/lib/module/form-control/index.js +1 -1
  11. package/lib/module/form-control/index.js.map +1 -1
  12. package/lib/module/form-control/useFormControl.js +33 -0
  13. package/lib/module/form-control/useFormControl.js.map +1 -1
  14. package/lib/typescript/common/mergeRefs.d.ts +8 -0
  15. package/lib/typescript/common/mergeRefs.d.ts.map +1 -1
  16. package/lib/typescript/form-control/index.d.ts +1 -1
  17. package/lib/typescript/form-control/index.d.ts.map +1 -1
  18. package/lib/typescript/form-control/useFormControl.d.ts +28 -3
  19. package/lib/typescript/form-control/useFormControl.d.ts.map +1 -1
  20. package/package.json +4 -2
  21. package/src/common/accessibilityUtils.test.ts +12 -0
  22. package/src/common/cn.test.ts +19 -0
  23. package/src/common/composeEventHandlers.test.ts +35 -0
  24. package/src/common/getSpacedChild.test.tsx +64 -0
  25. package/src/common/mergeRefs.test.ts +148 -0
  26. package/src/common/mergeRefs.ts +45 -2
  27. package/src/common/useControllableState.test.tsx +90 -0
  28. package/src/context/createContext.test.tsx +31 -0
  29. package/src/form-control/index.ts +2 -0
  30. package/src/form-control/useFormControl.test.tsx +214 -0
  31. package/src/form-control/useFormControl.tsx +48 -4
  32. package/src/style/context/index.test.tsx +31 -0
  33. package/src/style/withStyleContext/index.test.tsx +55 -0
@@ -0,0 +1,64 @@
1
+ import React, { isValidElement } from 'react';
2
+ import { Text } from 'react-native';
3
+ import { flattenChildren } from './getSpacedChild';
4
+
5
+ describe('flattenChildren', () => {
6
+ it('flattens fragment children', () => {
7
+ const result = flattenChildren(
8
+ <>
9
+ <Text key="a">A</Text>
10
+ <Text key="b">B</Text>
11
+ </>,
12
+ );
13
+
14
+ expect(result).toHaveLength(2);
15
+ expect(isValidElement(result[0]) && result[0].type).toBe(Text);
16
+ expect(isValidElement(result[1]) && result[1].type).toBe(Text);
17
+ });
18
+
19
+ it('assigns composite keys to nested fragment children', () => {
20
+ const result = flattenChildren(
21
+ <React.Fragment key="group">
22
+ <Text key="child">Child</Text>
23
+ </React.Fragment>,
24
+ );
25
+
26
+ expect(result).toHaveLength(1);
27
+ const key = isValidElement(result[0]) ? String(result[0].key) : '';
28
+ expect(key).toContain('group');
29
+ expect(key).toContain('child');
30
+ });
31
+
32
+ it('passes through non-element children', () => {
33
+ const result = flattenChildren(['plain', <Text key="t">T</Text>]);
34
+
35
+ expect(result).toHaveLength(2);
36
+ expect(result[0]).toBe('plain');
37
+ });
38
+
39
+ it('preserves explicit element keys', () => {
40
+ const result = flattenChildren(<Text key="explicit">Label</Text>);
41
+
42
+ expect(result).toHaveLength(1);
43
+ const key = isValidElement(result[0]) ? String(result[0].key) : '';
44
+ expect(key).toContain('explicit');
45
+ });
46
+
47
+ it('uses index keys when fragment and child keys are missing', () => {
48
+ const result = flattenChildren(
49
+ <>
50
+ <Text>First</Text>
51
+ <React.Fragment>
52
+ <Text>Nested</Text>
53
+ </React.Fragment>
54
+ </>,
55
+ );
56
+
57
+ expect(result).toHaveLength(2);
58
+ const firstKey = isValidElement(result[0]) ? String(result[0].key) : '';
59
+ const secondKey = isValidElement(result[1]) ? String(result[1].key) : '';
60
+ expect(firstKey).toContain('0');
61
+ expect(secondKey).toContain('1');
62
+ expect(secondKey).toContain('0');
63
+ });
64
+ });
@@ -0,0 +1,148 @@
1
+ import { createRef } from 'react';
2
+ import { mergeRefs } from './mergeRefs';
3
+
4
+ describe('mergeRefs', () => {
5
+ it('assigns value to object refs', () => {
6
+ const refA = createRef<string>();
7
+ const refB = createRef<string>();
8
+
9
+ mergeRefs(refA, refB)('value');
10
+
11
+ expect(refA.current).toBe('value');
12
+ expect(refB.current).toBe('value');
13
+ });
14
+
15
+ it('invokes callback refs', () => {
16
+ const callback = jest.fn();
17
+
18
+ mergeRefs(callback)('value');
19
+
20
+ expect(callback).toHaveBeenCalledWith('value');
21
+ });
22
+
23
+ it('skips undefined refs and assigns null', () => {
24
+ const ref = createRef<string | null>();
25
+
26
+ mergeRefs(undefined, ref)(null);
27
+
28
+ expect(ref.current).toBeNull();
29
+ });
30
+
31
+ it('updates callback and object refs together', () => {
32
+ const callback = jest.fn();
33
+ const objectRef = createRef<string | null>();
34
+
35
+ mergeRefs(callback, objectRef)('shared');
36
+
37
+ expect(callback).toHaveBeenCalledWith('shared');
38
+ expect(objectRef.current).toBe('shared');
39
+ });
40
+
41
+ describe('React 19 ref-cleanup semantics', () => {
42
+ it('returns a cleanup function when called with a non-null value', () => {
43
+ const ref = createRef<string>();
44
+ const merged = mergeRefs(ref);
45
+
46
+ const cleanup = merged('value');
47
+
48
+ expect(typeof cleanup).toBe('function');
49
+ });
50
+
51
+ it('does not return a cleanup when called with null', () => {
52
+ const ref = createRef<string>();
53
+ const merged = mergeRefs(ref);
54
+
55
+ const result = merged(null);
56
+
57
+ expect(result).toBeUndefined();
58
+ });
59
+
60
+ it('cleanup nulls object refs', () => {
61
+ const refA = createRef<string>();
62
+ const refB = createRef<string>();
63
+ const merged = mergeRefs(refA, refB);
64
+
65
+ const cleanup = merged('value') as () => void;
66
+ expect(refA.current).toBe('value');
67
+ expect(refB.current).toBe('value');
68
+
69
+ cleanup();
70
+ expect(refA.current).toBeNull();
71
+ expect(refB.current).toBeNull();
72
+ });
73
+
74
+ it('cleanup calls callback refs with null when they did not return a cleanup', () => {
75
+ const callback = jest.fn();
76
+ const merged = mergeRefs(callback);
77
+
78
+ const cleanup = merged('value') as () => void;
79
+ expect(callback).toHaveBeenCalledWith('value');
80
+
81
+ callback.mockClear();
82
+ cleanup();
83
+ expect(callback).toHaveBeenCalledWith(null);
84
+ });
85
+
86
+ it('cleanup invokes the inner cleanup instead of calling ref(null) for refs that returned one', () => {
87
+ const innerCleanup = jest.fn();
88
+ const callbackWithCleanup = jest.fn().mockReturnValue(innerCleanup);
89
+ const merged = mergeRefs(callbackWithCleanup);
90
+
91
+ const cleanup = merged('element') as () => void;
92
+ expect(callbackWithCleanup).toHaveBeenCalledWith('element');
93
+
94
+ callbackWithCleanup.mockClear();
95
+ cleanup();
96
+ expect(innerCleanup).toHaveBeenCalledTimes(1);
97
+ expect(callbackWithCleanup).not.toHaveBeenCalled();
98
+ });
99
+
100
+ it('handles mixed refs: object, callback with cleanup, callback without cleanup', () => {
101
+ const objectRef = createRef<string>();
102
+ const innerCleanup = jest.fn();
103
+ const callbackWithCleanup = jest.fn().mockReturnValue(innerCleanup);
104
+ const callbackNoCleanup = jest.fn();
105
+
106
+ const merged = mergeRefs(objectRef, callbackWithCleanup, callbackNoCleanup);
107
+ const cleanup = merged('node') as () => void;
108
+
109
+ expect(objectRef.current).toBe('node');
110
+ expect(callbackWithCleanup).toHaveBeenCalledWith('node');
111
+ expect(callbackNoCleanup).toHaveBeenCalledWith('node');
112
+
113
+ callbackWithCleanup.mockClear();
114
+ callbackNoCleanup.mockClear();
115
+ cleanup();
116
+
117
+ expect(objectRef.current).toBeNull();
118
+ expect(innerCleanup).toHaveBeenCalledTimes(1);
119
+ expect(callbackWithCleanup).not.toHaveBeenCalled();
120
+ expect(callbackNoCleanup).toHaveBeenCalledWith(null);
121
+ });
122
+
123
+ it('null-call path still works for React 18 compat (calls all refs with null)', () => {
124
+ const objectRef = createRef<string>();
125
+ const callback = jest.fn();
126
+ const merged = mergeRefs(objectRef, callback);
127
+
128
+ merged('value');
129
+ callback.mockClear();
130
+
131
+ merged(null);
132
+
133
+ expect(objectRef.current).toBeNull();
134
+ expect(callback).toHaveBeenCalledWith(null);
135
+ });
136
+
137
+ it('skips undefined entries in cleanup', () => {
138
+ const objectRef = createRef<string>();
139
+ const merged = mergeRefs(undefined, objectRef, undefined);
140
+
141
+ const cleanup = merged('value') as () => void;
142
+ expect(objectRef.current).toBe('value');
143
+
144
+ cleanup();
145
+ expect(objectRef.current).toBeNull();
146
+ });
147
+ });
148
+ });
@@ -1,13 +1,56 @@
1
1
  import type { Ref, RefCallback } from 'react';
2
2
 
3
+ type CleanupFn = () => void;
4
+
5
+ /**
6
+ * Merges multiple refs (object or callback) into a single callback ref.
7
+ *
8
+ * Supports React 19 ref-cleanup semantics: if an inner callback ref returns a
9
+ * cleanup function, that cleanup is captured and invoked when the merged ref is
10
+ * detached — either via the returned cleanup (React 19) or via a subsequent
11
+ * call with `null` (React 18 backward-compat path).
12
+ */
3
13
  export function mergeRefs<T>(...refs: (Ref<T> | undefined)[]): RefCallback<T> {
4
- return (value: T | null) => {
14
+ return (value: T | null): CleanupFn | undefined => {
15
+ if (value === null) {
16
+ for (const ref of refs) {
17
+ if (typeof ref === 'function') {
18
+ ref(null);
19
+ } else if (ref != null) {
20
+ ref.current = null;
21
+ }
22
+ }
23
+ return undefined;
24
+ }
25
+
26
+ const cleanups: (CleanupFn | undefined)[] = [];
5
27
  for (const ref of refs) {
6
28
  if (typeof ref === 'function') {
7
- ref(value);
29
+ cleanups.push(ref(value) as CleanupFn | undefined);
8
30
  } else if (ref != null) {
9
31
  ref.current = value;
32
+ cleanups.push(undefined);
33
+ } else {
34
+ cleanups.push(undefined);
10
35
  }
11
36
  }
37
+
38
+ return () => {
39
+ for (let i = 0; i < refs.length; i++) {
40
+ const ref = refs[i];
41
+ if (ref == null) continue;
42
+
43
+ if (typeof ref === 'function') {
44
+ const refCleanup = cleanups[i];
45
+ if (typeof refCleanup === 'function') {
46
+ refCleanup();
47
+ } else {
48
+ ref(null);
49
+ }
50
+ } else {
51
+ ref.current = null;
52
+ }
53
+ }
54
+ };
12
55
  };
13
56
  }
@@ -0,0 +1,90 @@
1
+ import { act, renderHook } from '@testing-library/react-native';
2
+ import { useControllableState } from './useControllableState';
3
+
4
+ describe('useControllableState', () => {
5
+ it('manages uncontrolled state from defaultProp', () => {
6
+ const onChange = jest.fn();
7
+ const { result } = renderHook(() => useControllableState({ defaultProp: 'initial', onChange }));
8
+
9
+ expect(result.current[0]).toBe('initial');
10
+
11
+ act(() => {
12
+ result.current[1]('next');
13
+ });
14
+
15
+ expect(result.current[0]).toBe('next');
16
+ expect(onChange).toHaveBeenCalledWith('next');
17
+ });
18
+
19
+ it('uses prop value in controlled mode and notifies onChange', () => {
20
+ const onChange = jest.fn();
21
+ const { result } = renderHook(() => useControllableState({ prop: 'controlled', onChange }));
22
+
23
+ expect(result.current[0]).toBe('controlled');
24
+
25
+ act(() => {
26
+ result.current[1]('updated');
27
+ });
28
+
29
+ expect(onChange).toHaveBeenCalledWith('updated');
30
+ expect(result.current[0]).toBe('controlled');
31
+ });
32
+
33
+ it('supports function updaters in uncontrolled mode', () => {
34
+ const { result } = renderHook(() => useControllableState({ defaultProp: 1 }));
35
+
36
+ act(() => {
37
+ result.current[1]((prev: number | undefined) => (prev ?? 0) + 1);
38
+ });
39
+
40
+ expect(result.current[0]).toBe(2);
41
+ });
42
+
43
+ it('follows prop updates in controlled mode', () => {
44
+ const { result, rerender } = renderHook(({ value }) => useControllableState({ prop: value }), {
45
+ initialProps: { value: 'a' },
46
+ });
47
+
48
+ rerender({ value: 'b' });
49
+
50
+ expect(result.current[0]).toBe('b');
51
+ });
52
+
53
+ it('supports function updaters in controlled mode', () => {
54
+ const onChange = jest.fn();
55
+ const { result } = renderHook(() => useControllableState({ prop: 2, onChange }));
56
+
57
+ act(() => {
58
+ result.current[1]((prev: number | undefined) => (prev ?? 0) + 3);
59
+ });
60
+
61
+ expect(onChange).toHaveBeenCalledWith(5);
62
+ expect(result.current[0]).toBe(2);
63
+ });
64
+
65
+ it('does not notify onChange when controlled value is unchanged', () => {
66
+ const onChange = jest.fn();
67
+ const { result } = renderHook(() => useControllableState({ prop: 'same', onChange }));
68
+
69
+ act(() => {
70
+ result.current[1]('same');
71
+ });
72
+
73
+ expect(onChange).not.toHaveBeenCalled();
74
+ });
75
+
76
+ it('switches from uncontrolled to controlled when prop is provided', () => {
77
+ const { result, rerender } = renderHook(
78
+ (props: { prop?: string; defaultProp?: string }) => useControllableState(props),
79
+ { initialProps: { defaultProp: 'internal' } },
80
+ );
81
+
82
+ act(() => {
83
+ result.current[1]('internal');
84
+ });
85
+
86
+ rerender({ prop: 'external' });
87
+
88
+ expect(result.current[0]).toBe('external');
89
+ });
90
+ });
@@ -0,0 +1,31 @@
1
+ import type { ReactNode } from 'react';
2
+ import { renderHook } from '@testing-library/react-native';
3
+ import { createContext } from './createContext';
4
+
5
+ describe('createContext', () => {
6
+ it('provides value through Provider and consumer hook', () => {
7
+ const [Provider, useTestContext] = createContext<{ label: string }>('Test');
8
+
9
+ const wrapper = ({ children }: { children: ReactNode }) => (
10
+ <Provider value={{ label: 'hello' }}>{children}</Provider>
11
+ );
12
+
13
+ const { result } = renderHook(() => useTestContext(), { wrapper });
14
+
15
+ expect(result.current).toEqual({ label: 'hello' });
16
+ });
17
+
18
+ it('throws when consumer is used outside Provider', () => {
19
+ const [, useTestContext] = createContext<{ label: string }>('Test');
20
+
21
+ expect(() => {
22
+ renderHook(() => useTestContext());
23
+ }).toThrow('useTest must be used within a TestProvider');
24
+ });
25
+
26
+ it('names the Provider from the display name argument', () => {
27
+ const [Provider] = createContext<{ label: string }>('Field');
28
+
29
+ expect(Provider.displayName).toBe('FieldProvider');
30
+ });
31
+ });
@@ -1,4 +1,5 @@
1
1
  export {
2
+ type Focusable,
2
3
  type FormControlContextValue,
3
4
  type FormControlFieldProps,
4
5
  type FormControlRootProps,
@@ -8,4 +9,5 @@ export {
8
9
  useFormControl,
9
10
  useFormControlContext,
10
11
  useFormControlRoot,
12
+ useReportFormControlLabelFocus,
11
13
  } from './useFormControl';
@@ -0,0 +1,214 @@
1
+ import type { ReactNode } from 'react';
2
+ import { Platform, type TextInput } from 'react-native';
3
+ import { act, renderHook } from '@testing-library/react-native';
4
+ import {
5
+ FormControlContext,
6
+ useFormControl,
7
+ useFormControlContext,
8
+ useFormControlRoot,
9
+ useReportFormControlLabelFocus,
10
+ } from './useFormControl';
11
+
12
+ function FormControlTestProvider({
13
+ children,
14
+ rootProps,
15
+ hasFeedbackText = false,
16
+ hasHelpText = false,
17
+ }: {
18
+ children: ReactNode;
19
+ rootProps?: Parameters<typeof useFormControlRoot>[0];
20
+ hasFeedbackText?: boolean;
21
+ hasHelpText?: boolean;
22
+ }) {
23
+ const root = useFormControlRoot(rootProps ?? { id: 'email' });
24
+
25
+ return (
26
+ <FormControlContext.Provider value={{ ...root, hasFeedbackText, hasHelpText }}>
27
+ {children}
28
+ </FormControlContext.Provider>
29
+ );
30
+ }
31
+
32
+ describe('useFormControlRoot', () => {
33
+ it('uses provided id and coerces boolean state flags', () => {
34
+ const { result } = renderHook(() =>
35
+ useFormControlRoot({
36
+ id: 'custom-id',
37
+ isRequired: true,
38
+ isInvalid: true,
39
+ isDisabled: false,
40
+ isReadOnly: false,
41
+ name: 'email',
42
+ 'data-test': 'root',
43
+ }),
44
+ );
45
+
46
+ expect(result.current.id).toBe('custom-id');
47
+ expect(result.current.labelId).toBe('custom-id-label');
48
+ expect(result.current.isRequired).toBe(true);
49
+ expect(result.current.isInvalid).toBe(true);
50
+ expect(result.current.isDisabled).toBe(false);
51
+ expect(result.current.isReadOnly).toBe(false);
52
+ expect(result.current.name).toBe('email');
53
+ expect(result.current.htmlProps).toEqual({ 'data-test': 'root' });
54
+ });
55
+
56
+ it('generates an id when none is provided', () => {
57
+ const { result } = renderHook(() => useFormControlRoot({}));
58
+
59
+ expect(result.current.id).toMatch(/^field-/);
60
+ expect(result.current.feedbackId).toBe(`${result.current.id}-feedback`);
61
+ });
62
+
63
+ it('ignores empty string id and generates a fallback', () => {
64
+ const { result } = renderHook(() => useFormControlRoot({ id: '' }));
65
+
66
+ expect(result.current.id).toMatch(/^field-/);
67
+ expect(result.current.id).not.toBe('');
68
+ });
69
+
70
+ it('exposes native focus helpers by default', () => {
71
+ const { result } = renderHook(() => useFormControlRoot({}));
72
+
73
+ expect(result.current.inputRef).toBeDefined();
74
+ expect(result.current.focusInput).toBeDefined();
75
+
76
+ const { inputRef, focusInput } = result.current;
77
+ if (!inputRef || !focusInput) {
78
+ throw new Error('expected native focus helpers');
79
+ }
80
+
81
+ const focus = jest.fn();
82
+ act(() => {
83
+ inputRef.current = { focus } as TextInput;
84
+ focusInput();
85
+ });
86
+
87
+ expect(focus).toHaveBeenCalled();
88
+ });
89
+
90
+ it('no-ops focusInput when ref is empty or focus is unavailable', () => {
91
+ const { result } = renderHook(() => useFormControlRoot({}));
92
+ const { focusInput, inputRef } = result.current;
93
+
94
+ if (!focusInput || !inputRef) {
95
+ throw new Error('expected native focus helpers');
96
+ }
97
+
98
+ expect(() => {
99
+ focusInput();
100
+ }).not.toThrow();
101
+
102
+ act(() => {
103
+ inputRef.current = {} as TextInput;
104
+ focusInput();
105
+ });
106
+
107
+ expect(inputRef.current).toEqual({});
108
+ });
109
+
110
+ it('omits native focus helpers on web', () => {
111
+ const originalDescriptor = Object.getOwnPropertyDescriptor(Platform, 'OS');
112
+ Object.defineProperty(Platform, 'OS', { configurable: true, get: () => 'web' });
113
+
114
+ const { result } = renderHook(() => useFormControlRoot({}));
115
+
116
+ expect(result.current.inputRef).toBeUndefined();
117
+ expect(result.current.focusInput).toBeUndefined();
118
+
119
+ if (originalDescriptor) {
120
+ Object.defineProperty(Platform, 'OS', originalDescriptor);
121
+ }
122
+ });
123
+ });
124
+
125
+ describe('useFormControl', () => {
126
+ it('merges local props with context and composes aria-describedby', () => {
127
+ const { result } = renderHook(() => useFormControl({ id: 'override', isDisabled: true }), {
128
+ wrapper: ({ children }) => (
129
+ <FormControlTestProvider
130
+ rootProps={{
131
+ id: 'email',
132
+ name: 'email',
133
+ isRequired: true,
134
+ isInvalid: true,
135
+ isDisabled: false,
136
+ isReadOnly: false,
137
+ }}
138
+ hasFeedbackText
139
+ hasHelpText
140
+ >
141
+ {children}
142
+ </FormControlTestProvider>
143
+ ),
144
+ });
145
+
146
+ expect(result.current.id).toBe('override');
147
+ expect(result.current.name).toBe('email');
148
+ expect(result.current.disabled).toBe(true);
149
+ expect(result.current.required).toBe(true);
150
+ expect(result.current['aria-invalid']).toBe(true);
151
+ expect(result.current['aria-labelledby']).toBe('email-label');
152
+ expect(result.current['aria-describedby']).toBe('email-feedback email-helptext');
153
+ });
154
+
155
+ it('returns undefined aria-describedby when no help or feedback is present', () => {
156
+ const { result } = renderHook(() => useFormControl({}), {
157
+ wrapper: ({ children }) => <FormControlTestProvider>{children}</FormControlTestProvider>,
158
+ });
159
+
160
+ expect(result.current['aria-describedby']).toBeUndefined();
161
+ expect(result.current.id).toBe('email-input');
162
+ });
163
+
164
+ it('composes aria-describedby from feedback or help text alone', () => {
165
+ const feedbackOnly = renderHook(() => useFormControl({}), {
166
+ wrapper: ({ children }) => (
167
+ <FormControlTestProvider hasFeedbackText>{children}</FormControlTestProvider>
168
+ ),
169
+ }).result.current['aria-describedby'];
170
+
171
+ const helpOnly = renderHook(() => useFormControl({}), {
172
+ wrapper: ({ children }) => (
173
+ <FormControlTestProvider hasHelpText>{children}</FormControlTestProvider>
174
+ ),
175
+ }).result.current['aria-describedby'];
176
+
177
+ expect(feedbackOnly).toBe('email-feedback');
178
+ expect(helpOnly).toBe('email-helptext');
179
+ });
180
+
181
+ it('merges readOnly from local props and omits id without field context', () => {
182
+ const { result } = renderHook(() => useFormControl({ isReadOnly: true }));
183
+
184
+ expect(result.current.readOnly).toBe(true);
185
+ expect(result.current.id).toBeUndefined();
186
+ });
187
+ });
188
+
189
+ describe('useReportFormControlLabelFocus', () => {
190
+ it('reports active state to the form control context', () => {
191
+ const { result, rerender } = renderHook(
192
+ ({ active }: { active: boolean }) => {
193
+ useReportFormControlLabelFocus(active);
194
+ return useFormControlContext().isLabelFocused;
195
+ },
196
+ {
197
+ wrapper: ({ children }) => <FormControlTestProvider>{children}</FormControlTestProvider>,
198
+ initialProps: { active: true },
199
+ },
200
+ );
201
+
202
+ expect(result.current).toBe(true);
203
+
204
+ rerender({ active: false });
205
+
206
+ expect(result.current).toBe(false);
207
+ });
208
+
209
+ it('no-ops when setIsLabelFocused is unavailable', () => {
210
+ expect(() => {
211
+ renderHook(() => useReportFormControlLabelFocus(true));
212
+ }).not.toThrow();
213
+ });
214
+ });