React Trigger Component

5.3.4 · maintenance · verified Sun Apr 19

rc-trigger is a foundational React component for managing and positioning overlay elements, such as tooltips, dropdowns, and context menus, relative to a target element. It abstracts the complex logic of popup display, alignment, and interaction events (like click, hover, contextMenu) into a reusable API. As of the provided metadata, the stable version is 5.3.4. While no specific release cadence for rc-trigger itself is explicitly documented (its last publish was 3 years ago), the package historically provided a robust, cross-browser solution for dynamic popup management in React applications. Its key differentiator lies in its flexibility for custom trigger actions and advanced alignment options, serving as a base for many other 'react-component' libraries. However, active feature development appears to have largely shifted to the newer, scoped package `@rc-component/trigger` within the same repository.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic click-triggered popup with custom alignment, rendering the Trigger component into a DOM container with its default styling.

import React from 'react';
import ReactDOM from 'react-dom';
import Trigger from 'rc-trigger';
import 'rc-trigger/assets/index.less'; // Import default styling

const App = () => (
  <Trigger
    action={['click']} // Trigger popup on click
    popup={<span>This is the popup content!</span>}
    popupAlign={{
      points: ['tl', 'bl'], // Align top-left of popup to bottom-left of target
      offset: [0, 3] // Offset popup by 3px downwards from the target
    }}
    destroyPopupOnHide={true} // Clean up popup DOM when hidden
    mouseLeaveDelay={0.1} // Small delay for mouseLeave action, if 'hover' was enabled
  >
    <a href="#" style={{ padding: '10px', border: '1px solid blue', display: 'inline-block' }}>
      Click Me to Toggle Popup
    </a>
  </Trigger>
);

// Assuming a 'root' element exists in your HTML, e.g., <div id="root"></div>
const container = document.getElementById('root');
if (container) {
  ReactDOM.render(<App />, container);
} else {
  console.error('Root container not found. Please ensure an element with id="root" exists in your HTML.');
}

view raw JSON →