Tags input
v0.0.10
v0.0.10StableMobStatelessApache-2.0
Installation
mix mishka.ui.gen.mob tags_input
Source
View Source
The Mishka Chelekom Mob Tags Input is a bordered control that holds removable tag tokens above a text field for the next tag, on iOS and Android. It is the native port of the headless Tags Input and runs on Mob.
Props
Props of the <MishkaTagsInput> tag.
| Prop | Type | Default | Description |
|---|---|---|---|
tags | list of strings | [] | The current tokens. |
draft | string | "" | The value of the text field. |
placeholder | string | nil | Placeholder of the draft field. It shows Add a tag… when unset. |
disabled | boolean | false | Mutes the control and unwires everything. |
on_draft / on_add / on_remove | event tags | None | Events for typing, for the return key and for a token's ✕. See Events below. |
background / corner_radius / padding | color / radius / spacing | :surface / :radius_md / :space_sm | The control's own box. border_width: 0 removes the outline. |
border_color / border_width | color / number | :border / 1 | The outline. The draft field inside draws no box of its own. |
space | number | 6 | Gap between tokens. |
wrap_chars | number | 34 | Characters per row of tokens. Nothing on the Elixir side can measure text. |
id | string | nil | Tags the draft as <id>-draft and each token as <id>-tag-<tag>. |
add/3, remove/2 and wrap/2 | helpers | None | Trim and reject blanks and duplicates, remove by value, and pack token rows. |
Events
Your screen receives these messages in handle_info/2.
on_draftsends{:change, tag, text}as the draft is typed.on_addsends{:submit, tag}when the user presses return. It carries no text, so commit the draft you already hold, as the first example shows.on_removesends{:tap, {tag, tag_string}}when the user taps a token's ✕, wheretag_stringis the tag to remove.
elixir
def handle_info({:change, :draft, text}, socket) do
{:noreply, assign(socket, :draft, text)}
end
def handle_info({:tap, {:remove, tag}}, socket) do
{:noreply, assign(socket, :tags, MishkaTagsInput.remove(socket.assigns.tags, tag))}
endDifferences from the web component
nameandinput_nameare not ported, because they are form plumbing.- The
*_classattributes are not ported. The control's box is a set of props.
Attributes
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
tags
|
list of strings
|
[]
| — | No | The current tokens. |
draft
|
string
|
""
| — | No | The text field's value. |
placeholder
|
string
| — | — | No | Draft placeholder. |
disabled
|
boolean
|
false
| — | No | Mutes and unwires everything. |
on_draft
|
event tag (atom)
| — | — | No | `{:change, tag, text}` as the draft is typed. |
on_add
|
event tag (atom)
| — | — | No | Fired on return. Carries NO text — commit your own draft. |
on_remove
|
event tag (atom)
| — | — | No | `{:tap, {tag, tag_string}}` from a token's ✕. |
background / border_color / border_width / corner_radius / padding
| — | — | — | No | The control. |
space
|
number
|
6
| — | No | Gap between tokens. |
wrap_chars
|
number
|
34
| — | No | Roughly how much text fits on one token row. |
id
|
string
| — | — | No | Tags the draft field and each token's ✕. |
Options
Each option takes one or more of its values, separated by commas.
| Option | Values |
|---|---|
--type
|
tags_input
|
--module
| A module name of your own |
What it generates
Functions
tags_input
Helpers
None
Generated with it
pill
Command
mix mishka.ui.gen.mob tags_input