mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-16 22:17:59 +00:00
Merge pull request #7710 from haiwen/optimize/dropdown_menu
optimize dropdown menu open direction
This commit is contained in:
commit
034f1e2a04
@ -34,6 +34,7 @@ class ItemDropdownMenu extends React.Component {
|
|||||||
currentItem: ''
|
currentItem: ''
|
||||||
};
|
};
|
||||||
this.dropdownRef = React.createRef();
|
this.dropdownRef = React.createRef();
|
||||||
|
this.mainMenuDirection = 'down';
|
||||||
this.subMenuDirection = 'right';
|
this.subMenuDirection = 'right';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +48,24 @@ class ItemDropdownMenu extends React.Component {
|
|||||||
});
|
});
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this.dropdownRef.current) {
|
if (this.dropdownRef.current) {
|
||||||
|
const rect = this.dropdownRef.current.getBoundingClientRect();
|
||||||
|
const windowHeight = window.innerHeight;
|
||||||
|
|
||||||
|
const spaceBelow = windowHeight - rect.bottom;
|
||||||
|
const spaceAbove = rect.top;
|
||||||
|
const menuHeightThreshold = 400;
|
||||||
|
|
||||||
|
let mainMenuDirection;
|
||||||
|
if (spaceBelow < menuHeightThreshold && spaceAbove < menuHeightThreshold) {
|
||||||
|
const spaceRight = window.innerWidth - rect.right;
|
||||||
|
mainMenuDirection = spaceRight >= 200 ? 'right' : 'left';
|
||||||
|
} else if (spaceBelow < menuHeightThreshold) {
|
||||||
|
mainMenuDirection = 'up';
|
||||||
|
} else {
|
||||||
|
mainMenuDirection = 'down';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mainMenuDirection = mainMenuDirection;
|
||||||
this.subMenuDirection = (window.innerWidth - this.dropdownRef.current.getBoundingClientRect().right < 400) ? 'left' : 'right';
|
this.subMenuDirection = (window.innerWidth - this.dropdownRef.current.getBoundingClientRect().right < 400) ? 'left' : 'right';
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
@ -196,7 +215,12 @@ class ItemDropdownMenu extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown isOpen={this.state.isItemMenuShow} toggle={this.onDropdownToggleClick} className="vam">
|
<Dropdown
|
||||||
|
isOpen={this.state.isItemMenuShow}
|
||||||
|
toggle={this.onDropdownToggleClick}
|
||||||
|
className="vam"
|
||||||
|
direction={this.mainMenuDirection}
|
||||||
|
>
|
||||||
<DropdownToggle
|
<DropdownToggle
|
||||||
tag={tagName || 'i'}
|
tag={tagName || 'i'}
|
||||||
role="button"
|
role="button"
|
||||||
|
Loading…
Reference in New Issue
Block a user