---
title: "Lock Toggle"
description: "A padlock whose shackle drops home with a knock as the body fills solid and the key turns, then pops up and swings open on unlock."
category: "Micro Interactions"
publishedAt: "2026-11-16"
updatedAt: "2026-11-25"
documentation: "https://beui.dev/micro-interactions/lock-toggle"
markdown: "https://beui.dev/micro-interactions/lock-toggle.md"
license: "MIT"
---

# Lock Toggle

> A padlock whose shackle drops home with a knock as the body fills solid and the key turns, then pops up and swings open on unlock.

## Install

```bash
npx shadcn@latest add @beui/lock-toggle
```

## Dependencies

- `clsx`
- `motion`
- `react`
- `tailwind-merge`

## Usage

```tsx
"use client";

import { LockToggle } from "@/components/motion/lock-toggle";

export function LockToggleUsage() {
  return <LockToggle />;
}
```

## API Reference

### LockToggle

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `locked` | `boolean` | — | No | Whether the padlock is locked, for controlled use. |
| `defaultLocked` | `boolean` | `true` | No | Whether it starts locked when uncontrolled. Default: true |
| `onLockedChange` | `((locked: boolean) => void)` | — | No | Called with the next state when the padlock is toggled. |
| `showLabel` | `boolean` | `true` | No | Show Locked / Unlocked next to the padlock. |
| `labels` | `Partial<{ lock: string; locked: string; unlocked: string; }>` | — | No | Override any built-in string, e.g. for translation. |
| `sound` | `boolean` | `false` | No | Play a low press on lock and a light tap on unlock. Off by default; a `SoundProvider` can mute it app-wide. |
| `className` | `string` | — | No | Classes merged onto the root element. |

## About Lock Toggle

Lock Toggle is a React padlock toggle built with Framer Motion. Locking swings the shackle back over the body and drops it in, a touch past home, so the body knocks as it seats. The body then fills solid around a cut-out keyhole and the key turns a quarter and back. Unlocking turns the key back, drains the fill, and pops the shackle up and open on its right leg, while the label morphs between Locked and Unlocked with Text Morph.

### When to use it

- A document, field or layer can be locked against edits.
- A privacy setting makes something public or private.
- A canvas or design tool locks an object in place.

### Accessibility

It renders a real button named Lock with aria-pressed showing the state, while the visible word changes. With reduced motion the shackle changes position without moving, the key does not turn, and only the fill fades.

### FAQ

**Can I hide the label?**

Yes. Set showLabel to false for a round icon-only toggle.

**Is it locked by default?**

Yes. Pass defaultLocked={false} to start unlocked, or control it with locked and onLockedChange.

## Source

- Registry detail: https://beui.dev/r/lock-toggle
- Raw source: https://beui.dev/r/lock-toggle/raw
- GitHub: https://github.com/starc007/ui-components
