rc-dialog is a foundational React UI component providing a highly customizable and accessible dialog (modal) implementation. It offers core functionalities like visibility control, masking, animation hooks, and keyboard interaction (e.g., Esc key to close). While version 10.0.0 is the latest stable release of `rc-dialog` as a standalone package, its active development has largely shifted to its successor, `@rc-component/dialog`. `rc-dialog` itself has not seen new releases or significant updates for over a year, suggesting it is now in a maintenance or deprecated state. Developers are generally advised to consider `@rc-component/dialog` for new projects or migrations due to its ongoing development and improved features, including enhanced focus management. This package prioritizes stateless design and easy customization via props like `prefixCls`, `className`, `classNames`, and `styles`, making it a flexible choice for various design systems.
npm install rc-dialogVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic functional React component using `rc-dialog`, including state management for visibility, custom title, and event handling for closing. It highlights essential props like `visible`, `onClose`, `maskClosable`, `keyboard`, and `destroyOnClose`, and includes the necessary CSS import.
Consider migrating to `@rc-component/dialog`. Review its documentation for potential API differences. For example, imports will change from `import Dialog from 'rc-dialog'` to `import Dialog from '@rc-component/dialog'`. Ensure you update styling references accordingly if any internal class names have changed.
Carefully test focus flow for all interactive elements within and outside the dialog. Ensure `keyboard` prop is used for Esc key closing. For complex scenarios, you might need to manually manage focus using `ref`s and the DOM API, or explore `focusTrap` options if available in newer versions of `@rc-component/dialog`.
Always include `import 'rc-dialog/assets/index.css';` in your entry file or a relevant component file. For custom styling, override these defaults using the `prefixCls`, `className`, `classNames`, or `style`/`styles` props.
For new projects or modern bundlers, prefer ESM imports: `import Dialog from 'rc-dialog';`. If you must use CommonJS, stick to `const Dialog = require('rc-dialog');` consistently. Ensure your build configuration correctly handles module resolution.Ensure that `onClose` or any visibility toggling function correctly updates the state to `false` (or the desired hidden state) and that there are no unintended side effects causing the dialog to immediately reopen. Example: `const onClose = useCallback(() => setVisible(false), []);`
Verify that elements are present in the DOM before attempting to focus them. If using `destroyOnClose`, consider alternative strategies for preserving focus, or explicitly set focus to the trigger element in the `afterClose` callback. For custom focus handling, use `getContainer` to control where the dialog mounts, ensuring it's part of the accessible DOM tree.
First, ensure the package is installed: `npm install rc-dialog` or `yarn add rc-dialog`. Double-check the import statement `import Dialog from 'rc-dialog';`. If using a bundler like Webpack, ensure its module resolution configuration (e.g., `resolve.extensions`) is set up to handle `.js`, `.jsx`, `.ts`, `.tsx` files correctly.