mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-24 18:47:44 +00:00
Fix context menu positioning when scrolled
This commit is contained in:
parent
194cc02356
commit
baf6c37fe9
2 changed files with 19 additions and 5 deletions
|
|
@ -4,6 +4,10 @@
|
|||
|
||||
Users can pass an initial layout (TODO: Documentation)
|
||||
|
||||
### Fixes
|
||||
|
||||
- Fixes positioning of context menus in context menu targets when they are spawned while scrolled.
|
||||
|
||||
## 1.1.1
|
||||
|
||||
### Fixes
|
||||
|
|
|
|||
|
|
@ -34,11 +34,21 @@ export default class ContextMenuTarget extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
_offset() {
|
||||
if (!this.handleNode) {
|
||||
return { top: 0, left: 0 };
|
||||
}
|
||||
|
||||
const rect = this.handleNode.getBoundingClientRect();
|
||||
const scrollLeft =
|
||||
window.pageXOffset || document.documentElement.scrollLeft;
|
||||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
||||
return { top: rect.top + scrollTop, left: rect.left + scrollLeft };
|
||||
}
|
||||
|
||||
render() {
|
||||
const { handle, children, top, bottom, ...passThroughProps } = this.props;
|
||||
const rect = this.handleNode
|
||||
? this.handleNode.getBoundingClientRect()
|
||||
: { top: 0, left: 0 };
|
||||
const offset = this._offset();
|
||||
return (
|
||||
<div {...passThroughProps}>
|
||||
<div
|
||||
|
|
@ -51,8 +61,8 @@ export default class ContextMenuTarget extends React.Component {
|
|||
</div>
|
||||
<ContextMenu
|
||||
selected={this.state.selected}
|
||||
offsetTop={rect.top}
|
||||
offsetLeft={rect.left}
|
||||
offsetTop={offset.top}
|
||||
offsetLeft={offset.left}
|
||||
top={top}
|
||||
bottom={bottom}
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue