@@ -13,6 +13,7 @@ import {
13
13
import Tab from '@mui/material/Tab' ;
14
14
import Tabs , { tabsClasses as classes } from '@mui/material/Tabs' ;
15
15
import Tooltip from '@mui/material/Tooltip' ;
16
+ import Divider from '@mui/material/Divider' ;
16
17
import { svgIconClasses } from '@mui/material/SvgIcon' ;
17
18
import { createTheme , ThemeProvider } from '@mui/material/styles' ;
18
19
import { createSvgIcon } from '@mui/material/utils' ;
@@ -1541,6 +1542,7 @@ describe('<Tabs />', () => {
1541
1542
} ) ;
1542
1543
} ) ;
1543
1544
1545
+ // https://github.com/mui/material-ui/issues/46265
1544
1546
it ( 'should select the Tab wrapped with a component on click' , ( ) => {
1545
1547
function TestComponent ( ) {
1546
1548
const [ value , setValue ] = React . useState ( 'one' ) ;
@@ -1572,4 +1574,127 @@ describe('<Tabs />', () => {
1572
1574
expect ( firstTab ) . to . have . attribute ( 'aria-selected' , 'false' ) ;
1573
1575
expect ( secondTab ) . to . have . attribute ( 'aria-selected' , 'true' ) ;
1574
1576
} ) ;
1577
+
1578
+ // https://github.com/mui/material-ui/issues/27947
1579
+ it ( 'should select the custom Tab' , ( ) => {
1580
+ function CustomTab ( { value } ) {
1581
+ return < Tab label = { value } value = { value } /> ;
1582
+ }
1583
+
1584
+ function TestComponent ( ) {
1585
+ const [ value , setValue ] = React . useState ( 'one' ) ;
1586
+
1587
+ const handleChange = ( _ , newValue ) => {
1588
+ setValue ( newValue ) ;
1589
+ } ;
1590
+
1591
+ return (
1592
+ < Tabs value = { value } onChange = { handleChange } >
1593
+ < Tab label = "one" value = "one" />
1594
+ < CustomTab label = "two" value = "two" />
1595
+ </ Tabs >
1596
+ ) ;
1597
+ }
1598
+
1599
+ render ( < TestComponent /> ) ;
1600
+
1601
+ const firstTab = screen . getAllByRole ( 'tab' ) [ 0 ] ;
1602
+ const secondTab = screen . getAllByRole ( 'tab' ) [ 1 ] ;
1603
+
1604
+ expect ( firstTab ) . to . have . attribute ( 'aria-selected' , 'true' ) ;
1605
+ expect ( secondTab ) . to . have . attribute ( 'aria-selected' , 'false' ) ;
1606
+
1607
+ fireEvent . click ( secondTab ) ;
1608
+
1609
+ expect ( firstTab ) . to . have . attribute ( 'aria-selected' , 'false' ) ;
1610
+ expect ( secondTab ) . to . have . attribute ( 'aria-selected' , 'true' ) ;
1611
+ } ) ;
1612
+
1613
+ // https://github.com/mui/material-ui/issues/34740
1614
+ it ( 'should select if the Tabs are rendered conditionally' , ( ) => {
1615
+ function Authorizer ( { hide, children } ) {
1616
+ return < > { ! hide ? children : null } </ > ;
1617
+ }
1618
+
1619
+ function TestComponent ( ) {
1620
+ const [ value , setValue ] = React . useState ( 'one' ) ;
1621
+
1622
+ const handleChange = ( _ , newValue ) => {
1623
+ setValue ( newValue ) ;
1624
+ } ;
1625
+
1626
+ return (
1627
+ < Tabs value = { value } onChange = { handleChange } >
1628
+ < Authorizer >
1629
+ < Tab label = "one" value = "one" />
1630
+ </ Authorizer >
1631
+ < Authorizer hide >
1632
+ < Tab label = "two" value = "two" />
1633
+ </ Authorizer >
1634
+ < Authorizer >
1635
+ < Tab label = "three" value = "three" />
1636
+ </ Authorizer >
1637
+ </ Tabs >
1638
+ ) ;
1639
+ }
1640
+
1641
+ render ( < TestComponent /> ) ;
1642
+
1643
+ // only two tabs are rendered. one is hidden
1644
+ expect ( screen . getAllByRole ( 'tab' ) . length ) . to . equal ( 2 ) ;
1645
+
1646
+ const firstTab = screen . getAllByRole ( 'tab' ) [ 0 ] ;
1647
+ const secondTab = screen . getAllByRole ( 'tab' ) [ 1 ] ;
1648
+
1649
+ expect ( firstTab ) . to . have . attribute ( 'aria-selected' , 'true' ) ;
1650
+ expect ( secondTab ) . to . have . attribute ( 'aria-selected' , 'false' ) ;
1651
+
1652
+ fireEvent . click ( secondTab ) ;
1653
+
1654
+ expect ( firstTab ) . to . have . attribute ( 'aria-selected' , 'false' ) ;
1655
+ expect ( secondTab ) . to . have . attribute ( 'aria-selected' , 'true' ) ;
1656
+ } ) ;
1657
+
1658
+ // https://github.com/mui/material-ui/issues/38516
1659
+ it ( 'should render with a Divider' , ( ) => {
1660
+ function TestComponent ( ) {
1661
+ const [ value , setValue ] = React . useState ( 'one' ) ;
1662
+
1663
+ const handleChange = ( _ , newValue ) => {
1664
+ setValue ( newValue ) ;
1665
+ } ;
1666
+
1667
+ return (
1668
+ < Tabs value = { value } onChange = { handleChange } >
1669
+ < Tab label = "one" value = "one" />
1670
+ < Divider />
1671
+ < Tab label = "two" value = "two" />
1672
+ < Divider />
1673
+ < Tab label = "three" value = "three" />
1674
+ </ Tabs >
1675
+ ) ;
1676
+ }
1677
+
1678
+ render ( < TestComponent /> ) ;
1679
+
1680
+ const firstTab = screen . getAllByRole ( 'tab' ) [ 0 ] ;
1681
+ const secondTab = screen . getAllByRole ( 'tab' ) [ 1 ] ;
1682
+ const thirdTab = screen . getAllByRole ( 'tab' ) [ 2 ] ;
1683
+
1684
+ expect ( firstTab ) . to . have . attribute ( 'aria-selected' , 'true' ) ;
1685
+ expect ( secondTab ) . to . have . attribute ( 'aria-selected' , 'false' ) ;
1686
+ expect ( thirdTab ) . to . have . attribute ( 'aria-selected' , 'false' ) ;
1687
+
1688
+ fireEvent . click ( secondTab ) ;
1689
+
1690
+ expect ( firstTab ) . to . have . attribute ( 'aria-selected' , 'false' ) ;
1691
+ expect ( secondTab ) . to . have . attribute ( 'aria-selected' , 'true' ) ;
1692
+ expect ( thirdTab ) . to . have . attribute ( 'aria-selected' , 'false' ) ;
1693
+
1694
+ fireEvent . click ( thirdTab ) ;
1695
+
1696
+ expect ( firstTab ) . to . have . attribute ( 'aria-selected' , 'false' ) ;
1697
+ expect ( secondTab ) . to . have . attribute ( 'aria-selected' , 'false' ) ;
1698
+ expect ( thirdTab ) . to . have . attribute ( 'aria-selected' , 'true' ) ;
1699
+ } ) ;
1575
1700
} ) ;
0 commit comments