Join our Discord Community

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.

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:

Loading component...

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

Loading component...

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

PropTypeDefaultDescription
showInputbooleanfalseControls input visibility state
setShowInputfunction-State setter for input visibility
transitionTransition{ type: 'spring', stiffness: 300, damping: 20 }Motion transition configuration
idstringuseId()Unique identifier for layout animations

InputButtonAction

PropTypeDefaultDescription
onClickfunction-Click handler for button action
childrenReactNoderequiredButton text content

InputButtonSubmit

PropTypeDefaultDescription
iconReact.ElementTypeArrowRightIcon component for collapsed state
childrenReactNode-Submit button text content
disabledbooleanfalseDisables the submit button

InputButtonInput

PropTypeDefaultDescription
typestring"text"HTML input type attribute
placeholderstring-Input placeholder text
valuestring-Controlled input value
onChangefunction-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:

Questions developers actually ask