mirror of
https://github.com/flarum/framework.git
synced 2025-05-22 22:59:57 +08:00
Make sure dropdowns stay within the viewport horizontally too
This commit is contained in:
@ -47,13 +47,18 @@ export default class Dropdown extends Component {
|
|||||||
// bottom of the viewport. If it does, we will apply class to make it show
|
// bottom of the viewport. If it does, we will apply class to make it show
|
||||||
// above the toggle button instead of below it.
|
// above the toggle button instead of below it.
|
||||||
this.$().on('shown.bs.dropdown', () => {
|
this.$().on('shown.bs.dropdown', () => {
|
||||||
const $menu = this.$('.Dropdown-menu').removeClass('Dropdown-menu--top');
|
const $menu = this.$('.Dropdown-menu').removeClass('Dropdown-menu--top Dropdown-menu--right');
|
||||||
|
|
||||||
$menu.toggleClass(
|
$menu.toggleClass(
|
||||||
'Dropdown-menu--top',
|
'Dropdown-menu--top',
|
||||||
$menu.offset().top + $menu.height() > $(window).scrollTop() + $(window).height()
|
$menu.offset().top + $menu.height() > $(window).scrollTop() + $(window).height()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$menu.toggleClass(
|
||||||
|
'Dropdown-menu--right',
|
||||||
|
$menu.offset().left + $menu.width() > $(window).scrollLeft() + $(window).width()
|
||||||
|
);
|
||||||
|
|
||||||
if (this.props.onshow) {
|
if (this.props.onshow) {
|
||||||
this.props.onshow();
|
this.props.onshow();
|
||||||
m.redraw();
|
m.redraw();
|
||||||
|
Reference in New Issue
Block a user