npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-keyboard-avoiding-container

v0.0.4

Published

A React component that provides smooth keyboard interactions for mobile web apps, handling viewport adjustments, scroll behavior, and input field focus with a sticky footer layout

Readme

React Keyboard Avoiding Container

A React component for web applications that handles mobile keyboard interactions gracefully, ensuring proper viewport adjustments and scroll behavior when the keyboard appears. Works fluently across modern browsers and devices.

https://www.npmjs.com/package/react-keyboard-avoiding-container

Features

  • 📱 Automatic keyboard height detection
  • 🔄 Smooth scroll adjustments when keyboard appears
  • 🎯 Auto-scrolls to focused input fields
  • 📍 Maintains viewport stability
  • 🔒 Prevents unwanted scrolling/bouncing
  • 🎨 Clean, responsive layout with sticky footer
  • 💪 TypeScript support
  • ⚛️ Works with React 16.8+

Installation

npm install react-keyboard-avoiding-container
# or
yarn add react-keyboard-avoiding-container

Usage

import { KeyboardAvoidingContainer } from "react-keyboard-avoiding-container";

function LoginForm() {
  const bodyContent = (
    <div>
      <input type="text" placeholder="Username" />
      <input type="password" placeholder="Password" />
    </div>
  );

  const footerContent = <button>Login</button>;

  return (
    <KeyboardAvoidingContainer body={bodyContent} footer={footerContent} />
  );
}

Props

| Prop | Type | Description | | -------- | ----------------- | ---------------------------------------- | | body | React.ReactNode | Main content of the container | | footer | React.ReactNode | Footer content that sticks to the bottom |

Features in Detail

Keyboard Handling

  • Automatically detects keyboard height using visualViewport API
  • Adjusts the viewport height when keyboard appears/disappears
  • Prevents unwanted scrolling and viewport jumps

Focus Management

  • Automatically scrolls to focused input fields
  • Ensures focused elements are visible above the keyboard
  • Smooth scrolling animations for better UX

Layout Control

  • Fixed positioning to prevent page scrolling
  • Sticky footer that remains visible
  • Handles orientation changes gracefully

Browser Support

The component uses the visualViewport API for optimal keyboard handling. For browsers that don't support this API, it falls back to window.innerHeight.

Best Practices

  1. Place all interactive elements (inputs, textareas) in the body prop
  2. Keep action buttons (submit, cancel) in the footer prop
  3. Use within mobile-focused layouts
  4. Ensure parent containers don't interfere with fixed positioning

Example

import React, { useState } from "react";

import { KeyboardAvoidingContainer } from "react-keyboard-avoiding-container";

const LoginPage: React.FC = () => {
  const [username, setUsername] = useState("");
  const [password, setPassword] = useState("");

  const handleLogin = () => {
    console.log("Login attempt:", { username, password });
    alert("Login clicked!");
  };

  const bodyContent = (
    <div>
      <h1 className="text-2xl font-bold mb-6 text-center">Login</h1>
      <div className="flex flex-col space-y-4">
        <div>
          <label
            htmlFor="username"
            className="block text-sm font-medium text-gray-700 mb-1"
          >
            Username
          </label>
          <input
            type="text"
            id="username"
            value={username}
            onChange={(e) => setUsername(e.target.value)}
            className="border rounded-lg w-full p-2"
            placeholder="Enter your username"
          />
        </div>
        <div>
          <label
            htmlFor="password"
            className="block text-sm font-medium text-gray-700 mb-1"
          >
            Password
          </label>
          <input
            type="password"
            id="password"
            value={password}
            onChange={(e) => setPassword(e.target.value)}
            className="border rounded-lg w-full p-2"
            placeholder="Enter your password"
          />
        </div>
      </div>
    </div>
  );

  const footerContent = (
    <button
      onClick={handleLogin}
      className="w-full bg-blue-500 text-white py-2 px-4 rounded-lg hover:bg-blue-600 transition-colors"
    >
      Login
    </button>
  );

  return (
    <KeyboardAvoidingContainer body={bodyContent} footer={footerContent} />
  );
};

export default LoginPage;

Demo:

https://github.com/user-attachments/assets/bced1ff1-1140-4038-ba63-438c9784b9b5

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

ISC

Support

If you have any questions or run into issues, please open an issue on GitHub.