React Input Button
React input button that transforms into input field with smooth transitions. Framer Motion animations and compound patterns with TypeScript and shadcn/ui.
Powered by
Building expandable form interactions?
Join our Discord community for help from other developers.
Input forms are everywhere—newsletter signups, search bars, contact forms. But most are just static fields sitting there waiting. No interaction. No surprise. No delight. Meanwhile, users expect smooth micro-interactions that guide them through the flow. This React component gives you buttons that morph into inputs with perfect timing, spring physics, and accessibility baked in.
Button transforms into input field
Click to see the smooth layout transition from button to input with automatic focus:
Built for React applications with TypeScript and Next.js. Uses compound component pattern for flexible composition. The layout transition uses Framer Motion's layoutId system for seamless morphing between states. Works with any form library—React Hook Form, Formik, or native validation. Perfect accessibility with proper focus management and keyboard navigation.
Why most input forms feel clunky
Developers just throw an input field on the page and call it done. Or they add a basic fade-in that feels disconnected from user intent. The problem? Users need clear affordances about what's interactive and what happens next. A button says "click me." An input field says "type here." This component bridges that gap.
The morphing animation isn't just pretty—it guides user attention. The spring physics feel natural, not robotic. The compound component pattern gives you full control over layout and styling while handling the complex state coordination behind the scenes.
Plus, the TypeScript definitions catch integration mistakes before runtime. Automatic focus management means users can immediately start typing. ARIA attributes ensure screen readers understand the state changes.
Installation
npx shadcn@latest add https://www.shadcn.io/registry/input-button.json
npx shadcn@latest add https://www.shadcn.io/registry/input-button.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/input-button.json
bunx shadcn@latest add https://www.shadcn.io/registry/input-button.json
Features
- Smooth layout transitions using Motion's layoutId for seamless button-to-input morphing
- Compound component pattern with provider, action, submit, and input components
- Loading state handling with built-in pending states and success feedback
- Accessible form integration supporting proper form submission and validation
- TypeScript support with complete interface definitions for all sub-components
- shadcn/ui integration using design tokens and consistent styling patterns
Examples
Loading States
Demonstrates form submission with loading indicators and success states.
Use Cases
This free open source React component works perfectly for:
- Newsletter signups - Email collection with smooth interaction flow built with Next.js
- Search interfaces - Expandable search boxes using TypeScript and Tailwind CSS
- Quick actions - Compact forms that expand on demand for better UX
- CTA buttons - Call-to-action elements that transform into input forms
- Contact forms - Progressive disclosure for complex form interactions
- Survey inputs - Step-by-step question flows with guided transitions
API Reference
InputButtonProvider
Prop | Type | Default | Description |
---|---|---|---|
showInput | boolean | false | Controls input visibility state |
setShowInput | function | - | State setter for input visibility |
transition | Transition | { type: 'spring', stiffness: 300, damping: 20 } | Motion transition configuration |
id | string | useId() | Unique identifier for layout animations |
InputButtonAction
Prop | Type | Default | Description |
---|---|---|---|
onClick | function | - | Click handler for button action |
children | ReactNode | required | Button text content |
InputButtonSubmit
Prop | Type | Default | Description |
---|---|---|---|
icon | React.ElementType | ArrowRight | Icon component for collapsed state |
children | ReactNode | - | Submit button text content |
disabled | boolean | false | Disables the submit button |
InputButtonInput
Prop | Type | Default | Description |
---|---|---|---|
type | string | "text" | HTML input type attribute |
placeholder | string | - | Input placeholder text |
value | string | - | Controlled input value |
onChange | function | - | Input change handler |
Common gotchas
Layout shift prevention: The component uses layoutId for smooth transitions, but parent containers with changing widths can cause jumpy animations. Wrap in a container with fixed or min-width for best results.
Focus timing issues: The input receives focus automatically when it appears, but if you're conditionally rendering the entire component, focus might not work. Ensure the component stays mounted and only the input visibility changes.
Form validation conflicts: If using React Hook Form or similar, register the input field properly and handle the showInput state separately from form validation state. Don't tie validation errors directly to the visibility toggle.
Mobile keyboard behavior: On mobile, the keyboard appearing can shift the layout. Consider using viewport height units (vh) carefully or add handling for keyboard presence on touch devices.
Double submission prevention: The action button and submit button can both trigger form submission. Use the compound pattern correctly—action shows input, submit handles the actual form submission.
Animation performance: The layout animation creates reflow on every frame. On lower-end devices with many input buttons, consider reducing animation duration or using transform-based animations instead.
You might also like
Explore other interactive button components for React applications:
Copy Button
One-click clipboard copying with visual feedback
Icon Button
Animated icon buttons with particle burst effects
Flip Button
3D flip animations with smooth physics transitions
GitHub Stars Button
Display repository stars with animated counting
Questions developers actually ask
React Icon Button
React icon button with particle burst and glow effects on activation. Lucide icons with smooth animations, TypeScript support, and shadcn/ui styling.
React Liquid Button
React liquid button with fluid fill animations and gradient effects. Multiple color variants and smooth hover transitions with TypeScript and shadcn/ui styling.