import React, {CSSProperties, SyntheticEvent} from 'react'; import {createPortal} from 'react-dom'; import {positionPopup} from '../helpers'; interface IProps { label: string; close: () => void; target: HTMLElement; } const BACKDROP_STYLE: CSSProperties = { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, zIndex: 999, // positionPopup sets it to 1000 overflow: 'auto', // to allow scroll }; const stopEvent = (event: SyntheticEvent) => event.stopPropagation(); export class ItemListPopup extends React.PureComponent { constructor(props) { super(props); this.close = this.close.bind(this); } componentDidMount() { positionPopup(this.props.target); } close(event: SyntheticEvent) { // avoid click propagating to list item // https://reactjs.org/docs/portals.html#event-bubbling-through-portals event.stopPropagation(); this.props.close(); } render() { return createPortal( , document.getElementById('react-placeholder'), 'popup', ); } }