Skip to content

Commit

Permalink
fix: proper dropdown width
Browse files Browse the repository at this point in the history
  • Loading branch information
berezinant committed Nov 20, 2024
1 parent 353e2e1 commit 12ae5b6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,23 @@ function toggleDropdownButton(button: Element): void {
}

function toggleDropdownList(list: Element | null, minWidth?: number): void {
list?.classList.toggle('dropdown--list_expanded');
if (list) {
list.classList.toggle('dropdown--list_expanded');
if (list.classList.contains('dropdown--list_expanded')) {
setListMinWidth(list, minWidth);
} else {
setListMinWidth(list, undefined);
}
}
}

function setListMinWidth(list: Element, minWidth: number | undefined): void {
if (minWidth) {
(list as HTMLElement).style.minWidth = `${minWidth}px`;
const currentMinWidth = parseInt(getComputedStyle(list as HTMLElement).minWidth, 10);
const nextMinWidth = isNaN(currentMinWidth) ? minWidth : Math.max(currentMinWidth, minWidth);
(list as HTMLElement).style.minWidth = `${nextMinWidth}px`;
} else {
(list as HTMLElement).style.minWidth = 'auto';
(list as HTMLElement).style.minWidth = '';
}
}

Expand All @@ -53,6 +65,7 @@ function handleOutsideClick(event: MouseEvent): void {
});
dropdown.querySelectorAll(DROPDOWN_LIST)?.forEach((list: Element) => {
list.classList.remove('dropdown--list_expanded');
(list as HTMLElement).style.minWidth = '';
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
max-height: 400px;
padding: 12px 0;

-webkit-transform: translate3d(0, 0, 0);

border: 1px solid lighten(rgb(50, 50, 55), 15%); // color-background-nav-dt
background-color: var(--color-background-nav-dt);

box-shadow: 0 2px 8px 0 #00000040;
-webkit-transform: translate3d(0,0,0);

@media (width < $breakpoint-desktop-min) {
top: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@
position: absolute;
right: 0;
top: 44px;
-webkit-transform: translateZ(0);
width: -moz-fit-content;
width: fit-content;
z-index: 10;
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 12ae5b6

Please sign in to comment.