Slider
Numeric range controls — a draggable track (single or two-thumb range, with discrete pips and scrubber variants), an angle dial, an exposure ticker, a media scrubber, or a springy elastic slider that stretches past its bounds.
Preview
<x-ui.angle-slider :value="45" name="angle" />
Installation
php artisan ui:add angle-slider
Note
This component ships an Alpine behavior module at
resources/js/ui/angle-slider.js. Import it once from your bundle so it registers on alpine:init:
import './angle-slider.js';
Registry contract
php artisan ui:add angle-slider
writes only the files below. The CLI validates each file hash before writing and asks before it replaces a local change, unless you pass --force.
-
resources/views/components/ui/angle-slider.blade.php -
resources/js/ui/angle-slider.js
- Registry dependencies
- None — installs on its own.
- Packages
-
composer: jml/brok:^0.2npm: alpinejs
Use with AI
A brief for your coding agent: install command, usage, props, guidance and the rules. Copy it, or open a prompt about this component in an assistant.
# Brok UI: Angle Slider (`angle-slider`)
A circular dial control for selecting an angle value between 0° and 360°.
Brok UI is a Laravel Blade component registry. Installed components are plain Blade files the app owns.
## Install
```bash
php artisan ui:add angle-slider
```
## Usage
```blade
<x-ui.angle-slider :value="45" name="angle" />
```
## Props
- `value` (int, default `0`) — Current angle.
- `min` (int, default `0`) — Minimum angle.
- `max` (int, default `360`) — Maximum angle.
- `step` (int, default `1`) — Degrees per keyboard step.
- `size` (int, default `160`) — Diameter of the dial, in pixels.
- `name` (mixed|null, default `null`) — Renders a hidden input with this name for form posts.
## Use when
- Use when continuous adjustment or immediate visual feedback helps users choose a value.
- Selecting a rotational value such as a compass heading, hue angle or gradient direction.
- Wanting a dial-style control instead of a linear track.
## Avoid when
- Do not use for precise values or broad ranges without good landmarks; direct entry is better when accuracy matters.
- Selecting a plain linear numeric value; use slider instead.
## Anti-patterns
- Using sliders for precise or unbounded values
## Rules
- Use the `<brok:angle-slider>` tag (or `<x-ui.angle-slider>`) in Blade; do not rewrite the component.
- Prefer the documented props and variants over utility-class overrides; when a utility must win, use the `!` important modifier.
- Use semantic design tokens (`bg-primary`, `text-muted-foreground`), never raw colour utilities.
- Keep the `data-slot` attributes; they are the styling and test hooks.
## Links
- Docs: https://brokui.dev/docs/components/angle-slider
- Registry JSON (files, props, contract): https://brokui.dev/r/open/angle-slider.json
Working in Claude Code, Cursor or Codex? Give the agent the whole registry through the MCP server or the Brok UI skill.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | int | 0 | Current angle. |
| min | int | 0 | Minimum angle. |
| max | int | 360 | Maximum angle. |
| step | int | 1 | Degrees per keyboard step. |
| size | int | 160 | Diameter of the dial, in pixels. |
| name | mixed | null | null | Renders a hidden input with this name for form posts. |
Slots
default— Not used by this component; present for attribute-bag compatibility.
Data slots
Stable hooks for CSS overrides and browser tests.
Behavior
- Dragging the ring, or pressing arrow keys on the focused thumb, sweeps the value from min to max around the circle; the sweep arc and central readout update live.
- Installs a JavaScript behavior module when the registry item includes resources/js/ui files.
- Declares registry capability flags: a11y, interactive, responsive, rtl, darkMode, localized.
Guidance
Adjust an intuitive continuous value.
Use when
- Use when continuous adjustment or immediate visual feedback helps users choose a value.
- Selecting a rotational value such as a compass heading, hue angle or gradient direction.
- Wanting a dial-style control instead of a linear track.
Avoid when
- Do not use for precise values or broad ranges without good landmarks; direct entry is better when accuracy matters.
- Selecting a plain linear numeric value; use slider instead.
Use instead
- Number field for precise entry
- Select for discrete values
Anti-patterns
- Using sliders for precise or unbounded values
- Anatomy
- Theming hooks
Accessibility
- Keyboard
- ArrowUp ArrowDown ArrowLeft ArrowRight Home End
- Focus
managed
- The thumb is a role="slider" with aria-valuemin/max/now and an aria-valuetext showing the degree symbol, and is fully keyboard-operable via onKey.
- Semantic HTML and a stable
data-slotattribute for styling and scripting hooks. - Focus-visible rings use the
ringtoken, so keyboard focus is always visible. - Disabled and invalid states are conveyed to assistive tech, not by color alone.
- Targets WCAG 2.2 AA; verify contrast in light, dark, admin and customer surfaces in the preview.
- Labels go through
__()and layout uses logical properties (ms-*,text-start), so it mirrors underdir="rtl"— flip the preview to RTL to confirm. - Dark mode uses the same semantic tokens under the
darkclass; high contrast follows forced-color system tokens.
Livewire
Add a stable wire:key when Livewire can reorder this interactive component.
<div wire:key="angle-slider-{{ $record->id }}">
<x-ui.angle-slider :value="45" name="angle" />
</div>
Validation
Validation support: native. Keep the error message connected with aria-describedby.
<form wire:submit="save" class="space-y-2">
<brok:angle-slider
wire:model="value"
:aria-invalid="$errors->has('value') ? 'true' : 'false'"
aria-describedby="value-error"
/>
@error('value')
<p id="value-error" role="alert">{{ $message }}</p>
@enderror
<brok:button type="submit" wire:loading.attr="disabled">
<span wire:loading.remove>Save</span>
<span wire:loading>Saving…</span>
</brok:button>
</form>
Source
The exact, editable files ui:add writes
into your app. Previews render this same code; there are no preview-only components.
@props([
'value' => 0,
'min' => 0,
'max' => 360,
'step' => 1,
'size' => 160,
'name' => null,
])
<div
x-data="uiAngleSlider({ value: @js((float) $value), min: @js((float) $min), max: @js((float) $max), step: @js((float) $step) })"
{{-- Modelable: `x-model` (Alpine) and `wire:model` (Livewire binds through
the same x-model contract) attach to the root. Inert without either. --}}
x-modelable="value"
data-slot="angle-slider"
@pointerdown="startDrag($event)"
style="width: {{ (int) $size }}px; height: {{ (int) $size }}px;"
{{ $attributes->merge(['class' => 'relative inline-flex cursor-pointer touch-none select-none items-center justify-center rounded-full']) }}
>
{{-- Track ring, sweep arc from 0° (top, clockwise) to the value, and quarter ticks --}}
<svg data-slot="angle-slider-track" class="absolute inset-0 size-full" viewBox="0 0 100 100" aria-hidden="true">
<circle cx="50" cy="50" r="45" fill="none" class="stroke-muted" stroke-width="6" />
<circle
cx="50" cy="50" r="45" fill="none"
class="stroke-primary transition-[stroke-dashoffset] motion-reduce:transition-none"
stroke-width="6" stroke-linecap="round" pathLength="360"
stroke-dasharray="360"
:stroke-dashoffset="360 - value"
:style="dragging ? 'transition: none' : ''"
transform="rotate(-90 50 50)"
/>
@foreach ([0, 90, 180, 270] as $tick)
<line x1="50" y1="1" x2="50" y2="4" class="stroke-muted-foreground/60" stroke-width="1.5" stroke-linecap="round" transform="rotate({{ $tick }} 50 50)" />
@endforeach
</svg>
{{-- Draggable grip on the ring --}}
<span
data-slot="angle-slider-thumb"
role="slider"
tabindex="0"
aria-label="{{ __('Angle') }}"
aria-orientation="horizontal"
aria-valuemin="{{ $min }}"
aria-valuemax="{{ $max }}"
:aria-valuenow="value"
:aria-valuetext="`${value}°`"
@keydown="onKey($event)"
class="absolute top-0 left-0 size-5 rounded-full border-2 border-background bg-primary shadow-md ring-1 ring-border transition-transform focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background motion-reduce:transition-none"
:style="`transform: translate(${thumbLeft}px, ${thumbTop}px);${dragging ? ' transition: none;' : ''}`"
></span>
{{-- Central readout --}}
<span
data-slot="angle-slider-readout"
class="pointer-events-none flex select-none flex-col items-center leading-none"
aria-hidden="true"
>
<span class="text-lg font-semibold tabular-nums text-foreground" x-text="`${value}°`"></span>
</span>
@if ($name)
<input type="hidden" name="{{ $name }}" :value="value" />
@endif
</div>
/**
* Angle Slider behavior — a circular dial that selects an angle value (0–360°).
*
* The thumb is absolutely positioned on the circumference of the circular track
* using trigonometry derived from the current `value` (in degrees). Pointer drag
* calculates the new angle via `atan2` from the element centre. Keyboard input
* supports Arrow keys (±step), Home (min) and End (max). The `radius` reactive
* property is computed at init time from the element's rendered size so that it
* works with any `size` prop without needing a hard-coded constant.
*
* Self-registers on `alpine:init` so import order does not matter — import this
* file once from your bundle (e.g. resources/js/ui/index.js).
*/
document.addEventListener('alpine:init', () => {
window.Alpine.data('uiAngleSlider', (config = {}) => ({
value: config.value ?? 0,
min: config.min ?? 0,
max: config.max ?? 360,
step: config.step ?? 1,
/** Half the element's rendered width/height — set in init(). */
radius: 60,
/** True while a pointer drag owns the dial (kills transitions inline). */
dragging: false,
// Bound listener refs so we can remove exactly what we added.
_move: null,
_up: null,
/** Thumb position (top-left corner in px) on the ring, which sits at 90% of the radius; the thumb is 20px. */
get ringRadius() {
return this.radius * 0.9;
},
get thumbTop() {
const rad = ((this.value - 90) * Math.PI) / 180;
return this.radius + this.ringRadius * Math.sin(rad) - 10;
},
get thumbLeft() {
const rad = ((this.value - 90) * Math.PI) / 180;
return this.radius + this.ringRadius * Math.cos(rad) - 10;
},
init() {
// Derive radius from the rendered element dimensions.
this.$nextTick(() => {
const r = this.$el.getBoundingClientRect();
if (r.width > 0) {
this.radius = r.width / 2;
}
});
this.value = this.clamp(this.value);
},
destroy() {
// Remove any listeners still attached if unmounted mid-drag.
window.removeEventListener('pointermove', this._move);
window.removeEventListener('pointerup', this._up);
},
clamp(v) {
v = Math.round(v / this.step) * this.step;
return Math.min(this.max, Math.max(this.min, v));
},
/**
* Compute the angle (in degrees, 0 = top, clockwise) from the centre of
* the element to the pointer position.
*/
angleFromPointer(clientX, clientY) {
const r = this.$el.getBoundingClientRect();
const cx = r.left + r.width / 2;
const cy = r.top + r.height / 2;
const dx = clientX - cx;
const dy = clientY - cy;
// atan2 returns angle from positive-x axis; we want 0 = top (negative-y).
let deg = (Math.atan2(dx, -dy) * 180) / Math.PI;
if (deg < 0) deg += 360;
return this.clamp(deg);
},
startDrag(e) {
e.preventDefault();
this.dragging = true;
this.value = this.angleFromPointer(e.clientX, e.clientY);
// Bind once so the same refs can be removed later (here or in destroy()).
this._move = (ev) => {
this.value = this.angleFromPointer(ev.clientX, ev.clientY);
};
this._up = () => {
this.dragging = false;
window.removeEventListener('pointermove', this._move);
window.removeEventListener('pointerup', this._up);
};
window.addEventListener('pointermove', this._move);
window.addEventListener('pointerup', this._up);
},
onKey(e) {
switch (e.key) {
case 'ArrowLeft':
case 'ArrowDown':
e.preventDefault();
this.value = this.clamp(this.value - this.step);
break;
case 'ArrowRight':
case 'ArrowUp':
e.preventDefault();
this.value = this.clamp(this.value + this.step);
break;
case 'Home':
e.preventDefault();
this.value = this.min;
break;
case 'End':
e.preventDefault();
this.value = this.max;
break;
}
},
}));
});
Ownership & lifecycle
Owner, release state, review evidence and adoption for this item.
- Owner
- Platform UI (@JoshJML)
- Current version
-
1.3.1 - Status
- Stable
- License
-
open - Accessibility reviewed
- No review date recorded
- Last breaking change
- No date recorded
- Deprecation
- Not deprecated
- Contract
-
v6 - Foundation
-
≥ 1.0.0