Context menu
v0.0.10
mix mishka.ui.gen.mob context_menu
The Mob Context Menu in Mishka Chelekom opens the actions for one row or object on iOS and Android screens built with Mob. A user holds the object to open it, which is the touch version of a right-click. It is the native port of the headless Context Menu.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
for_label | string | nil | The object these actions apply to, shown as a heading above the actions. |
open | boolean | false | Whether the menu is shown. |
on_select | event tag | none | Sent as {:tap, {tag, item_id}}. |
| everything else | see Menu | none | The Context Menu renders through the Menu, so it accepts width, danger_color, the panel props and the row tags. |
trigger/3
trigger(id, children, opts) wraps the object the actions belong to. The options are :on_hold, an event tag, and :test_id, a string that becomes the wrapper's native test tag. Holding the wrapper sends {:tap, {tag, id}}.
Events
Two messages reach your screen in handle_info/2. A long press on the trigger sends {:tap, {tag, id}} with the tag you set in on_hold and the id you gave trigger/3. A tap on an enabled row sends {:tap, {tag, item_id}} with the tag you set in on_select.
def handle_info({:tap, {:open_for, id}}, socket) do
{:noreply, Mob.Socket.assign(socket, :open_for, id)}
end
def handle_info({:tap, {:act, action}}, socket) do
socket =
socket
|> Mob.Socket.assign(:last, action)
|> Mob.Socket.assign(:open_for, nil)
{:noreply, socket}
endDifferences from the web component
The Mob Context Menu does not port these parts of the headless Context Menu:
- Placement at the pointer. A touch has no cursor to open at, and a phone has no room for a menu pinned to a coordinate.
- The web component's
idand*_classattributes.
Attributes
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
for_label
|
string
| — | — | No | The object these actions apply to, shown as a heading. |
Options
Each option takes one or more of its values, separated by commas.
| Option | Values |
|---|---|
--type
|
context_menu
|
--module
| A module name of your own |
What it generates
mix mishka.ui.gen.mob context_menu