@@ -1519,6 +1519,122 @@ for (const usingRemoveActiveDescendant of [false, true]) {
15191519 expect ( selectAllCheckbox ) . toHaveProperty ( 'indeterminate' , true )
15201520 } )
15211521 } )
1522+
1523+ describe ( 'disableSelectOnHover' , ( ) => {
1524+ it ( 'should not update aria-activedescendant when hovering over items when disableSelectOnHover is true' , async ( ) => {
1525+ const user = userEvent . setup ( )
1526+
1527+ render ( < BasicSelectPanel disableSelectOnHover = { true } /> )
1528+
1529+ await user . click ( screen . getByText ( 'Select items' ) )
1530+
1531+ const input = screen . getByPlaceholderText ( 'Filter items' )
1532+ const options = screen . getAllByRole ( 'option' )
1533+
1534+ // Initially, aria-activedescendant should not be set if setInitialFocus is false (default)
1535+ const initialActiveDescendant = input . getAttribute ( 'aria-activedescendant' )
1536+
1537+ // Hover over the first item
1538+ await user . hover ( options [ 0 ] )
1539+
1540+ // aria-activedescendant should not change when disableSelectOnHover is true
1541+ expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toBe ( initialActiveDescendant )
1542+
1543+ // Hover over the second item
1544+ await user . hover ( options [ 1 ] )
1545+
1546+ // aria-activedescendant should still not change
1547+ expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toBe ( initialActiveDescendant )
1548+ } )
1549+
1550+ it ( 'should update aria-activedescendant when hovering over items when disableSelectOnHover is false (default)' , async ( ) => {
1551+ const user = userEvent . setup ( )
1552+
1553+ render ( < BasicSelectPanel /> )
1554+
1555+ await user . click ( screen . getByText ( 'Select items' ) )
1556+
1557+ const input = screen . getByPlaceholderText ( 'Filter items' )
1558+ const options = screen . getAllByRole ( 'option' )
1559+
1560+ // Hover over the first item
1561+ await user . hover ( options [ 0 ] )
1562+
1563+ // aria-activedescendant should be set to the first item
1564+ expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toBe ( options [ 0 ] . id )
1565+
1566+ // Hover over the second item
1567+ await user . hover ( options [ 1 ] )
1568+
1569+ // aria-activedescendant should be updated to the second item
1570+ expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toBe ( options [ 1 ] . id )
1571+ } )
1572+ } )
1573+
1574+ describe ( 'setInitialFocus' , ( ) => {
1575+ it ( 'should not set aria-activedescendant until user interaction when setInitialFocus is true' , async ( ) => {
1576+ const user = userEvent . setup ( )
1577+
1578+ render ( < BasicSelectPanel setInitialFocus = { true } /> )
1579+
1580+ await user . click ( screen . getByText ( 'Select items' ) )
1581+
1582+ const input = screen . getByPlaceholderText ( 'Filter items' )
1583+ const options = screen . getAllByRole ( 'option' )
1584+
1585+ // Initially, aria-activedescendant should not be set
1586+ expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toBeFalsy ( )
1587+
1588+ // User interacts with keyboard
1589+ await user . keyboard ( '{ArrowDown}' )
1590+
1591+ // Now aria-activedescendant should be set to the first item
1592+ expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toBe ( options [ 0 ] . id )
1593+ } )
1594+
1595+ it ( 'should set aria-activedescendant to the first item on mount when setInitialFocus is false (default)' , async ( ) => {
1596+ const user = userEvent . setup ( )
1597+
1598+ render ( < BasicSelectPanel /> )
1599+
1600+ await user . click ( screen . getByText ( 'Select items' ) )
1601+
1602+ const input = screen . getByPlaceholderText ( 'Filter items' )
1603+ const options = screen . getAllByRole ( 'option' )
1604+
1605+ // Wait a tick for the effect to run
1606+ await new Promise ( resolve => setTimeout ( resolve , 0 ) )
1607+
1608+ // aria-activedescendant should be set to the first item
1609+ expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toBe ( options [ 0 ] . id )
1610+ } )
1611+
1612+ it ( 'should not set aria-activedescendant on mouse hover until after first interaction when setInitialFocus is true' , async ( ) => {
1613+ const user = userEvent . setup ( )
1614+
1615+ render ( < BasicSelectPanel setInitialFocus = { true } /> )
1616+
1617+ await user . click ( screen . getByText ( 'Select items' ) )
1618+
1619+ const input = screen . getByPlaceholderText ( 'Filter items' )
1620+ const options = screen . getAllByRole ( 'option' )
1621+
1622+ // Initially, aria-activedescendant should not be set
1623+ expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toBeFalsy ( )
1624+
1625+ // Hover over the first item (this is the first interaction)
1626+ await user . hover ( options [ 0 ] )
1627+
1628+ // Now aria-activedescendant should be set to the first item
1629+ expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toBe ( options [ 0 ] . id )
1630+
1631+ // Hover over the second item
1632+ await user . hover ( options [ 1 ] )
1633+
1634+ // aria-activedescendant should update to the second item
1635+ expect ( input . getAttribute ( 'aria-activedescendant' ) ) . toBe ( options [ 1 ] . id )
1636+ } )
1637+ } )
15221638 } )
15231639
15241640 describe ( 'Event propagation' , ( ) => {
0 commit comments