Component
KeyboardAvoidingView
KeyboardAvoidingView handles application layouts outside Base UI drawers by exposing stable viewport and keyboard CSS variables.
Preview
Installation
pnpm dlx shadcn@latest add https://pwaui.com/r/keyboard-avoiding-view.jsonUsage
import { KeyboardAvoidingView } from "@/components/ui/keyboard-avoiding-view"
export function Composer() { return ( <KeyboardAvoidingView behavior="padding" keyboardOffset={8}> <textarea aria-label="Message" /> <button>Send</button> </KeyboardAvoidingView> )}Anatomy
KeyboardAvoidingViewuseVisualViewportBehavior notes
- Behaviors: padding, height, and position.
- Exposes --pwa-keyboard-height and --pwa-visual-viewport-height.
- Inside BottomSheet, prefer Base UI's dedicated keyboard provider.
Platform limitations
- Keyboard avoidance depends on the Visual Viewport API and the page's
interactive-widgetpolicy. With Android'soverlays-contentthe viewport does not resize, so--pwa-keyboard-heightstays 0 and this view does not move. Useresizes-contentorresizes-visualif you depend on it. See Platform limitations. - On iOS Safari the OS also auto-scrolls the focused field, which can compound with
behavior="position". Test thepaddingandheightbehaviors on a real device.
Accessibility
The component is layout-only. Preserve normal focus order and label all form controls inside it.