Skip to content

Element.focusNextChild/focusPreviousChild do not respect hidden property #266

@KJ7LNW

Description

@KJ7LNW

Summary

Element.prototype.focusNextChild and Element.prototype.focusPreviousChild do not check the hidden property before giving focus to children. This causes arrow key navigation to reach hidden elements in collapsible widgets like SelectList and SelectListMulti.

Expected Behavior

When a SelectList is collapsed, pressing UP/DOWN arrow keys should not navigate to the hidden menu items. Only the master button should be focusable when the dropdown is closed.

Actual Behavior

Arrow keys navigate through all children including those with hidden = true, causing focus to move to invisible elements.

Root Cause

Document.focusNext() and Document.focusPrevious() correctly check !currentElement.hidden before calling giveFocusTo_() (Document.js lines 243, 252, 267).

However, Element.focusNextChild() and Element.focusPreviousChild() (Element.js lines 543-569, 573+) call giveFocusTo_() unconditionally without checking the hidden property.

Suggested Fix

Add hidden check in Element.focusNextChild before giveFocusTo_:

// Current (Element.js ~line 562):
focusAware = this.document.giveFocusTo_( this.children[ index ] , type ) ;

// Suggested fix:
if ( ! this.children[ index ].hidden ) {
    focusAware = this.document.giveFocusTo_( this.children[ index ] , type ) ;
}

Same change needed in focusPreviousChild.

Environment

  • terminal-kit version: 3.1.2
  • Node.js version: 22.x
  • Platform: Linux

Workaround

We are currently patching Element.prototype.focusNextChild and Element.prototype.focusPreviousChild at module load to add the hidden check, matching the behavior in Document.focusNext.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions