Skip to content

Commit 6045aff

Browse files
committed
Layout: Improved sidebar sizing, and dropdown consideration
- Updated tri-layout sidebars to have less padding and to avoid cutting off content when in single-sidebar mode. - Updated dropdown handling to consider the parent scroll container when deciding to drop upwards, to help prevent cut-off.
1 parent dfeca24 commit 6045aff

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

resources/js/components/dropdown.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {onSelect} from '../services/dom.ts';
1+
import {findClosestScrollContainer, onSelect} from '../services/dom.ts';
22
import {KeyboardNavigationHandler} from '../services/keyboard-navigation.ts';
33
import {Component} from './component';
44

@@ -33,7 +33,8 @@ export class Dropdown extends Component {
3333
const menuOriginalRect = this.menu.getBoundingClientRect();
3434
let heightOffset = 0;
3535
const toggleHeight = this.toggle.getBoundingClientRect().height;
36-
const dropUpwards = menuOriginalRect.bottom > window.innerHeight;
36+
const containerBounds = findClosestScrollContainer(this.menu).getBoundingClientRect();
37+
const dropUpwards = menuOriginalRect.bottom > containerBounds.bottom;
3738
const containerRect = this.container.getBoundingClientRect();
3839

3940
// If enabled, Move to body to prevent being trapped within scrollable sections

resources/js/services/dom.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,22 @@ export function findTargetNodeAndOffset(parentNode: HTMLElement, offset: number)
256256
export function hashElement(element: HTMLElement): string {
257257
const normalisedElemText = (element.textContent || '').replace(/\s{2,}/g, '');
258258
return cyrb53(normalisedElemText);
259+
}
260+
261+
/**
262+
* Find the closest scroll container parent for the given element
263+
* otherwise will default to the body element.
264+
*/
265+
export function findClosestScrollContainer(start: HTMLElement): HTMLElement {
266+
let el: HTMLElement|null = start;
267+
do {
268+
const computed = window.getComputedStyle(el);
269+
if (computed.overflowY === 'scroll') {
270+
return el;
271+
}
272+
273+
el = el.parentElement;
274+
} while (el);
275+
276+
return document.body;
259277
}

resources/sass/_layout.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ body.flexbox {
431431
grid-template-areas: "a b b";
432432
grid-template-columns: 1fr 3fr;
433433
grid-template-rows: min-content min-content 1fr;
434-
padding-inline-end: vars.$l;
434+
margin-inline-start: (vars.$m + vars.$xxs);
435+
margin-inline-end: (vars.$m + vars.$xxs);
435436
}
436437
.tri-layout-sides {
437438
grid-column-start: a;
@@ -452,6 +453,8 @@ body.flexbox {
452453
height: 100%;
453454
scrollbar-width: none;
454455
-ms-overflow-style: none;
456+
padding-inline: vars.$m;
457+
margin-inline: -(vars.$m);
455458
&::-webkit-scrollbar {
456459
display: none;
457460
}

0 commit comments

Comments
 (0)