Harlock.Tabs (harlock v0.3.0)

Copy Markdown View Source

Key-event helper for the Harlock.Elements.tabs/1 widget.

The widget is a dumb renderer — the app holds the active tab id in its model. When the tabs element has focus, route key events through apply_key/3 to compute the next active id:

def update({:key, _, _} = event, %{tab: active} = model) do
  case Harlock.Focus.current() do
    :tabs ->
      case Harlock.Tabs.apply_key(event, active, [{:a, "Alpha"}, {:b, "Beta"}]) do
        {:select, id} -> %{model | tab: id}
        :noop -> model
      end

    _ ->
      model
  end
end

Bindings:

  • Left / Right — cycle tabs (with wrap)
  • Home / End — first / last
  • anything else — :noop

Summary

Functions

Map a {:key, key, mods} event to a selection change.

Types

event()

@type event() :: {:select, id()} | :noop

id()

@type id() :: any()

item()

@type item() :: {id(), String.t()}

Functions

apply_key(arg1, active, items)

@spec apply_key({:key, any(), [atom()]}, id(), [item()]) :: event()

Map a {:key, key, mods} event to a selection change.