@@ -1055,7 +1055,7 @@ describe('<Autocomplete.Root />', () => {
10551055
10561056 it ( 'prop: validate' , async ( ) => {
10571057 await render (
1058- < Field . Root validate = { ( ) => 'error' } >
1058+ < Field . Root validationMode = "onBlur" validate = { ( ) => 'error' } >
10591059 < Autocomplete . Root >
10601060 < Autocomplete . Input data-testid = "input" />
10611061 < Autocomplete . Portal >
@@ -1066,13 +1066,56 @@ describe('<Autocomplete.Root />', () => {
10661066 ) ;
10671067
10681068 const input = screen . getByTestId ( 'input' ) ;
1069+ expect ( input ) . not . to . have . attribute ( 'aria-invalid' ) ;
1070+
1071+ fireEvent . focus ( input ) ;
1072+ fireEvent . blur ( input ) ;
1073+ await flushMicrotasks ( ) ;
1074+ expect ( input ) . to . have . attribute ( 'aria-invalid' , 'true' ) ;
1075+ } ) ;
10691076
1077+ it ( 'prop: validationMode=onSubmit' , async ( ) => {
1078+ const { user } = await render (
1079+ < Form >
1080+ < Field . Root
1081+ validate = { ( value ) => {
1082+ return value === 'one' ? 'error' : null ;
1083+ } }
1084+ >
1085+ < Autocomplete . Root required >
1086+ < Autocomplete . Input data-testid = "input" />
1087+ < Autocomplete . Portal >
1088+ < Autocomplete . Positioner >
1089+ < Autocomplete . Popup >
1090+ < Autocomplete . List >
1091+ < Autocomplete . Item value = "one" > Option 1</ Autocomplete . Item >
1092+ < Autocomplete . Item value = "two" > Option 2</ Autocomplete . Item >
1093+ </ Autocomplete . List >
1094+ </ Autocomplete . Popup >
1095+ </ Autocomplete . Positioner >
1096+ </ Autocomplete . Portal >
1097+ </ Autocomplete . Root >
1098+ </ Field . Root >
1099+ < button type = "submit" > submit</ button >
1100+ </ Form > ,
1101+ ) ;
1102+
1103+ const input = screen . getByTestId ( 'input' ) ;
10701104 expect ( input ) . not . to . have . attribute ( 'aria-invalid' ) ;
10711105
1072- await act ( async ( ) => input . focus ( ) ) ;
1073- await act ( async ( ) => input . blur ( ) ) ;
1106+ await user . click ( screen . getByText ( 'submit' ) ) ;
1107+ expect ( input ) . to . have . attribute ( 'aria-invalid' , 'true' ) ;
10741108
1109+ await user . type ( input , 'two' ) ;
1110+ expect ( input ) . not . to . have . attribute ( 'aria-invalid' ) ;
1111+
1112+ await user . clear ( input ) ;
1113+ await user . type ( input , 'one' ) ;
10751114 expect ( input ) . to . have . attribute ( 'aria-invalid' , 'true' ) ;
1115+
1116+ await user . clear ( input ) ;
1117+ await user . type ( input , 'three' ) ;
1118+ expect ( input ) . not . to . have . attribute ( 'aria-invalid' ) ;
10761119 } ) ;
10771120
10781121 // flaky in real browser
0 commit comments