Skip to content

refactor(modal): migrate Modal from Flow to TypeScript - #4771

Open
bonchevskyi wants to merge 1 commit into
box:masterfrom
bonchevskyi:refactor/flow-to-ts-modal
Open

refactor(modal): migrate Modal from Flow to TypeScript#4771
bonchevskyi wants to merge 1 commit into
box:masterfrom
bonchevskyi:refactor/flow-to-ts-modal

Conversation

@bonchevskyi

@bonchevskyi bonchevskyi commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Convert Modal components to TypeScript

This PR converts src/components/modal from JavaScript with Flow to TypeScript.

Changes

  • Converted Modal, ModalDialog, and ModalActions to TSX with exported props interfaces
  • Converted tests and Storybook stories to TSX
  • Converted index.js to index.ts with type exports
  • Added .js.flow files for backward compatibility
  • Removed obsolete code and suppressions

Contract

  • Declared Flow props contract and runtime behavior preserved

Testing

  • All 26 modal tests pass
  • yarn lint, yarn lint:ts, and flow check pass
  • Verified Storybook compiles and starts successfully

Summary by CodeRabbit

  • New Features

    • Added modal dialogs with dialog and alert modes.
    • Added optional loading indicators, portal rendering, custom styling, and action areas.
    • Added localized back and close controls with accessible labels.
    • Added focus management, keyboard and backdrop dismissal, focus trapping, and background scroll prevention.
    • Added public exports for modal components and their prop types.
  • Tests

    • Improved modal test coverage and type safety.

@bonchevskyi
bonchevskyi requested a review from a team as a code owner August 11, 2026 15:07
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c5f4e386-748d-4e26-a8c6-2207af3783b7

📥 Commits

Reviewing files that changed from the base of the PR and between 7496e9e and 4c17a73.

📒 Files selected for processing (2)
  • src/components/modal/ModalDialog.tsx
  • src/components/modal/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/modal/index.ts

Walkthrough

The modal components now have TypeScript implementations with typed props and exports. Modal supports focus management, portals, loading state, close handling, focus trapping, styling, and body scroll suppression. ModalDialog supports localized accessible dialog and alert modes.

Changes

Modal component migration

Layer / File(s) Summary
Modal lifecycle and interaction handling
src/components/modal/Modal.tsx, src/components/modal/Modal.js.flow
Adds typed modal props, lifecycle focus handling, keyboard and backdrop close handling, portal rendering, loading output, focus trapping, and body scroll suppression.
Dialog semantics and controls
src/components/modal/ModalDialog.tsx, src/components/modal/ModalDialog.js.flow
Adds typed dialog props, localized controls, dialog and alertdialog modes, ARIA attributes, alert-child validation, and forwarded DOM properties.
Actions and public exports
src/components/modal/ModalActions.tsx, src/components/modal/ModalActions.js.flow, src/components/modal/index.ts, src/components/modal/index.js.flow
Adds typed ModalActions rendering and exports modal components with their prop types.
Typed test updates
src/components/modal/__tests__/*
Updates Enzyme, Sinon, React Intl, event, style, and component-instance typing in modal tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Modal
  participant DocumentBody
  participant LoadingIndicator
  participant ModalDialog
  Modal->>DocumentBody: suppress body scrolling while open
  Modal->>Modal: initialize or trap focus
  alt loading
    Modal->>LoadingIndicator: render loading state
  else loaded
    Modal->>ModalDialog: render dialog props and content
  end
Loading

Possibly related PRs

Suggested labels: ready-to-merge

Suggested reviewers: vitali-usik, reneshen0328, tjiang-box

Poem

A rabbit checks the modal door,
Focus hops from floor to floor.
Escape and backdrop close with care,
Typed controls bloom everywhere.
“The dialog is ready!” says the hare.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly states the migration scope, compatibility contract, testing results, and Storybook verification.
Title check ✅ Passed The title clearly and concisely identifies the main change: migrating the Modal component from Flow to TypeScript.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/components/modal/Modal.tsx (1)

159-162: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider typing the wrapper instead of casting to React.ElementType.

The as React.ElementType cast removes prop checking for both branches. TypeScript then cannot verify that Portal accepts onKeyDown and tabIndex. Portal spreads all props onto an inner div (src/components/portal/Portal.tsx lines 39-43), so the runtime behavior is correct today. A narrower union keeps the check active.

♻️ Alternative typing
-        const WrapperComponent = (shouldNotUsePortal ? 'div' : Portal) as React.ElementType;
+        const WrapperComponent: React.ElementType<React.HTMLAttributes<HTMLDivElement>> = shouldNotUsePortal
+            ? 'div'
+            : Portal;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/modal/Modal.tsx` around lines 159 - 162, Update the
WrapperComponent typing in the Modal render path to use a narrowed union of the
intrinsic div element and the Portal component instead of casting to
React.ElementType. Preserve the existing conditional selection and props, while
retaining TypeScript validation that onKeyDown, tabIndex, className, and related
props are accepted by both branches.
src/components/modal/Modal.js.flow (1)

132-176: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

The .js.flow shims duplicate full implementations. Both files copy the entire component body from their TSX counterparts. Flow reads only the exported types from a .js.flow file, so the method bodies serve no purpose and create two sources of truth. Each future change to a TSX file must be mirrored by hand, or Flow consumers receive a stale contract.

Confirm the established pattern in this repository before changing these files. Other .js.flow shims may already use one style consistently.

  • src/components/modal/Modal.js.flow#L132-L176: replace the class body with a declare export default class Modal extends React.Component<Props> declaration that keeps the dialog field.
  • src/components/modal/ModalDialog.js.flow#L39-L170: replace the class body with declarations for the default export and the ModalDialogBase named export.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/modal/Modal.js.flow` around lines 132 - 176, Replace the
duplicated implementations in src/components/modal/Modal.js.flow lines 132-176
and src/components/modal/ModalDialog.js.flow lines 39-170 with Flow
declarations, following the repository’s established .js.flow shim pattern. In
Modal.js.flow, declare the default Modal class extending React.Component<Props>
and retain its dialog field; in ModalDialog.js.flow, declare both the default
export and the named ModalDialogBase export without method bodies.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/modal/ModalDialog.tsx`:
- Line 115: Restore the explicit `#909090` color prop on IconClose in
src/components/modal/ModalDialog.tsx at lines 115-115, and keep the matching
color prop in src/components/modal/ModalDialog.js.flow at lines 107-107 so both
implementations render identically.
- Around line 109-114: Add type="button" to the close button rendered by the
ModalDialog component, alongside its existing aria-label and className
attributes. Keep closeButtonProps spread first so callers can override the
default type, matching the behavior already implemented by renderBackButton.
- Around line 184-187: Export the InjectedModalDialogProps type from
ModalDialog.tsx, then update the modal index barrel to re-export
InjectedModalDialogProps instead of or alongside ModalDialogProps so consumers
can type the injected component without supplying intl or closeButtonProps.

---

Nitpick comments:
In `@src/components/modal/Modal.js.flow`:
- Around line 132-176: Replace the duplicated implementations in
src/components/modal/Modal.js.flow lines 132-176 and
src/components/modal/ModalDialog.js.flow lines 39-170 with Flow declarations,
following the repository’s established .js.flow shim pattern. In Modal.js.flow,
declare the default Modal class extending React.Component<Props> and retain its
dialog field; in ModalDialog.js.flow, declare both the default export and the
named ModalDialogBase export without method bodies.

In `@src/components/modal/Modal.tsx`:
- Around line 159-162: Update the WrapperComponent typing in the Modal render
path to use a narrowed union of the intrinsic div element and the Portal
component instead of casting to React.ElementType. Preserve the existing
conditional selection and props, while retaining TypeScript validation that
onKeyDown, tabIndex, className, and related props are accepted by both branches.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 045cb637-38dc-4bd2-9817-93bca8d9e820

📥 Commits

Reviewing files that changed from the base of the PR and between 5d273fe and 7496e9e.

📒 Files selected for processing (14)
  • src/components/modal/Modal.js.flow
  • src/components/modal/Modal.tsx
  • src/components/modal/ModalActions.js.flow
  • src/components/modal/ModalActions.tsx
  • src/components/modal/ModalDialog.js.flow
  • src/components/modal/ModalDialog.tsx
  • src/components/modal/__tests__/Modal.test.tsx
  • src/components/modal/__tests__/ModalActions.test.tsx
  • src/components/modal/__tests__/ModalDialog.test.tsx
  • src/components/modal/index.js.flow
  • src/components/modal/index.ts
  • src/components/modal/stories/Modal.stories.tsx
  • src/components/modal/stories/ModalActions.stories.tsx
  • src/components/modal/stories/ModalDialog.stories.tsx
💤 Files with no reviewable changes (3)
  • src/components/modal/stories/ModalActions.stories.tsx
  • src/components/modal/stories/ModalDialog.stories.tsx
  • src/components/modal/stories/Modal.stories.tsx

Comment thread src/components/modal/ModalDialog.tsx
Comment thread src/components/modal/ModalDialog.tsx
Comment thread src/components/modal/ModalDialog.tsx Outdated
@bonchevskyi
bonchevskyi force-pushed the refactor/flow-to-ts-modal branch from 7496e9e to 4c17a73 Compare August 12, 2026 11:31
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.

1 participant