Skip to content

Conversation

@OpenStaxClaude
Copy link
Contributor

Summary

Refactors reactUtils.ts by extracting utilities into focused, single-responsibility modules as proposed in CORE-1452.

Changes Made

Split the monolithic reactUtils.ts (518 lines, 20+ utilities) into four focused modules:

  1. focusUtils.ts (412 lines)

    • Focus management: useDrawFocus, useFocusElement, useFocusHighlight
    • Tab navigation: createTrapTab, useTrapTabNavigation
    • Focus events: useFocusIn, useFocusLost
    • Tab control: useDisableContentTabbing
  2. keyboardUtils.ts (240 lines)

    • Key press detection: useOnKey, onKey
    • Escape key handling: useOnEsc, onEscCallbacks
    • Key combinations: useKeyCombination, keyboardEventMatchesCombination
  3. mediaQueryUtils.ts (120 lines)

    • Media queries: useMatchMediaQuery, useMatchMobileQuery, useMatchMobileMediumQuery
    • Window size: useDebouncedWindowSize
  4. scrollUtils.ts (40 lines)

    • Scroll monitoring: useOnScrollTopOffset

Updated reactUtils.ts

  • Now serves as a barrel export (177 lines, down from 518)
  • Re-exports all utilities from new modules
  • Retains general-purpose utilities: onDOMEventHandler, useOnDOMEvent, useTimeout, isSSR
  • Maintains 100% backward compatibility

SOLID Principles Applied

  • Single Responsibility Principle: Each module has one clear concern

    • focusUtils: Everything related to focus management
    • keyboardUtils: Everything related to keyboard events
    • mediaQueryUtils: Everything related to responsive design
    • scrollUtils: Everything related to scroll events
  • Open/Closed Principle: Easier to extend each module independently

  • Interface Segregation: Focused exports, no forced dependencies

Benefits

  • 66% reduction in main file size (518 → 177 lines)
  • Better discoverability through focused modules
  • Comprehensive JSDoc comments on all functions
  • Each module testable in isolation
  • No breaking changes - all existing imports work

Testing

  • All existing imports from reactUtils continue to work via barrel exports
  • Existing test suite should pass without modifications
  • No API changes

Related Issues

  • CORE-1452: Identify complex code needing refactoring
  • CORE-1454: Refactor reactUtils.ts (this ticket)

🤖 Generated with Claude Code

Split the monolithic reactUtils.ts (518 lines, 20+ utilities) into focused modules following Single Responsibility Principle:

Created modules:
- focusUtils.ts: Focus management, tab trapping, and focus event detection
- keyboardUtils.ts: Keyboard event handling and key combinations
- mediaQueryUtils.ts: Media queries and responsive design hooks
- scrollUtils.ts: Scroll position monitoring

Updated reactUtils.ts:
- Now serves as a barrel export re-exporting from new modules
- Retains general-purpose utilities (DOM events, timeouts, SSR detection)
- Maintains backward compatibility - all existing imports continue to work

Benefits:
- Better code organization by concern
- Easier to find and maintain related utilities
- Comprehensive JSDoc comments added to all functions
- Each module is now testable in isolation
- Reduced file size improves readability

No breaking changes - all existing exports preserved through re-exports.

Related to CORE-1452 and CORE-1454

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@OpenStaxClaude OpenStaxClaude requested a review from a team as a code owner December 23, 2025 13:53
@TomWoodward TomWoodward temporarily deployed to rex-web-core-1454-refac-r4jmqb December 23, 2025 13:53 Inactive
@TomWoodward TomWoodward temporarily deployed to rex-web-core-1454-refac-zrjbew December 23, 2025 15:54 Inactive
@RoyEJohnson RoyEJohnson force-pushed the core-1454-refactor-reactutils branch from df2b95a to 1f86266 Compare December 23, 2025 16:28
@TomWoodward TomWoodward temporarily deployed to rex-web-core-1454-refac-lyyrqb December 23, 2025 16:28 Inactive
@RoyEJohnson RoyEJohnson force-pushed the core-1454-refactor-reactutils branch from 1f86266 to 3df5b09 Compare December 23, 2025 16:37
@TomWoodward TomWoodward temporarily deployed to rex-web-core-1454-refac-lyyrqb December 23, 2025 16:37 Inactive
@RoyEJohnson RoyEJohnson force-pushed the core-1454-refactor-reactutils branch from 3df5b09 to c2aa855 Compare December 23, 2025 17:04
@TomWoodward TomWoodward temporarily deployed to rex-web-core-1454-refac-lyyrqb December 23, 2025 17:04 Inactive
@RoyEJohnson RoyEJohnson force-pushed the core-1454-refactor-reactutils branch from c2aa855 to 65a6749 Compare December 23, 2025 17:09
@TomWoodward TomWoodward temporarily deployed to rex-web-core-1454-refac-lyyrqb December 23, 2025 17:09 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants