This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Always use yarn instead of npm for all commands in this repository (yarn@4.9.2).
yarn install- Install dependencies (run from project root)yarn start- Start the docs-site development server at http://localhost:5173yarn build- Full production build (JS + CSS in all formats)yarn build-dev- Development build with file watching
yarn test- Run the full test suite (Jest with ts-jest)yarn test src/test/calendar_test.test.tsx- Run a single test fileyarn test:watch- Run tests in watch modeyarn test:ci- Run tests with coverage for CIyarn lint- Run both ESLint and Stylelintyarn eslint- Run ESLint on src directoryyarn sass-lint- Run Stylelint on SCSS filesyarn type-check- Run TypeScript type checking without emitting filesyarn prettier- Format all JS/JSX/TS/TSX filesyarn prettier:check- Check formatting without making changes
yarn build:src- Build JS using Rollupyarn js:dev- Build JS in watch modeyarn css:prod- Build minified production CSSyarn css:dev- Build expanded development CSSyarn css:modules:prod- Build CSS modules (minified)yarn css:modules:dev- Build CSS modules (expanded)
The main entry point is src/index.tsx which exports the DatePicker component. The component hierarchy flows as follows:
DatePicker (index.tsx) - Main component, class-based
├── PopperComponent (popper_component.tsx) - Positioned calendar container
│ ├── withFloating HOC (with_floating.tsx) - Floating UI integration
│ ├── Portal (portal.tsx) - Optional portal rendering
│ └── TabLoop (tab_loop.tsx) - Keyboard navigation wrapper
│ └── Calendar (calendar.tsx) - Core calendar logic
│ ├── ClickOutsideWrapper - Handles outside clicks
│ ├── Month/Year/Time components - Date selection UI
│ └── Various dropdowns for date navigation
Positioning System: The datepicker uses @floating-ui/react (v0.27.15) for positioning the calendar relative to the input. The withFloating HOC wraps PopperComponent to provide positioning logic.
Date Utilities: All date manipulation goes through date_utils.ts, which wraps date-fns (v4.1.0). This provides a consistent API across the codebase and makes it easier to maintain date-related logic.
State Management: The main DatePicker component is class-based and manages state internally. Most child components are controlled components that receive props and callbacks.
Styling: SCSS source files live in src/stylesheets/. The build process generates multiple CSS outputs:
- Regular CSS:
react-datepicker.css(dev) andreact-datepicker.min.css(prod) - CSS Modules:
react-datepicker-cssmodules.cssandreact-datepicker.module.css
Rollup (configured in rollup.config.mjs) generates multiple bundle formats in the dist/ directory:
- UMD:
react-datepicker.jsandreact-datepicker.min.js(browser) - CommonJS:
index.js(Node/bundlers) - ES Modules:
index.es.js(modern bundlers) - Types:
index.d.ts(TypeScript definitions)
Tests use Jest with @testing-library/react and are located in src/test/. The test setup:
- Configuration:
jest.config.js - Setup file:
src/test/index.ts - Helper components:
src/test/helper_components/ - Coverage is collected and reported to Codecov
Important for tests: Some components use ShadowDOM for testing. The shadow_root.tsx helper uses flushSync to ensure synchronous updates required by tests.
The codebase uses @floating-ui/react for positioning. Important: The Floating UI library requires refs and context to be accessed during render, which is by design. When fixing linting errors:
- Use
eslint-disablecomments for Floating UI ref accesses (e.g.,popperProps.refs.setFloating,popperProps.context,arrowRef) - These are not violations of React best practices—they're intentional library usage
- See
popper_component.tsxandwith_floating.tsxfor examples
This codebase uses eslint-plugin-react-hooks v7.0.1+ which has strict rules about:
- Ref access during render: Generally not allowed, but see Floating UI exception above
- setState in effects: Avoid calling setState directly in effects; use
flushSyncwhen synchronous updates are needed - When refs must be updated based on props, do it in
useEffect, not during render
- Install node >=16.0.0 and yarn >=4.6.x
yarn installfrom project rootyarn buildfrom project root (generates dist/ directory)yarn startto launch docs at http://localhost:5173- In a new terminal, run
yarn build-devto auto-rebuild on changes
Note: The docs-site uses a portal: dependency ("react-datepicker": "portal:../") which links to the parent project. Changes to the main package are reflected in the docs when you rebuild.
If you need tighter integration during development:
- Run
yarn linkfrom project root - Run
cd docs-site && yarn link react-datepicker - Then follow steps above
After initial setup, when making changes:
- JS/TS changes: Changes auto-rebuild if
yarn build-devis running - SCSS changes: Run
yarn run css:dev && yarn run css:modules:dev
The repo uses Husky with lint-staged. On commit:
- Prettier formats staged files automatically
- Files are automatically added to the commit (via
git addin lint-staged config)
reactandreact-dom(^16.9.0 || ^17 || ^18 || ^19) - peer dependenciesdate-fns(^4.1.0) - Date manipulation library@floating-ui/react(^0.27.15) - Positioning engineclsx(^2.1.1) - Conditional className utility
- Build: Rollup with Babel and TypeScript plugins
- Testing: Jest, ts-jest, @testing-library/react, jest-axe
- Linting: ESLint 9, TypeScript ESLint, Stylelint
- Formatting: Prettier 3.4.2
- CSS: Sass 1.93.2
When fixing bugs, always follow Test-Driven Development:
- Write the test first - Create a failing test that reproduces the bug
- Confirm it fails - Run the test to verify it captures the broken behavior
- Implement the fix - Make the minimal code change to fix the issue
- Verify the test passes - Run the test again to confirm the fix works
- Run full test suite - Ensure no regressions with
yarn test:ci - Create a branch -
git checkout -b fix/descriptive-branch-name - Commit the fix - Use a descriptive commit message referencing the issue (e.g.,
fix: description of fix\n\nFixes #123) - Push the branch -
git push -u origin fix/descriptive-branch-name - Create a PR - Use
gh pr createwith a clear title and description that references the issue - Return to main -
git checkout mainto prepare for the next task
This ensures every bug fix has regression coverage and documents the expected behavior.
- Prettier handles all code formatting - don't worry about tabs vs spaces
- ESLint enforces coding standards - run
yarn lintbefore committing - TypeScript strict mode - the codebase is fully typed
- Tests are required - add Jest tests for new functionality
- Accessibility matters - maintain ARIA attributes and keyboard navigation