TermUI.Focus.Traversal (TermUI v0.2.0)
View SourceFocus traversal utilities for calculating tab order.
Provides utilities for determining the order in which components receive focus during Tab/Shift+Tab navigation.
Tab Order
Components are ordered by:
- Explicit
tab_index(lower numbers first) - Screen position (top-to-bottom, left-to-right)
Usage
# Get tab order for components
order = Traversal.calculate_order(component_ids)
# Check if component should be skipped
Traversal.should_skip?(component_id)
Summary
Functions
Calculates the tab order for a list of components.
Filters a list to only focusable components.
Gets the next component in tab order.
Gets the previous component in tab order.
Checks if a component should be skipped during traversal.
Functions
Calculates the tab order for a list of components.
Returns components sorted by tab index, then by position.
Parameters
component_ids- List of component idsopts- Options::tab_indices- Map of component_id => tab_index
Returns
Sorted list of component ids.
Filters a list to only focusable components.
Parameters
component_ids- List of component idsopts- Options passed toshould_skip?/2
Returns
Filtered list of focusable component ids.
Gets the next component in tab order.
Parameters
ordered_list- Components in tab ordercurrent- Currently focused component (or nil)
Returns
Next component id, wrapping to first if at end.
Gets the previous component in tab order.
Parameters
ordered_list- Components in tab ordercurrent- Currently focused component (or nil)
Returns
Previous component id, wrapping to last if at beginning.
Checks if a component should be skipped during traversal.
A component is skipped if:
- It has
focusable: false - It has
disabled: true - It has a negative
tab_index
Parameters
component_id- Component to checkopts- Options::focusable- Map of component_id => boolean:disabled- Map of component_id => boolean:tab_indices- Map of component_id => integer
Returns
Boolean indicating if component should be skipped.