1.8.0
React Trigger Component
Include the default styling and then:
import React from 'react'; import ReactDOM from 'react-dom'; import Trigger from '@rc-component/trigger'; ReactDOM.render(( <Trigger action={['click']} popup={<span>popup</span>} popupAlign={{ points: ['tl', 'bl'], offset: [0, 3] }} > <a href='#'>hover</a> </Trigger> ), container);
http://localhost:9001
online example: http://react-component.github.io/trigger/
npm install npm start
npm test npm run chrome-test
npm run coverage
open coverage/ dir
After React 16, you won’t access popup element’s ref in parent component’s componentDidMount, which means following code won’t work.
class App extends React.Component { componentDidMount() { this.input.focus(); // error, this.input is undefined. } render() { return ( <Trigger action={['click']} popup={<div><input ref={node => this.input = node} type="text" /></div>} > <button>click</button> </Trigger> ) } }
Consider wrap your popup element to a separate component:
class InputPopup extends React.Component { componentDidMount() { this.props.onMount(); } render() { return ( <div> <input ref={this.props.inputRef} type="text" /> </div> ); } } class App extends React.Component { handlePopupMount() { this.input.focus(); // error, this.input is undefined. } render() { return ( <Trigger action={['click']} popup={<InputPopup inputRef={node => this.input = node} onMount={this.handlePopupMount} />} > <button>click</button> </Trigger> ) } }
rc-trigger is released under the MIT license.
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802032778号
@rc-component/trigger
React Trigger Component
Install
Usage
Include the default styling and then:
Compatibility
IE / Edge
Firefox
Chrome
Safari
Electron
Example
http://localhost:9001
online example: http://react-component.github.io/trigger/
Development
API
props
Test Case
Coverage
open coverage/ dir
React 16 Note
After React 16, you won’t access popup element’s ref in parent component’s componentDidMount, which means following code won’t work.
Consider wrap your popup element to a separate component:
License
rc-trigger is released under the MIT license.