@@ -3,6 +3,8 @@ import { useId } from '@react-native-aria/utils';
33import omit from 'lodash.omit' ;
44import type { IFormControlProps } from './types' ;
55import { ariaAttr } from '../../../utils' ;
6+ import { ResponsiveQueryContext } from '../../../utils/useResponsiveQuery/ResponsiveQueryProvider' ;
7+ import { uniqueId } from 'lodash' ;
68
79export type IFormControlContext = Omit <
810 ReturnType < typeof useFormControlProvider > ,
@@ -21,7 +23,18 @@ export function useFormControlProvider(props: IFormControlProps) {
2123 ...htmlProps
2224 } = props ;
2325
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 = '';
2538 // Generate all the required ids
2639 const nativeID = idProp || `field-${ id } ` ;
2740
@@ -85,7 +98,7 @@ export function useFormControl(props: IFormControlProps) {
8598
8699 return {
87100 ...cleanProps ,
88- nativeID : props . nativeID ?? field ?. nativeID ,
101+ nativeID : props . nativeID ?? field ?. nativeID + '-input' ,
89102 disabled : props . isDisabled || field ?. isDisabled ,
90103 readOnly : props . isReadOnly || field ?. isReadOnly ,
91104 required : props . isRequired || field ?. isRequired ,
0 commit comments