Keyboard focus management in Feathers UI
In desktop apps, users expect to be able to use the Tab key to navigate between focusable UI components, and they expect to be able to use the Space or Enter key trigger buttons, or the arrow keys to adjust sliders, numeric steppers, and scroll bars. On smart TVs and game consoles, the remote or gamepad typically provides a d-pad or another input method for passing focus up, down, to the left, or to the right.
Enabling the Focus Manager
Feathers UI automatically enables focus management when the main entrypoint is a subclass of the Application
component.
import feathers.controls.Application;
class MyProject extends Application {
public function new() {
super();
}
}
However, if a project isn't using the Application
component, focus management may be enabled manually by calling FocusManager.addRoot()
when the project first starts up.
// only when not using the Application component
FocusManager.addRoot(stage);
Changing Focus Programmatically
Call the static method FocusManager.setFocus()
to change focus manually.
FocusManager.setFocus(component);
The UI component passed to
FocusManager.setFocus()
must implement theIFocusObject
interface, and itsfocusManager
property must not benull
. If the focus manager is enabled, this property will be automatically populated when a UI component is added to the stage.
Disabling focus
To allow a component to receive focus from mouse or touch only, but to be skipped when changing focus with the keyboard, set the tabEnabled
property to false
.
component.tabEnabled = false;
In rare cases, it may be necessary to completely disable the ability of a UI component to receive focus. Set the focusEnabled
property to false
to prevent a component from receiving focus at all.
component.focusEnabled = false;