Scroller
v0.0.10
mix mishka.ui.gen.headless scroller
Overview of the Phoenix and LiveView Headless Scroller Component
The Mishka Chelekom Headless Scroller puts previous and next buttons around a horizontal row of items. In Phoenix LiveView it renders a root div, a viewport that holds your items, and two native buttons. A small Scroller hook scrolls the viewport by about 80% of its width, or by scroll_by pixels, when a button is pressed.
At each end of the row the matching button gets data-disabled and the native disabled attribute, and a ResizeObserver keeps that right when the viewport changes size. Buttons are styled with control_class, the viewport with viewport_class and the root with class.
Attributes and parts
id is required, because the hook is attached to the root. scroll_by is the distance in pixels for one press; without it the viewport scrolls by 80% of its width. prev_label and next_label are the aria-label values of the two buttons and default to "Scroll left" and "Scroll right".
The parts are the root (data-part="root"), prev, viewport and next. control_class is applied to both buttons. Their arrows are the characters ‹ and › inside an aria-hidden span, and the component has no slot to replace them. Style the data-disabled state with a variant such as data-[disabled]:opacity-30.
Accessibility
There is no formal WAI-ARIA pattern for a scroller. The two controls are native buttons, so Tab reaches them and Enter and Space press them, and a disabled end button leaves the tab order. The buttons are named by prev_label and next_label, so translate them for your users. Items inside the viewport that can take focus scroll into view as focus reaches them.
Attributes
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
id
|
string
| — | — | Yes | Unique id (carries the Scroller hook) |
scroll_by
|
integer
| — | — | No | px to scroll per click (default ~80% of the viewport) |
prev_label
|
string
|
Scroll left
| — | No | aria-label for the back button |
next_label
|
string
|
Scroll right
| — | No | aria-label for the forward button |
class
|
any
| — | — | No | Extra classes for the root |
viewport_class
|
any
| — | — | No | Extra classes for the scroll viewport |
control_class
|
any
| — | — | No | Extra classes for the prev/next buttons |
rest
|
global
| — | — | No | — |
Slots
| Name | Required | Description |
|---|---|---|
inner_block
| Yes | The scrollable items (place them in a row) |
Options
Each option takes one or more of its values, separated by commas.
| Option | Values |
|---|---|
--type
|
scroller
|
--module
| A module name of your own |
What it generates
mix mishka.ui.gen.headless scroller