@@ -3,6 +3,8 @@ import { useId } from '@react-native-aria/utils';
3
3
import omit from 'lodash.omit' ;
4
4
import type { IFormControlProps } from './types' ;
5
5
import { ariaAttr } from '../../../utils' ;
6
+ import { ResponsiveQueryContext } from '../../../utils/useResponsiveQuery/ResponsiveQueryProvider' ;
7
+ import { uniqueId } from 'lodash' ;
6
8
7
9
export type IFormControlContext = Omit <
8
10
ReturnType < typeof useFormControlProvider > ,
@@ -21,7 +23,18 @@ export function useFormControlProvider(props: IFormControlProps) {
21
23
...htmlProps
22
24
} = props ;
23
25
24
- const id = useId ( ) ;
26
+ let id = uniqueId ( ) ;
27
+ const responsiveQueryContext = React . useContext ( ResponsiveQueryContext ) ;
28
+ const disableCSSMediaQueries = responsiveQueryContext . disableCSSMediaQueries ;
29
+
30
+ if ( ! disableCSSMediaQueries ) {
31
+ // This if statement technically breaks the rules of hooks, but is safe
32
+ // because the condition never changes after mounting.
33
+ // eslint-disable-next-line react-hooks/rules-of-hooks
34
+ id = useId ( ) ;
35
+ }
36
+
37
+ // const id = '';
25
38
// Generate all the required ids
26
39
const nativeID = idProp || `field-${ id } ` ;
27
40
@@ -85,7 +98,7 @@ export function useFormControl(props: IFormControlProps) {
85
98
86
99
return {
87
100
...cleanProps ,
88
- nativeID : props . nativeID ?? field ?. nativeID ,
101
+ nativeID : props . nativeID ?? field ?. nativeID + '-input' ,
89
102
disabled : props . isDisabled || field ?. isDisabled ,
90
103
readOnly : props . isReadOnly || field ?. isReadOnly ,
91
104
required : props . isRequired || field ?. isRequired ,
0 commit comments