Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
react-relative-portal
Advanced tools
React component for place dropdowns outside overflow: hidden; elements
React component for place dropdown-like components outside overflow: hidden; sections
npm install react-relative-portal --save
import React from 'react';
import RelativePortal from 'react-relative-portal';
export default class DropdownLink extends React.Component {
constructor(props) {
super(props);
this.state = {
show: false,
};
this._setShowAsyncTimer = null;
this._handleShow = () => {
this._setShowAsync(true);
};
this._handleHide = () => {
this._setShowAsync(false);
};
}
componentWillUnmount() {
// Prevent the asynchronous `setState` call after unmount.
clearTimeout(this._setShowAsyncTimer);
}
/**
* Changes the dropdown show/hide state asynchronously.
*
* Need to change the dropdown state asynchronously,
* otherwise the dropdown gets immediately closed
* during the dropdown toggle's `onClick` which propagates to `onOutClick`.
*/
_setShowAsync(show) {
// Prevent multiple asynchronous `setState` calls, jsut the latest has to happen.
clearTimeout(this._setShowAsyncTimer);
this._setShowAsyncTimer = setTimeout(() => {
this.setState({ show: show });
}, 0);
}
render() {
const { show } = this.state;
return (
<div>
<button onClick={show ? this._handleHide : this._handleShow}>
Dropdown toggle
</button>
<RelativePortal
component="div"
left={0}
top={10}
onOutClick={show ? this._handleHide : null}
>
{show &&
<div style={{ padding: 10, backgroundColor: '#FFF' }}>
Dropdown content
</div>
}
</RelativePortal>
</div>
);
}
}
export default class RelativePortal extends React.Component {
static propTypes = {
right: PropTypes.number, // set right offset from current position. If undefined portal positons from left
left: PropTypes.number, // set left offset from current position. If `right` prop is set, `left` ignores
fullWidth: PropTypes.bool, // enables you to set both left and right portal positions
top: PropTypes.number, // set top offset from current position
children: PropTypes.any.isRequired, // portal content
onOutClick: PropTypes.func, // called when user click outside portal element
component: PropTypes.string.isRequired, // dom tagName
};
static defaultProps = {
left: 0,
top: 0,
component: 'span',
};
...
}
FAQs
React component for place dropdowns outside overflow: hidden; elements
The npm package react-relative-portal receives a total of 3,316 weekly downloads. As such, react-relative-portal popularity was classified as popular.
We found that react-relative-portal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.