Skip to content

Commit 2fab37f

Browse files
committed
Dynamically stack the dialog controls on top of each other
Fixes #6400
1 parent cd54871 commit 2fab37f

3 files changed

Lines changed: 121 additions & 2 deletions

File tree

ts/WoltLabSuite/Core/Element/woltlab-core-dialog-control.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ export class WoltlabCoreDialogControlElement extends HTMLElement {
2424
#extraButton?: HTMLButtonElement;
2525
#primaryButton?: HTMLButtonElement;
2626

27+
constructor() {
28+
super();
29+
30+
const observer = new ResizeObserver(() => {
31+
this.#checkForButtonOverflow();
32+
});
33+
observer.observe(this);
34+
}
35+
2736
set primary(primary: string) {
2837
this.setAttribute("primary", primary);
2938
}
@@ -144,6 +153,40 @@ export class WoltlabCoreDialogControlElement extends HTMLElement {
144153

145154
this.append(this.#extraButton);
146155
}
156+
157+
this.#checkForButtonOverflow();
158+
}
159+
160+
#checkForButtonOverflow(): void {
161+
const hasCancelButton = this.#cancelButton !== undefined;
162+
const hasExtraButton = this.#extraButton !== undefined;
163+
164+
if (!hasCancelButton) {
165+
return;
166+
}
167+
168+
const gap = parseInt(window.getComputedStyle(this).columnGap.replace(/^px/, ""), 10);
169+
170+
const primaryAndCancelWidth = this.#primaryButton!.clientWidth + gap + this.#cancelButton!.clientWidth;
171+
const extraWidth = hasExtraButton ? gap + this.#extraButton!.clientWidth : 0;
172+
173+
if (hasExtraButton) {
174+
if (primaryAndCancelWidth > this.clientWidth) {
175+
this.classList.add("dialog__control--tripple-stacked");
176+
this.classList.remove("dialog__control--extra-stacked");
177+
} else if (primaryAndCancelWidth + extraWidth > this.clientWidth) {
178+
this.classList.add("dialog__control--extra-stacked");
179+
this.classList.remove("dialog__control--tripple-stacked");
180+
} else {
181+
this.classList.remove("dialog__control--tripple-stacked", "dialog__control--extra-stacked");
182+
}
183+
} else {
184+
if (primaryAndCancelWidth > this.clientWidth) {
185+
this.classList.add("dialog__control--duo-stacked");
186+
} else {
187+
this.classList.remove("dialog__control--duo-stacked");
188+
}
189+
}
147190
}
148191
}
149192

wcfsetup/install/files/js/WoltLabSuite/Core/Element/woltlab-core-dialog-control.js

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/style/ui/dialog.scss

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,39 @@ html[data-color-scheme="dark"] .dialog::backdrop {
388388
column-gap: 10px;
389389
display: grid;
390390
grid-template-areas: "extra cancel primary";
391-
grid-template-columns: auto max-content max-content;
391+
grid-template-columns: minmax(min-content, auto) max-content max-content;
392392
margin-top: 30px;
393+
row-gap: 10px;
394+
}
395+
396+
.dialog__control--duo-stacked,
397+
.dialog__control--extra-stacked,
398+
.dialog__control--tripple-stacked {
399+
justify-content: end;
400+
}
401+
402+
/* Cancel + Primary stacked on top of each other */
403+
.dialog__control--duo-stacked {
404+
grid-template-areas:
405+
"cancel"
406+
"primary";
407+
grid-template-columns: auto;
408+
}
409+
410+
/* Cancel + Primary are next to each other and extra on top */
411+
.dialog__control--extra-stacked {
412+
grid-template-areas:
413+
"extra extra"
414+
"cancel primary";
415+
grid-template-columns: auto max-content;
416+
}
417+
418+
.dialog__control--tripple-stacked {
419+
grid-template-areas:
420+
"extra"
421+
"cancel"
422+
"primary";
423+
grid-template-columns: auto;
393424
}
394425

395426
.dialog__control__button--primary {
@@ -402,7 +433,13 @@ html[data-color-scheme="dark"] .dialog::backdrop {
402433

403434
.dialog__control__button--extra {
404435
grid-area: extra;
405-
margin-right: auto;
436+
justify-self: start;
437+
}
438+
439+
.dialog__control--extra-stacked .dialog__control__button--extra,
440+
.dialog__control--tripple-stacked .dialog__control__button--extra {
441+
justify-self: end;
442+
margin-right: 0;
406443
}
407444

408445
/* Sections inside dialogs */

0 commit comments

Comments
 (0)