Skip to content

Slide to Unlock

The iPhone OS 1 lock-screen slider: a 280x47 inset glass well, a glossy 82x43 arrow knob that follows the pointer 1:1 and springs back, and a shimmering label. A keyboard-operable role="slider" that unlocks on Enter, Space or End.

Installation

Requires the theme. Register the @skeuomorph namespace and add @skeuomorph/skeuomorph first, as shown in the installation guide. The CLI also pulls it in as a dependency.

pnpm dlx shadcn@latest add @skeuomorph/slide-to-unlock

Without the namespace, install straight from the URL:

pnpm dlx shadcn@latest add https://ui-skeuomorph.vercel.app/r/slide-to-unlock.json

Usage

import { SlideToUnlock } from "@/components/ui/slide-to-unlock"
<SlideToUnlock onUnlock={() => router.push("/home")} />

The track is a translucent black well, so it belongs on a dark surface such as linen (material-linen) or an iOS glass tray.

Behaviour

  • Drag. The knob follows the pointer 1:1 using pointer capture. Release it past 90% of the track to unlock. Anything less springs back over 280ms with ease-out-quart.
  • Tap. Tapping the knob without dragging runs it across and unlocks. This is the single-pointer alternative to the drag that WCAG 2.5.1 asks for.
  • Keyboard. The knob is a focusable role="slider" (aria-valuemin 0, aria-valuemax 100, aria-valuetext "Locked" or "Unlocked"). Enter, Space or End unlocks. The arrow keys move it in 10% steps and Home sends it back. A half-slid knob springs home when focus leaves.
  • Shimmer. The label's bright band sweeps for 2.0s and rests for 0.6s. It pauses offscreen, in background tabs and while dragging. Under prefers-reduced-motion the shimmer and the spring are off, and the label is static.
  • RTL. Under dir="rtl" the travel, the arrow and the shimmer direction flip.

Locking again

Once unlocked, the slider stays unlocked. To lock it again, render it with a new key:

const [generation, setGeneration] = React.useState(0)
 
<SlideToUnlock key={generation} onUnlock={openHome} />
<Button variant="secondary" onClick={() => setGeneration((n) => n + 1)}>
  Lock
</Button>

API

PropTypeDefaultDescription
onUnlock() => void-Called once when the knob reaches the end of the track.
labelstring"slide to unlock"The shimmering hint. Also the slider's accessible name.
disabledbooleanfalseRemoves the knob from the tab order and stops the shimmer.
classNamestring-Merged onto the track. Set a width here, e.g. w-full.

Every other div prop is passed to the track. Parts carry data-slot="slide-to-unlock", "unlock-label" and "unlock-knob", and the track has data-state="locked" | "unlocked".