@@ -1866,4 +1866,51 @@ describe('<Select />', () => {
18661866 expect ( container . querySelector ( '.MuiSelect-iconFilled' ) ) . not . to . equal ( null ) ;
18671867 expect ( container . querySelector ( '.MuiSelect-filled ~ .MuiSelect-icon' ) ) . not . to . equal ( null ) ;
18681868 } ) ;
1869+
1870+ describe ( 'window resize' , ( ) => {
1871+ it ( 'should update menu width when window resizes while menu is open' , ( ) => {
1872+ const { container } = render (
1873+ < div style = { { width : '200px' } } >
1874+ < Select open value = "" >
1875+ < MenuItem value = "option1" > Option 1</ MenuItem >
1876+ < MenuItem value = "option2" > Option 2</ MenuItem >
1877+ </ Select >
1878+ </ div > ,
1879+ ) ;
1880+
1881+ // Get the menu paper element
1882+ const menuPaper = container . querySelector ( '[role="presentation"]' ) ;
1883+ expect ( menuPaper ) . not . to . equal ( null ) ;
1884+ const initialMinWidth = menuPaper . style . minWidth ;
1885+
1886+ // Simulate window resize
1887+ const resizeEvent = new Event ( 'resize' , { bubbles : true } ) ;
1888+ window . dispatchEvent ( resizeEvent ) ;
1889+
1890+ // Menu width should be updated (menu paper should have minWidth)
1891+ expect ( menuPaper . style . minWidth ) . to . equal ( initialMinWidth ) ;
1892+ } ) ;
1893+
1894+ it ( 'should not update menu width on resize if autoWidth is true' , ( ) => {
1895+ const { container } = render (
1896+ < div style = { { width : '200px' } } >
1897+ < Select open value = "" autoWidth >
1898+ < MenuItem value = "option1" > Option 1</ MenuItem >
1899+ < MenuItem value = "option2" > Option 2</ MenuItem >
1900+ </ Select >
1901+ </ div > ,
1902+ ) ;
1903+
1904+ const menuPaper = container . querySelector ( '[role="presentation"]' ) ;
1905+ expect ( menuPaper ) . not . to . equal ( null ) ;
1906+ const initialMinWidth = menuPaper . style . minWidth ;
1907+
1908+ // Simulate window resize
1909+ const resizeEvent = new Event ( 'resize' , { bubbles : true } ) ;
1910+ window . dispatchEvent ( resizeEvent ) ;
1911+
1912+ // Menu width should not have minWidth set when autoWidth is true
1913+ expect ( menuPaper . style . minWidth ) . to . equal ( initialMinWidth ) ;
1914+ } ) ;
1915+ } ) ;
18691916} ) ;
0 commit comments