Breadcrumb
v0.0.10
mix mishka.ui.gen.headless breadcrumb
Item slot - links and the current page
Each crumb is an item slot. Give it navigate (a LiveView navigation), patch or href and it renders as a link. A crumb with none of the three renders as a plain <span>. The slot class is added to that link or span (data-part="link"), not to the list item.
The last crumb is the current page by default, so it renders as <span aria-current="page"> even when it has an address. Set current on any crumb to make it the current page. Set current={false} on the last crumb to keep it a link, for a trail that ends in a section of the page instead of the page itself.
Separator slot
Without a separator slot every gap between crumbs holds a / character and the separator carries data-default. The slot content replaces it, and it is rendered once for each gap.
<.breadcrumb separator_class="px-1 text-neutral-400">
<:separator><.icon name="hero-chevron-right" class="size-3" /></:separator>
<:item navigate={~p"/"}>Home</:item>
<:item navigate={~p"/docs"}>Docs</:item>
<:item>Breadcrumb</:item>
</.breadcrumb>Collapsing a long trail with max_items
max_items shortens the trail once it has more crumbs than that number. boundary (default 1) is how many crumbs stay at each end. A trail of boundary * 2 + 1 crumbs or fewer is left whole, because the ellipsis would hide one crumb at most. The default for max_items is nil, which never collapses.
By default the ellipsis is a plain <span> and takes no tab stop. Pass on_expand, a LiveView event name or a Phoenix.LiveView.JS command, and it becomes a <button type="button"> named by expand_label (default Show all). The component does not expand itself. Your handler renders the trail again without max_items.
<.breadcrumb max_items={@max_items} on_expand="expand_trail" expand_label="Show all pages">
<:item :for={crumb <- @trail} navigate={crumb.path}>{crumb.title}</:item>
</.breadcrumb>def handle_event("expand_trail", _params, socket) do
{:noreply, assign(socket, :max_items, nil)}
endParts & data attributes
Each part carries a stable data-part and a structural chelekom-breadcrumb__* class you can target, plus the state attributes below.
| Part | data-part | State / ARIA | Purpose |
|---|---|---|---|
| Root | root | aria-label, data-collapsed | The nav landmark. data-collapsed is present while the middle of the trail is elided. |
| List | list | - | The ordered list. |
| Item | item | data-index | One list item for each crumb or ellipsis. |
| Separator | separator | aria-hidden, data-default | Sits between items. data-default is present when the built-in / is used. |
| Link | link | aria-current | An a element for a link, or a span for the current page and for a crumb with no address. |
| Ellipsis | ellipsis | aria-label | A button when on_expand is given, otherwise a span. |
Accessibility
Follows the WAI-ARIA Breadcrumb pattern: the trail is a labelled nav landmark holding an ordered list, and the current page is marked with aria-current="page". Tab moves through the links and Enter follows one. Separators are hidden from assistive technology. The collapsed ellipsis is focusable only when on_expand turns it into a button.
Attributes
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
id
|
string
| — | — | No | Unique id |
label
|
string
|
Breadcrumb
| — | No | Accessible name for the nav landmark |
max_items
|
integer
| — | — | No | Collapse the middle of the trail once it is longer than this; nil never collapses |
boundary
|
integer
|
1
| — | No | How many items to keep at each end when collapsing |
on_expand
|
any
| — | — | No | A JS command or LiveView event name; makes the ellipsis a real button |
expand_label
|
string
|
Show all
| — | No | Accessible label for the ellipsis button |
class
|
any
| — | — | No | Extra classes for the root |
list_class
|
any
| — | — | No | — |
item_class
|
any
| — | — | No | — |
separator_class
|
any
| — | — | No | — |
ellipsis_class
|
any
| — | — | No | — |
link_class
|
any
| — | — | No | — |
rest
|
global
| — | — | No | — |
Slots
| Name | Required | Description |
|---|---|---|
separator
| No | Custom separator; falls back to a `/` character |
item
| No | One crumb |
Attributes of the item slot
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
navigate
|
string
| — | — | No | — |
patch
|
string
| — | — | No | — |
href
|
string
| — | — | No | — |
current
|
boolean
| — | — | No | Force this crumb to be the current page |
class
|
any
| — | — | No | — |
Options
Each option takes one or more of its values, separated by commas.
| Option | Values |
|---|---|
--type
|
breadcrumb
|
--module
| A module name of your own |
What it generates
mix mishka.ui.gen.headless breadcrumb