hamburger-react provides a collection of animated hamburger menu icons specifically designed for React applications. It focuses on performance and elegance, utilizing CSS-driven transitions on 'cheap' properties to avoid jerky animations, differentiating itself from libraries that use JavaScript for animations or transition expensive CSS properties. The current stable version is 2.5.2, with releases occurring periodically to support new React versions and add minor features or accessibility improvements. Key differentiators include its small bundle size (~1.5 KB min+gzip per hamburger), hooks-based implementation (requiring React 16.8.0+), robust accessibility features (ARIA labels, keyboard interaction, recommended tap area), and a focused API that avoids over-customization while providing sensible defaults. It supports React 16.8 through 19 via peer dependencies.
npm install hamburger-reactVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic setup of the Hamburger component, integrating it with React's `useState` hook for toggling, and showcasing various common props for customization and accessibility.
If the previous default color is desired, explicitly set the `color` prop on the `Hamburger` component (e.g., `<Hamburger color="#000" />`) or ensure its parent element has the desired text color.
Ensure that any custom keyboard event handlers or accessibility integrations rely on `KeyboardEvent.key` for cross-browser compatibility and modern standards. This change primarily affects internal library handling, but developers integrating deeply with keyboard events should be aware.
Upgrade your project's React version to `^16.8 || ^17 || ^18 || ^19` as specified in the peer dependencies. Ensure all other React-related packages are compatible with the updated React version.
Account for the default padding when calculating spacing or positioning. If custom styling is applied that interferes with this, ensure the resulting interactive area still meets accessibility guidelines.
Update your `react` and `react-dom` packages to version 16.8.0 or higher. For example, `npm install react@latest react-dom@latest`.
Change `import { Hamburger } from 'hamburger-react'` to `import Hamburger from 'hamburger-react'`.