shadcn.io is not affiliated with official shadcn/ui
Drag Handle Responsive Comparator Features Block for React
A responsive-width resizer for a preview tool: drag the edge of a small shop page, or pick Phone, Tablet or Desktop, and the page reflows at its real breakpoints while a badge names the width.
Installation
Overview
A responsive comparator feature section for React with Base UI, written for Reflowr, a fictional responsive-preview tool. A compact header holds three width presets, Phone, Tablet and Desktop, in a segmented control. Under it, a stage in a hairline frame with + marks on its corners shows a small shop page drawn in greyscale, exactly as wide as you set it: drag the handle on its end edge, press the arrow keys, or pick a preset, and the page reflows. Below 640 pixels the navigation collapses to a menu and the layout stacks; between 640 and 1024 the product grid has three columns; from 1024 up it has four. A badge in the stage's toolbar names the breakpoint and the width ("Tablet · 768 px"), and a ruler along the top marks the three presets. The handle is a native range input laid invisibly over the stage, so pointer, touch and keyboard all work and a screen reader announces "Tablet, 768 pixels". It's built from Segment Group, Badge and Guides with your theme's tokens, there is no call to action, and nothing is in your primary colour. For design tools, site builders and any product that previews pages at different sizes.
FAQ
How does the drag handle work?
A native input type="range" covers the part of the stage where the page's edge can be, and the page's width is the range's value. Because the input is the control, you get mouse and touch dragging, arrow keys, Page Up and Page Down, Home and End, and a screen-reader name and value without any pointer code. The line and grip you see are drawn from the same value. The range runs from 320 to 1280 pixels in steps of 10.
How do I change the breakpoints and the page?
layoutOf holds the two breakpoints (640 and 1024) and returns phone, tablet or desktop. The page, ShopPage, sets a data-layout attribute and reads it with group variants (group-data-[layout=phone]/page:hidden), so a block of classes can say what changes at each width. Replace its contents with a drawing of your own product and keep the same attribute.
Why are there presets, and what happens on a phone?
The presets are the quick path and the keyboard-friendly one: a click sets the width exactly. On a phone the stage is too narrow to drag in, so the handle and its range input are hidden below sm and the presets are the control, each a single tap. The page still reflows, and the stage keeps its height.
How do screen readers and keyboards handle it?
The segmented control is named "Preview width", and so is the range, which reads out its breakpoint and width in words. The page itself is decoration: it is aria-hidden and inert, so none of its text is read and none of its links take focus. A focus ring appears around the stage when the range has keyboard focus. The stage is drawn left to right in every language, since it is a picture of a page.
Does it follow my theme?
Yes. The page is bg-card, its blocks bg-muted, its one mock button bg-foreground text-background, and the edge handle is the foreground colour, so the section is light on a light page and dark on a dark one, and the Segment Group's selected segment is the only thing that changes with the choice.
Related
- Pro
Before After Toggle Features
Live controlsA Before and After control that cross-fades a settings screen between a cluttered version (warning banners, a nested menu, badges everywhere) and a clean one, in a frame that never changes height.
- Pro
Before After Visual Features
Proof and comparisonsThree measured outcomes as ruled rows, each with its own Before and After control that swaps both the figure and the bar: page weight, load time and weekly support tickets.
- Pro
Full-Width Before After Slider Hero
Interactive demosA showcase hero with centred copy over a wide before and after panel in a hairline frame, with a draggable handle and a band of four results.
- Pro
Alternating Device Frame Rows Features
Alternating rowsTwo alternating rows for a transit app, each pairing a sentence with a phone drawn as a ring on a hairline floor: the trip planner with line chips and the live arrivals with countdowns.
- Pro
Resizable Split Testimonials
Quote gridsA featured quote and two supporting quotes for a checkout platform in a resizable split inside a framed figure: drag the divider, or focus it and use the arrow keys, to give either side more room, with a Shine Button in the header row.
- Pro
Vertical Slider Board Features
Live controlsA board of six vertical sliders for an alert-tuning tool, each with a level meter and a readout, and a composite readout of pages a week and incidents caught worked out from the six settings.