@@ -20,6 +20,43 @@ afterEach(() => {
2020 renderInput . mockClear ( ) ;
2121} ) ;
2222
23+ it . each ( [ 'filled' , 'outlined' ] as const ) (
24+ 'uses the placeholder as the name of an unlabelled %s field, including after typing' ,
25+ async ( variant ) => {
26+ await render ( < TextInput variant = { variant } placeholder = "Search" /> ) ;
27+
28+ const input = screen . getByLabelText ( 'Search' ) ;
29+ await userEvent . type ( input , 'Paper' ) ;
30+ expect ( screen . getByLabelText ( 'Search' ) ) . toHaveDisplayValue ( 'Paper' ) ;
31+ }
32+ ) ;
33+
34+ it . each ( [
35+ { label : 'Search products' } ,
36+ { 'aria-label' : 'Search products' } ,
37+ { accessibilityLabel : 'Search products' } ,
38+ ] ) ( 'prefers a supplied name over the placeholder: %j' , async ( props ) => {
39+ await render ( < TextInput { ...props } placeholder = "Search" /> ) ;
40+
41+ expect ( screen . getByLabelText ( 'Search products' ) ) . toBeOnTheScreen ( ) ;
42+ expect ( screen . queryByLabelText ( 'Search' ) ) . toBeNull ( ) ;
43+ } ) ;
44+
45+ it . each ( [
46+ { disabled : true , 'aria-disabled' : false , expectedDisabled : true } ,
47+ { disabled : true , 'aria-disabled' : true , expectedDisabled : true } ,
48+ { disabled : false , 'aria-disabled' : true , expectedDisabled : true } ,
49+ { disabled : false , 'aria-disabled' : false , expectedDisabled : false } ,
50+ ] ) (
51+ 'keeps the disabled semantics consistent: %j' ,
52+ async ( { expectedDisabled, ...props } ) => {
53+ await render ( < TextInput { ...props } label = "Email" readOnly /> ) ;
54+
55+ const input = screen . getByLabelText ( 'Email' ) ;
56+ expect ( input ) . toHaveProp ( 'aria-disabled' , expectedDisabled ) ;
57+ }
58+ ) ;
59+
2360it . each ( [ 'filled' , 'outlined' ] as const ) (
2461 'keeps an empty unfocused %s field visible to assistive technology' ,
2562 async ( variant ) => {
@@ -308,7 +345,7 @@ it('renders decorative accessories outside the accessibility tree without button
308345 ) . toBeOnTheScreen ( ) ;
309346} ) ;
310347
311- it ( 'preserves decorative loading and container visuals without accessible controls' , async ( ) => {
348+ it ( 'preserves decorative loading and content styles without accessible controls' , async ( ) => {
312349 await render (
313350 < TextInput
314351 label = "Search"
@@ -330,11 +367,6 @@ it('preserves decorative loading and container visuals without accessible contro
330367 expect (
331368 screen . getByRole ( 'progressbar' , { includeHiddenElements : true } )
332369 ) . toBeOnTheScreen ( ) ;
333- expect (
334- screen . getByTestId ( 'search-decoration-container' , {
335- includeHiddenElements : true ,
336- } )
337- ) . toHaveStyle ( { backgroundColor : 'pink' , borderWidth : 1 } ) ;
338370 expect (
339371 screen . getByTestId ( 'search-decoration' , { includeHiddenElements : true } )
340372 ) . toHaveStyle ( { padding : 2 } ) ;
0 commit comments