Pressable Feedback
FreeGive anything pressable, such as a tile, card or row, a small scale-down while it is held.
npx wunderui-cli add pressable-feedbackPlayground
Pressed 0 times
Installation
npx wunderui-cli add pressable-feedbackWrites the source into your project with its dependencies and, on first use, the styles - see Installation.
Then import what you need:
import { PressableFeedback } from "@/components/wunderui/pressable-feedback"Then use it:
import { PressableFeedback } from "@/components/ui/pressable-feedback"
export function QuickAction() {
return (
<PressableFeedback
onPress={() => console.log("opened")}
className="rounded-xl border border-border bg-card p-4 text-sm font-medium text-foreground hover:bg-bg-page"
>
New invoice
</PressableFeedback>
)
}Expected result: You should see a bordered tile that says New invoice. Hold the mouse button on it and it shrinks a little; release and it springs back and logs opened.
When to use
Use Pressable Feedback for
- Tiles, cards and rows that people press, such as quick actions or a template picker
- A link or a button of your own that should react to a press the way the library buttons do
- Touch layouts, where a press needs to be seen at once under the finger
Use something else for
- Button for a normal action; it already reacts to a press
- Icon Button for an action that is only an icon
- Card for a surface that holds content, with an interactive mode for whole-card links
Wrapping
On its own it renders a button around its content. Used as a wrapper it lends the effect to the single child you pass, so a Button or link is never wrapped in a second button.
State
While the mouse button is down, or Space is held on the focused element, the content scales to 95 % at 90 % opacity and springs back on release. Hover changes nothing.
Keyboard interactions
Without asChild it is a native button, so the browser provides focus and activation. With asChild the keys are those of the child.
- TaborShift+Tab
- Moves focus to the pressable and away from it. The focus ring shows while it is focused.
- Enter
- Activates a button or a link and calls . Enter does not hold the pressed look; only the click runs.
- Space
- Holds the pressed look while the key is down on a button, and activates it on release.
Behavior and motion
What the pressable does while it is held, with a mouse, a finger or a key, and how it relates to its child.
- Pressed
- Pressing the mouse button sets the pressed look, 95 % scale at 90 % opacity, and releasing or leaving the element returns it. A finger and the Space key get the same look.
- Own button
- Alone it renders a button around its children and calls the press handler on click. It takes no other attributes, so it cannot be disabled or labelled: its content names it.
- asChild
- With asChild and one element as child, the effect goes onto that child: class names merge and its own handlers still run. A non-element child falls back to the own button.
- Hover
- There is no hover look of its own. Add one to the content.
- Focus
- The focus ring is the standard one: an indigo border with a 2 px ring, shown for keyboard focus.
- Motion
- The scale animates with the fast duration and the move easing, so a press answers at once and springs back softly.
- Reduced motion
- With reduced motion the transition is removed. The scale and opacity still apply instantly, so a press is seen without anything moving.
Anatomy
The figure marks a tile. PressableFeedback is a single part; the tile around it and the icon inside are your own markup.
- 1
Scales its content to 95 % at 90 % opacity while pressed. Alone it renders a button, with asChild it lends the effect to its single child, and it adds a focus ring only.
- 2
What you pass as children: a label, an icon with a label, a card body. It scales together with the button.
Best practices
- Do
Use it to give press feedback to something that is not a button yet, such as a tile, card or row. Buttons and icon buttons already react to a press.
- Do
Pass asChild when the child is already a button or a link. Without it you nest a button inside a button, which is invalid HTML.
- Do
Handle the action with the press handler. With asChild the child's own click handler runs first, then the press handler.
- Do
Give the pressable its own look: a border, a fill and a hover tone. The component only adds the scale, the opacity and the focus ring.
- Don’t
Don't put links or other buttons inside it without asChild. They would sit inside a button, and nested interactive elements break.
- Don’t
Don't use it for a disabled state or a name that is not in the content. Its own button takes neither; use asChild and put them on the child.
- Don’t
Don't use it on a large surface, such as a whole panel. A 5 % scale of a wide element moves its edges visibly.
API reference
One table for the one part. PressableFeedback wraps no primitive and passes no other props on, so the table lists every prop.
Scales its content to 95 % at 90 % opacity while pressed. Alone it renders a button, with asChild it lends the effect to its single child, and it adds a focus ring only.
| Prop | Type | Default | Description |
|---|---|---|---|
| children required | ReactNode | — | The content to scale. With it must be a single element, which receives the effect. |
| onPress | () => void | — | Called when the pressable is activated, from the click. With it runs after the child's own . |
| asChild | boolean | false | Apply the press effect to the child element instead of wrapping it. |
| className | string | — | Extra classes for the button, or merged into the child with . This is where the look goes: border, fill, padding and hover. |
Notes for AI
Give your coding assistant the Markdown reference instead of screenshots.
get_component("pressable-feedback")npx wunderui-cli add pressable-feedbackThe full library index for assistants is at /llms.txt.