@@ -977,6 +977,27 @@ export const TagDropdown: React.FC<TagDropdownProps> = ({
977977 const handleKeyboardEvent = ( e : KeyboardEvent ) => {
978978 if ( ! orderedTags . length ) return
979979
980+ const canEnterSubmenuForSelected = ( ) : {
981+ groupIndex : number
982+ nestedTagIndex : number
983+ } | null => {
984+ if ( selectedIndex < 0 || selectedIndex >= orderedTags . length ) return null
985+ const selectedTag = orderedTags [ selectedIndex ]
986+ for ( let gi = 0 ; gi < nestedBlockTagGroups . length ; gi ++ ) {
987+ const group = nestedBlockTagGroups [ gi ]
988+ for ( let ni = 0 ; ni < group . nestedTags . length ; ni ++ ) {
989+ const nestedTag = group . nestedTags [ ni ]
990+ if ( nestedTag . children && nestedTag . children . length > 0 ) {
991+ const firstChild = nestedTag . children [ 0 ]
992+ if ( firstChild . fullTag === selectedTag ) {
993+ return { groupIndex : gi , nestedTagIndex : ni }
994+ }
995+ }
996+ }
997+ }
998+ return null
999+ }
1000+
9801001 if ( inSubmenu ) {
9811002 const currentHovered = hoveredNested
9821003 if ( ! currentHovered ) {
@@ -1105,31 +1126,22 @@ export const TagDropdown: React.FC<TagDropdownProps> = ({
11051126 } )
11061127 break
11071128 case 'ArrowRight' :
1108- e . preventDefault ( )
1109- e . stopPropagation ( )
1110- if ( selectedIndex >= 0 && selectedIndex < orderedTags . length ) {
1111- const selectedTag = orderedTags [ selectedIndex ]
1112- for ( const group of nestedBlockTagGroups ) {
1113- for (
1114- let nestedTagIndex = 0 ;
1115- nestedTagIndex < group . nestedTags . length ;
1116- nestedTagIndex ++
1117- ) {
1118- const nestedTag = group . nestedTags [ nestedTagIndex ]
1119- if ( nestedTag . children && nestedTag . children . length > 0 ) {
1120- const firstChild = nestedTag . children [ 0 ]
1121- if ( firstChild . fullTag === selectedTag ) {
1122- setInSubmenu ( true )
1123- setSubmenuIndex ( 0 )
1124- setHoveredNested ( {
1125- tag : `${ group . blockId } -${ nestedTag . key } ` ,
1126- index : nestedTagIndex ,
1127- } )
1128- return
1129- }
1130- }
1131- }
1129+ {
1130+ const targetLocation = canEnterSubmenuForSelected ( )
1131+ if ( ! targetLocation ) {
1132+ // No submenu action for current selection; allow caret move
1133+ return
11321134 }
1135+ e . preventDefault ( )
1136+ e . stopPropagation ( )
1137+ const group = nestedBlockTagGroups [ targetLocation . groupIndex ]
1138+ const nestedTag = group . nestedTags [ targetLocation . nestedTagIndex ]
1139+ setInSubmenu ( true )
1140+ setSubmenuIndex ( 0 )
1141+ setHoveredNested ( {
1142+ tag : `${ group . blockId } -${ nestedTag . key } ` ,
1143+ index : targetLocation . nestedTagIndex ,
1144+ } )
11331145 }
11341146 break
11351147 case 'Enter' :
0 commit comments