Skip to content

Skip invisible widgets during keyboard focus navigation - #632

Open
metif12 wants to merge 2 commits into
vlang:masterfrom
metif12:focus-visibility
Open

metif12 wants to merge 2 commits into
vlang:masterfrom
metif12:focus-visibility

Conversation

@metif12

@metif12 metif12 commented Nov 21, 2026

Copy link
Copy Markdown
Member

Problem

Focus navigation used only !f.hidden as its visibility test (Focusable.has_focusable()). Mouse hit-testing, by contrast, requires is_visible() && is_parent_visible(true) && !has_parent_deactivated(). As a result:

  • widgets hidden by z_index = z_index_hidden (accordion, hideable, grid and treeview components) were still reachable with Tab and set_focus_first/last;
  • widgets inside a hidden or deactivated parent layout were still focusable;
  • force_focus() (used by Button.focus() and TextBox.focus()) bypassed even the hidden check and could steal focus from the real focused widget.

Change

Add Focusable.is_focus_visible() using the same predicates as mouse hit-testing, and use it in has_focusable(), set_focus() and force_focus(). An unfocusable widget is rejected before unfocus_all() runs, so it can no longer clear focus from the currently focused widget.

Notes

Add a disabled field and param to Dropdown, Switch, Radio, Slider, TextBox, Picture and Menu/MenuItem, and guard every input handler so disabled widgets cannot be clicked, focused, dragged or typed into. Dim their drawing with a shared dim_color helper.

CheckBox.disabled was declared but never read; it now blocks both mouse and keyboard toggling. ListBox disabled items are no longer selectable via single-select clicks or arrow keys, draggable, or hover-highlighted. Focus navigation now skips disabled widgets via Focusable.is_disabled(), and set_focus/force_focus no longer steal focus for them.

Document the new params in docs.md.
Focus navigation used only !hidden, so widgets hidden via z_index_hidden or inside a deactivated/absent parent layout were still Tab-reachable, and force_focus() bypassed even hidden.

Add Focusable.is_focus_visible() using the same predicates as mouse hit-testing (is_visible, is_parent_visible(true), !has_parent_deactivated) and use it in has_focusable(), set_focus() and force_focus(), so an unfocusable widget no longer steals focus from the currently focused one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant