Nav link
v0.0.10
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.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | nil | Base of the row's test tags. Without an id there are no tags. |
label | string | nil | The row's text. |
description | string | nil | A second line under the label. |
icon | glyph string, node or list | nil | Leading content. This is the web slot. |
trailing | glyph string, node or list | nil | Trailing content. A group shows its chevron instead. |
active | boolean | false | Current page styling, the web data-active. |
opened | boolean | nil | Whether the nested group is expanded. Wins over default_opened. |
default_opened | boolean | false | Opens the group initially, while opened is nil. |
disabled | boolean | false | Mutes the row and removes its handler. |
href | string | nil | Comes back with the tap, as in Anchor. |
indent | number | 16 | Indent applied to the nested links. |
on_tap | event tag (atom) | none | Tap on a leaf. |
on_toggle | event tag (atom) | none | Tap 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?)}
endDifferences from the web component
The Mob Nav Link does not port these parts of the headless component:
navigateandpatch. They are LiveView routing concepts. On a device your screen decides how to navigate, and the destination comes back with the tap ashref.class,label_class,children_classandrest. There is no CSS and there are no DOM attributes.- The
inner_blocklabel slot. The children of the tag are the nested links, so set the text withlabel. aria-current. No node type in the bridge carries accessibility semantics.
Attributes
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
id
|
string
| — | — | No | Base of the row's test tags. No id, no tags. |
label
|
string
| — | — | No | The row's text. |
description
|
string
| — | — | No | A second line under the label. |
icon
|
glyph string, node, or list
| — | — | No | Leading content — the web's slot. |
trailing
|
glyph string, node, or list
| — | — | No | Trailing content. Replaced by the chevron when it has children. |
active
|
boolean
|
false
| — | No | Current-page styling — the web's `data-active`. |
opened
|
boolean
| — | — | No | Whether the nested group is expanded. Wins over `default_opened`. |
default_opened
|
boolean
|
false
| — | No | Open initially, while `opened` is `nil`. |
disabled
|
boolean
|
false
| — | No | Mutes and unwires. |
href
|
string
| — | — | No | Rides along with `on_tap`, as in `.Anchor`. |
indent
|
number
|
16
| — | No | Indent applied to the children. |
on_tap
|
event tag (atom)
| — | — | No | Tapping a leaf. |
on_toggle
|
event tag (atom)
| — | — | No | Tapping a parent's row. Falls back to `on_tap`. |
Options
Each option takes one or more of its values, separated by commas.
| Option | Values |
|---|---|
--type
|
nav_link
|
--module
| A module name of your own |
What it generates
Functions
nav_link
Helpers
None
Generated with it
None
Command
mix mishka.ui.gen.mob nav_link