Skip to content
HyperUX Experimental
Demo

Drag-to-resize container with keyboard nudge controls and breakpoint awareness.

Current breakpoint:

px

Focus the drag handle and use arrow keys to resize by keyboard.


Alpine.js Resizable Container

huxResizable controls a container width with pointer and keyboard interactions, tracks the currently matched breakpoint, and can clamp width to min/max or parent bounds.

API

huxResizable(config)

Returns an Alpine data object with:

Internal helper methods are private implementation details and are not part of the supported API contract.

Options

Quick Start

<div x-data="huxResizable({ iframeSrc: '/examples/preview.html', stopAtLastBreakpoint: true })">
  <div
    x-ref="resizableContainer"
    x-bind:style="`width: ${currentWidth}px; min-width: ${minWidth}px;`"
  >
    <iframe x-ref="iframeEl" x-bind:src="iframeSrc" title="Preview"></iframe>

    <button
      type="button"
      aria-label="Drag to resize"
      x-on:mousedown="startDrag($event)"
      x-on:touchstart.prevent="startDrag($event)"
      x-on:keydown.right.prevent="nudgeWidth(8)"
      x-on:keydown.left.prevent="nudgeWidth(-8)"
      x-on:keydown.up.prevent="jumpToBreakpoint('next')"
      x-on:keydown.down.prevent="jumpToBreakpoint('prev')"
    ></button>
  </div>
</div>

Common Usage Patterns

Clamp to Parent Width

huxResizable({
  preventOverflow: true,
})

Cap at Largest Breakpoint

huxResizable({
  stopAtLastBreakpoint: true,
})

Custom Breakpoints

huxResizable({
  breakpointItems: [
    { label: 'mobile', minWidth: 360 },
    { label: 'tablet', minWidth: 768 },
    { label: 'desktop', minWidth: 1200 },
  ],
})

Dynamic iframe Source

Pass iframeSrc to load a specific URL into the preview iframe. This allows multiple resizable containers on the same page to each load different content without duplicating markup.

huxResizable({
  iframeSrc: '/preview/my-component',
})

When iframeSrc is null (the default), the iframe renders without a src attribute and displays a blank page.

Behavior Contract

Error Handling

Accessibility Notes

Notes