Structural layout and navigation
Structural layout and navigation components give Phoenix screens a clear frame and a clear path. They help an application group content, expose related choices, show location, guide a multi-step task, and move through a set of views without each screen inventing its own structure.
Screen boundaries
Containers
The container is the page-width boundary for a screen or section. It keeps content within a chosen maximum width and adds mobile padding by default, so the same page structure can adapt from a narrow phone view to a wide desktop view. PetalComponents.Container supports sm, md, lg, xl, and full widths, with an option to remove mobile padding when a layout needs edge-to-edge content.
References: lib/…/container.ex• L4-27 test/…/container_test.exs• L5-72
Cards
The card is a bounded content surface for related information or an action area. Its composable header, media, content, and footer parts let a screen establish hierarchy without treating every panel as a separate layout pattern. Basic and outline styles provide the main bordered surface, while the muted style creates a quieter inset area; media can show an image or a placeholder.
References: lib/…/card.ex• L6-113 test/…/card_test.exs• L5-138
Content disclosure
Accordions
The accordion organizes optional detail under headings so a screen can preserve context while reducing visible length. It can start with one section open, allow one section at a time or several sections at once, and present either row-style or boxed sections. Each heading controls a named content region, which gives the disclosure a usable keyboard and screen-reader relationship.
References: lib/…/accordion.ex• L7-35 lib/…/accordion.ex• L66-173 lib/…/accordion.ex• L177-240 test/…/accordion_test.exs• L59-239
Location and choice navigation
Breadcrumbs
Breadcrumbs show the user’s place inside a hierarchy and provide links back to higher levels. The last crumb represents the current page, while earlier crumbs can use normal links or Phoenix LiveView patch and redirect links. Slash and chevron separators support different visual treatments without changing the path model.
References: lib/…/breadcrumbs.ex• L6-53 test/…/breadcrumbs_test.exs• L119-168
Tabs
Tabs group peer views under one local navigation bar. An active tab is explicit, and a tab can navigate by a normal link, a LiveView patch, a LiveView redirect, or a button when selection is handled by a local action. Pill, underline, and segmented styles change the visual cue, while the tab list and tab roles preserve the relationship between the choices.
References: lib/…/tabs.ex• L7-45 lib/…/tabs.ex• L47-123 test/…/tabs_test.exs• L6-252
Navigation menus
The navigation menu supports top-level site navigation where an item may be a direct destination or may open a larger flyout. Flyout triggers expose their open state and controlled panel, and the panel can contain simple links, descriptive link rows, or a footer with calls to action. Hover mode suits pointer-oriented top navigation; click mode gives touch-first screens explicit open, click-away, and Escape behavior. A panel can also align to the trigger edge or span a positioned header as a mega menu.
References: lib/…/navigation_menu.ex• L1-35 lib/…/navigation_menu.ex• L47-165 test/…/navigation_menu_test.exs• L5-186
Vertical menus
The vertical menu organizes application destinations in a sidebar or other stacked navigation area. It can group items, mark the current page, and nest child destinations under a toggle. A nested branch stays open when its current page is inside that branch, so the active location remains visible while the user moves through the application.
References: lib/…/menu.ex• L102-188 lib/…/menu.ex• L192-263 test/…/menu_test.exs• L5-185
Links
The shared link pattern keeps navigation semantics consistent across these structures. It can render a normal anchor, a LiveView patch, a LiveView redirect, or a button for action-like navigation; a disabled link becomes a disabled button because anchors do not support a disabled state. This lets breadcrumbs, tabs, and menus choose the right navigation behavior without changing their surrounding layout.
References: lib/…/link.ex• L4-60 lib/…/breadcrumbs.ex• L32-40 lib/…/tabs.ex• L50-111
Guided and sequential views
Steppers
The stepper presents progress through an ordered journey. Each step can be active or complete and can expose a click target, while connectors show which adjacent steps are complete. Horizontal and vertical layouts support different screen shapes; circle and bar variants provide either a numbered progress path or a compact progress-bar read.
The following diagram shows the state relationship in a multi-step journey.
flowchart LR
A[Completed step] --> B[Active step]
B --> C[Pending step]
A -. completed connector .- B
B -. pending connector .- C
References: lib/…/stepper.ex• L5-43 lib/…/stepper.ex• L45-129 test/…/stepper_test.exs• L29-374
Sliding views
Carousels
The carousel presents a set of slides through one active frame. Users can move with previous and next controls, indicators, or thumbnails, and the component can also autoplay, loop, respond to touch swipes, and show more than one slide at a time. It supports horizontal or vertical travel, fade or slide transitions, optional image and text content, and links from a slide to an internal or external destination.
The carousel keeps the active slide, its controls, and its announcements tied to one named region. The browser behavior can therefore update the visible slide without changing the meaning of the slide set for assistive technology.
References: lib/…/carousel.ex• L47-139 lib/…/carousel.ex• L141-175 lib/…/carousel.ex• L197-351 test/…/carousel_test.exs• L5-324
Navigation selection guide
Choose the pattern by the relationship between the destinations or content, not only by its visual shape:
| Need | Pattern | Main user model |
|---|---|---|
| Keep a page or section within a readable width | Container | Screen boundary |
| Group related content into a bounded surface | Card | Content surface |
| Hide optional detail under headings | Accordion | Expandable detail |
| Show a location in a hierarchy | Breadcrumbs | Path to the current page |
| Switch between peer views | Tabs | Local view choice |
| Show position in an ordered task | Stepper | Journey progress |
| Move through media or a slide set | Carousel | Sequential or browseable slides |
| Expose site or application destinations | Navigation or vertical menu | Destination discovery |
Change checklist
When these files or sections are changed, remember to consider these:
- Keep accordion heading and content IDs aligned when changing disclosure markup or its client-side toggle behavior.
- Keep tab active state and link type aligned with the state owner. A button tab needs local selection behavior; a route tab needs a matching path and active calculation.
- Keep navigation-menu trigger mode aligned with the browser behavior. Hover mode depends on the navigation hook, while click mode depends on LiveView.JS dismissal rules.
- Keep stepper
active?,complete?, andon_clickdata aligned with the journey state. The visible progress and the announced current step come from the same step records. - Keep carousel control, indicator, thumbnail, and slide IDs derived from the same carousel ID. A changed ID contract can leave controls connected to the wrong slide set.
- Keep internal destinations on LiveView navigation links and external slide destinations on external links so browser navigation and target behavior remain correct.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An accordion receives a heading from both its item slot and its entry data | Rendering raises an argument error because the component cannot choose one label | Define the heading in one source only |
| A tab is rendered as a button without selection handling | The user can click a choice but no route or local state changes | Use a route link or provide the button action |
| A navigation-menu flyout uses hover mode without the bundled navigation hook | The panel does not receive its intended pointer and keyboard behavior | Register the component hook bundle in the consuming LiveView application |
| A stepper marks a later step complete while the prior step is incomplete | The progress line gives a false journey state | Set completion on ordered step records and verify adjacent states |
| A carousel control or thumbnail uses an ID from another carousel | The control changes the wrong slide set or does nothing | Keep all related IDs under one unique carousel ID |
Key files
| File | Why to read it |
|---|---|
lib/petal_components/container.ex | Defines the screen-width boundary and mobile padding behavior. |
lib/petal_components/card.ex | Shows how a bounded content surface is assembled from media, header, content, and footer parts. |
lib/petal_components/accordion.ex | Defines expandable sections and their accessibility relationship. |
lib/petal_components/breadcrumbs.ex | Defines hierarchical location links and current-page marking. |
lib/petal_components/tabs.ex | Defines local view navigation and its link or button choices. |
lib/petal_components/navigation_menu.ex | Defines direct links, flyout panels, and site-level navigation modes. |
lib/petal_components/menu.ex | Defines grouped and nested vertical application navigation. |
lib/petal_components/stepper.ex | Defines ordered progress states and journey navigation targets. |
lib/petal_components/carousel.ex | Defines the slide set, controls, indicators, thumbnails, and slide destinations. |
lib/petal_components/link.ex | Defines the shared destination and LiveView navigation choices used by structural patterns. |
See also: Layout, navigation, and content primitives, Content and identity primitives, and Application workspace layout.