Raxol. UI. FocusHelper
(Raxol v2.6.0)
View Source
Helpers for widgets to determine focus state from the render context.
The render context includes focused_element (the ID of the currently
focused widget). Widgets call focused?/2 during render to check if
they should display focus indicators.
Usage in a widget's render/2
def render(state, context) do
am_focused = FocusHelper.focused?(state.id, context)
style = if am_focused, do: FocusHelper.focus_style(state.style), else: state.style
# ... render with style
end
Summary
Functions
Merges focus indicator styles into the given base style.
Uses hardcoded defaults. Prefer focus_style/2 for theme-aware styling.
Merges focus indicator styles from the theme into the given base style. Falls back to hardcoded defaults when no theme focus config is present.
Returns true if the widget with the given ID is the currently focused element.
Returns the base style with focus styles merged in only if focused. Convenience for the common pattern in render/2.
Theme-aware variant of maybe_focus_style. Reads focus config from theme.
Looks up the style for a given pseudo-state from the theme. Falls back to built-in defaults when no theme config exists.
Determines the visual pseudo-state for a widget.
Functions
Merges focus indicator styles into the given base style.
Uses hardcoded defaults. Prefer focus_style/2 for theme-aware styling.
Merges focus indicator styles from the theme into the given base style. Falls back to hardcoded defaults when no theme focus config is present.
Returns true if the widget with the given ID is the currently focused element.
Returns the base style with focus styles merged in only if focused. Convenience for the common pattern in render/2.
Theme-aware variant of maybe_focus_style. Reads focus config from theme.
Looks up the style for a given pseudo-state from the theme. Falls back to built-in defaults when no theme config exists.
Determines the visual pseudo-state for a widget.
Priority: :disabled > :active > :focused > :default
widget_attrs should contain :disabled and/or :active boolean keys.