Application workspace layout
Application workspace layout combines persistent navigation, bounded scroll regions, adjustable panes, and long-form reading aids. These primitives let a page keep its shell stable while users move through content, change the space given to each work area, and understand their position in a long view. It complements Layout navigation and content, Structural layout and navigation, and Content and identity primitives.
Workspace shell
The workspace shell is a flex layout that keeps a navigation rail beside the page area. The sidebar can hold brand content, grouped links, nested links, badges, and a footer action, while the main area holds the page header and content.
PetalComponents.Sidebar.sidebar_shell/1 is the main shell for this relationship. Use sidebar_nav/1 for the navigation landmark, sidebar_group/1 for labelled runs of links, and sidebar_item/1 for links or nested disclosures.
Sidebar modes
The sidebar supports a fixed desktop rail, an icon rail, or an off-canvas sheet. A collapse trigger changes the rail on the client. A mobile trigger opens the sheet below the md breakpoint. The shell marks the main area inert while the sheet is open, locks page scrolling, and returns focus to the trigger when the sheet closes.
| Mode | Workspace behavior |
|---|---|
icon | The rail can reduce to an icon-only width and becomes an off-canvas sheet on small screens. |
offcanvas | The sidebar can leave the main flow and open as a sheet on small screens. |
none | The sidebar stays open at every width. |
The server supplies the initial collapsed state. If the application must keep that choice across navigation, the application owns the saved state and passes it back to the sidebar. The component does not store it by itself.
References: lib/…/sidebar.ex• L54-78 lib/…/sidebar.ex• L60-90
Sidebar sections
Sidebar groups and parent items are independent disclosure regions. Their buttons expose expanded state and control the item content, so a workspace can reduce navigation clutter without changing the page route.
References: lib/…/sidebar.ex• L219-347 lib/…/sidebar.ex• L94-124
Scroll areas
The scroll area gives a workspace a bounded region that uses native scrolling with a design-system scrollbar treatment. It supports vertical, horizontal, or two-axis movement, while the caller sets the viewport size with layout classes.
PetalComponents.ScrollArea.scroll_area/1 stays free of JavaScript. This keeps native momentum, keyboard movement, and assistive technology behavior. A focusable scroll area supports arrow keys, Page Up and Page Down, Home, and End. Use tabindex="-1" when the content already provides a useful path into the region, such as a list of links.
Scroll area affordances
Scroll area options describe how users perceive overflow rather than changing the scroll model:
| Option | Workspace use |
|---|---|
orientation | Selects vertical, horizontal, or both scroll axes. |
fade_edges | Softens the edges on the scrolling axis to suggest more content. The fade is static. |
gutter_stable | Reserves space for classic scrollbars to prevent content shift. Overlay scrollbars have no space to reserve. |
visibility="always" | Requests a visible scrollbar where the browser and operating system allow it. |
Name a standalone scroll region with aria-label or aria-labelledby. A named region becomes a landmark. An unnamed region remains an ordinary focusable container so it does not add noise to the landmark list.
References: lib/…/scroll_area.ex• L89-107 lib/…/scroll_area.ex• L167-183 lib/…/scroll_area.ex• L22-93
Resizable panels
Resizable panels divide a workspace into panes that users can adjust to match their task. The group keeps pane sizes as percentages, so the split remains proportional when the window changes size. A handle between each adjacent pair is both the drag control and the keyboard control.
PetalComponents.Resizable.resizable_group/1 coordinates panels and handles. A horizontal group places panels side by side. A vertical group stacks them. Nested groups support workspaces such as a file tree, editor, preview, and terminal because each group manages only its direct panels.
This diagram shows how a workspace split turns a group of panels and handles into an adjustable layout and optional saved size data.
flowchart LR
G[Resizable group] --> P1[Panel]
P1 --> H[Handle]
H --> P2[Panel]
H --> D[Drag or keyboard change]
D --> S[Percentage sizes]
S --> E[DOM event]
S --> L[Optional LiveView event]
Panel sizing
Each panel can declare a default percentage, a minimum, and a maximum. Panels without a default share the remaining space. A collapsible panel can snap to a separate collapsed size when a drag crosses its collapse threshold. The library does not save the result; the application can persist the emitted sizes in the session, URL, or local storage.
References: lib/…/resizable.ex• L130-180 assets/…/petal_components.js• L7406-7465 assets/…/petal_components.js• L7541-7561
Resize handles
The handle is an accessible separator with a name and live size values. Pointer dragging changes the two adjacent panels while preserving the group total. Keyboard input follows the separator direction: arrows resize by a small step, Shift makes a larger step, Home moves the preceding panel to its lower bound, End moves it to its upper bound, and Enter toggles collapse when allowed. A double click restores the adjacent panels to their default ratio.
Give a panel an id when its handle must identify it with aria-controls or when the application must identify collapse events. Set a height or width on the group through the surrounding layout because the group has no useful size without a constraint.
References: lib/…/resizable.ex• L183-247 assets/…/petal_components.js• L7467-7616 assets/…/petal_components.js• L7618-7668 lib/…/resizable.ex• L8-76
Separators
The separator provides a hairline that divides workspace content without imposing layout spacing. It can run horizontally between regions or vertically inside a toolbar and flex row. The caller supplies the gap or margin that matches the surrounding layout.
PetalComponents.Separator.separator/1 supports an optional horizontal label for boundaries such as dates or “OR”. A vertical separator ignores labels because a label does not fit that form. Separators are decorative by default. Mark one as semantic only when the division itself matters to assistive technology; then it exposes the separator role and its orientation when needed. The component does not add margin, so the surrounding workspace controls the gap around the rule. For a vertical rule, the parent must provide a height when stretch alone is not enough.
References: lib/…/separator.ex• L1-43 lib/…/separator.ex• L45-130 lib/…/separator.ex• L7-86
Long-form views
Long-form views need both a readable content flow and a way to show the reader where they are. A scrollspy rail links section ids to the article and changes its active entry as the matching section reaches a reading position.
PetalComponents.Scrollspy.scrollspy/1 renders a labelled navigation rail. The rail supports one nested level for a section and its subsections. The same behavior can also attach to custom markup when the container uses the PetalScrollspy hook and each link names its target with data-scrollspy-target.
This diagram shows the relationship between the long-form content, its section links, and the active reading state.
flowchart LR
A[Article sections with ids] --> O[Scroll position observer]
L[On this page links] --> O
O --> C[Active section]
C --> V[Active class and aria-current]
L --> J[Native hash navigation]
J --> A
Scrollspy activation
The section that owns the activation line becomes active. When several sections are above that line, the newest section takes over. At the bottom of a scroll region, the last section becomes active even when it is too short to reach the line. A matching URL hash activates its section on mount and on hash changes.
The rail can follow either page scrolling or a nested scroll pane. It applies the configured offset to target sections so a fixed header does not cover a heading after a link jump. Normal motion uses smooth scrolling. Reduced-motion preferences keep jumps instant and remove indicator movement.
Scrolling changes the rail state but does not move focus or rewrite the URL hash. The active link exposes aria-current="location", while the indicator is decorative. This keeps position clear without making color or focus the only signal.
References: lib/…/scrollspy.ex• L43-100 assets/…/petal_components.js• L8735-8989 lib/…/scrollspy.ex• L5-167
Timelines
The timeline presents ordered records such as activity, deploy history, order tracking, or audit events. It is for reading a record, not for moving through an interactive process; use a stepper when the entries represent user-controlled progress.
PetalComponents.Timeline.timeline/1 uses an ordered list with a marker rail and content for each event. Entries can carry a time, title, description, and richer content. The default layout places the rail on the left. Compact mode suits dense feeds. Alternating mode uses both sides of a center rail on wider screens and returns to the default layout on small screens.
Timeline layouts
| Layout | Purpose |
|---|---|
| Default | General event history with content beside a left rail. |
| Compact | Dense activity feed with tighter spacing and smaller type. |
| Alternating | Milestones on both sides of a center rail on wider screens. |
| Horizontal | Milestones across a horizontal rail with content below and sideways scroll when needed. |
| Leading times | A separate time column for logs scanned by time. It falls back above the title on narrow screens. |
Markers can be dots, icons, avatars, or entry numbers. States distinguish complete, current, loading, and upcoming records. Current entries expose aria-current="step". Loading entries expose aria-busy="true" and show progress without relying only on motion. Upcoming entries are muted and have a hollow marker.
Horizontal timelines are focusable scroll regions and must have an accessible label. Their smooth movement follows the reduced-motion preference. The rail and connectors are decorative, while the ordered-list structure gives assistive technology the event order and count.
References: lib/…/timeline.ex• L28-73 lib/…/timeline.ex• L140-173 lib/…/timeline.ex• L136-260
Collapsible sections
A collapsible section shows or hides one related content region behind a persistent trigger. It reduces the visible length of settings, details, changelog entries, or optional form fields without changing the surrounding page layout.
PetalComponents.Collapsible.collapsible/1 is an independent disclosure. Opening one section does not close another. Use an accordion when a group of sections must coordinate so that only one stays open.
The server-rendered open value sets the initial state and can be changed by LiveView. Client-side toggling avoids a round trip. The trigger is a real button with expanded state and a content relationship. Closed content is inert, so it cannot receive focus or appear in the accessibility tree. Reduced-motion settings remove the height transition while keeping the content fully readable.
References: lib/…/collapsible.ex• L1-44 lib/…/collapsible.ex• L52-145 lib/…/collapsible.ex• L7-84
Change checklist
When these files or sections are changed, remember to consider these:
- Keep sidebar trigger ids, controlled sidebar ids, and the shell main-region id aligned so mobile focus return and inert behavior still target the correct elements.
- Keep resizable panel order, handle placement, orientation, and percentage event payloads aligned between the server markup and the client resize hook.
- Keep scrollspy section ids, link targets, and the scroll container relationship aligned; an unmatched target cannot become active.
- Keep timeline state labels and accessibility state in step with any visual state changes so current, loading, and upcoming records remain clear without color alone.
- Keep collapsible trigger and content ids paired when custom markup or external toggle commands drive the disclosure.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A mobile sidebar is opened without its shell main region or trigger relationship | Background content can remain available to focus, or focus can return to the wrong control | Use one matching sidebar_shell and sidebar_nav id set with the mobile trigger targeting that nav. |
| A resizable group has no size constraint | The group cannot provide a useful drag extent | Give the group a height or width through its layout class or parent. |
| A scrollspy link points to a missing section id | The link is rendered but no active state or observer target exists | Use the same unique ids in the article sections and the rail items. |
| A standalone scroll region has no accessible name | It becomes a focusable scrolling surface without a useful landmark name | Add aria-label or aria-labelledby, especially for horizontal timelines. |
| A collapsible region uses hidden content without the component state | Keyboard and assistive-technology users can encounter content that looks closed but remains reachable | Let the disclosure control aria-expanded, aria-controls, and inert state together. |
Key files
| File | Why to read it |
|---|---|
lib/petal_components/sidebar.ex | Defines the persistent app shell, responsive sidebar modes, grouped navigation, and mobile focus behavior. |
lib/petal_components/resizable.ex | Defines pane groups, panel constraints, accessible handles, and resize event contracts. |
| assets/…/petal_components.js | Shows the client behavior for pane sizing and scrollspy activation across nested scroll roots. |
lib/petal_components/scroll_area.ex | Defines the native scroll-region contract and overflow affordances. |
lib/petal_components/scrollspy.ex | Defines the long-form navigation contract and section target structure. |
lib/petal_components/timeline.ex | Defines ordered event records, layouts, markers, and event states. |
lib/petal_components/collapsible.ex | Defines independent disclosure sections and their accessibility state. |
lib/petal_components/separator.ex | Defines visual and semantic dividers for workspace chrome. |