@@ -675,12 +675,19 @@ def test_single_select_with_duplicate_paths_selects_focused_node_on_keyboard
675675 nodes = all ( selector_for ( "action_menu.rb" ) )
676676 assert_equal 3 , nodes . size
677677
678- nodes [ 1 ] . send_keys ( :space )
678+ # icon_button.rb has current: true so it owns tabindex=0. Sending keys directly
679+ # to a tabindex=-1 node is unreliable: focusZone redirects focus to the aria-current
680+ # item on focusin, so Space would land on the wrong node.
681+ # Start from icon_button.rb and navigate down with arrow keys instead.
682+ find ( '[aria-current]' ) . send_keys ( :down )
683+ keyboard . type ( :down )
684+ keyboard . type ( :space )
679685
680686 nodes [ 1 ] . assert_matches_selector ( "[aria-checked='true']" )
681687 nodes [ 0 ] . assert_matches_selector ( "[aria-checked='false']" )
682688
683- nodes [ 0 ] . send_keys ( :space )
689+ keyboard . type ( :up )
690+ keyboard . type ( :space )
684691
685692 nodes [ 0 ] . assert_matches_selector ( "[aria-checked='true']" )
686693 nodes [ 1 ] . assert_matches_selector ( "[aria-checked='false']" )
@@ -707,10 +714,13 @@ def test_keyboard_toggles_off_already_selected_single_variant
707714 visit_preview ( :doubled_path )
708715
709716 nodes = all ( selector_for ( "action_menu.rb" ) )
710- nodes [ 0 ] . send_keys ( :space )
717+
718+ # Navigate from icon_button.rb (aria-current, tabindex=0) to nodes[0]
719+ find ( '[aria-current]' ) . send_keys ( :down )
720+ keyboard . type ( :space )
711721 nodes [ 0 ] . assert_matches_selector ( "[aria-checked='true']" )
712722
713- nodes [ 0 ] . send_keys ( :space )
723+ keyboard . type ( :space )
714724 nodes [ 0 ] . assert_matches_selector ( "[aria-checked='false']" )
715725 end
716726
0 commit comments