Nav link

v0.0.10

v0.0.10StableMobStatelessApache-2.0
Installation mix mishka.ui.gen.mob nav_link
Source View Source

The Mishka Chelekom Mob Nav Link is a navigation row for iOS and Android screens built with Mob. A row is either a link or a group that opens to show nested links. It is the native port of the headless Nav Link.

Test tags

A row shows that it is the current page with a color, and a group shows that it is open with a glyph. A device test reads neither. With id set, each node carries a tag that names its state. The label and description are text, so a test can already read them.

TagNodeWhen
<id>The tappable rowAlways. It is stable across every state, so a test can tap it.
<id>-active, -inactive, -disabledThe labelOne for each ink the label can take.
<id>-open, -closedThe chevronOn a group only.
<id>-iconThe leading glyphWhen icon is set.
<id>-trailingThe trailing glyphOn a leaf with trailing set.

Props

PropTypeDefaultDescription
idstringnilBase of the row's test tags. Without an id there are no tags.
labelstringnilThe row's text.
descriptionstringnilA second line under the label.
iconglyph string, node or listnilLeading content. This is the web slot.
trailingglyph string, node or listnilTrailing content. A group shows its chevron instead.
activebooleanfalseCurrent page styling, the web data-active.
openedbooleannilWhether the nested group is expanded. Wins over default_opened.
default_openedbooleanfalseOpens the group initially, while opened is nil.
disabledbooleanfalseMutes the row and removes its handler.
hrefstringnilComes back with the tap, as in Anchor.
indentnumber16Indent applied to the nested links.
on_tapevent tag (atom)noneTap on a leaf.
on_toggleevent tag (atom)noneTap on a parent row. Falls back to on_tap.

Events

on_tap and on_toggle send {:tap, {tag, href}} to the screen when the row has an href, and {:tap, tag} when it does not. A disabled row sends nothing. Handle both in handle_info/2.

elixir
def handle_info({:tap, {:pick, href}}, socket) do
  {:noreply, Mob.Socket.assign(socket, :current, href)}
end

def handle_info({:tap, :toggle}, socket) do
  {:noreply, Mob.Socket.assign(socket, :open?, not socket.assigns.open?)}
end

Differences from the web component

The Mob Nav Link does not port these parts of the headless component:

  • navigate and patch. They are LiveView routing concepts. On a device your screen decides how to navigate, and the destination comes back with the tap as href.
  • class, label_class, children_class and rest. There is no CSS and there are no DOM attributes.
  • The inner_block label slot. The children of the tag are the nested links, so set the text with label.
  • aria-current. No node type in the bridge carries accessibility semantics.