Skip to content

Commit

Permalink
ui dialog bugfixes (#16554)
Browse files Browse the repository at this point in the history
* fake snab modals

* more explicit show & modal properties

* update domDialog and snabDialog calls with new properties
  • Loading branch information
ornicar authored Dec 9, 2024
2 parents 6e83a71 + 6667c67 commit 58f0a1a
Show file tree
Hide file tree
Showing 28 changed files with 101 additions and 60 deletions.
1 change: 1 addition & 0 deletions ui/analyse/src/explorer/explorerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ const playerModal = (ctrl: ExplorerConfigCtrl) => {
ctrl.data.playerName.open(false);
ctrl.root.redraw();
},
modal: true,
vnodes: [
h('h2', 'Personal opening explorer'),
h('div.input-wrapper', [
Expand Down
1 change: 1 addition & 0 deletions ui/analyse/src/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export function view(ctrl: AnalyseCtrl): VNode {
return snabDialog({
class: 'help.keyboard-help',
htmlUrl: xhr.url('/analysis/help', { study: !!ctrl.study }),
modal: true,
onClose() {
ctrl.keyboardHelp = false;
ctrl.redraw();
Expand Down
3 changes: 2 additions & 1 deletion ui/analyse/src/serverSideUnderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ export default function (element: HTMLElement, ctrl: AnalyseCtrl) {
const url = `${baseUrl()}/embed/game/${data.game.id}?theme=auto&bg=auto${location.hash}`;
const iframe = `<iframe src="${url}"\nwidth=600 height=397 frameborder=0></iframe>`;
domDialog({
show: 'modal',
modal: true,
show: true,
htmlText:
'<div><strong style="font-size:1.5em">' +
$(this).html() +
Expand Down
2 changes: 2 additions & 0 deletions ui/analyse/src/study/chapterEditForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export function view(ctrl: StudyChapterEditForm): VNode | undefined {
ctrl.current(null);
ctrl.redraw();
},
modal: true,
noClickAway: true,
vnodes: [
h('h2', i18n.study.editChapter),
h(
Expand Down
2 changes: 1 addition & 1 deletion ui/analyse/src/study/chapterNewForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ export function view(ctrl: StudyChapterNewForm): VNode {
ctrl.isOpen(false);
ctrl.redraw();
},
modal: true,
noClickAway: true,
onInsert: dlg => dlg.show(),
vnodes: [
activeTab !== 'edit' &&
h('h2', [
Expand Down
1 change: 1 addition & 0 deletions ui/analyse/src/study/inviteForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function view(ctrl: ReturnType<typeof makeCtrl>): VNode {
ctrl.open(false);
ctrl.redraw();
},
modal: true,
noScrollable: true,
vnodes: [
h('h2', i18n.study.inviteToTheStudy),
Expand Down
1 change: 1 addition & 0 deletions ui/analyse/src/study/studyForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export function view(ctrl: StudyForm): VNode {
ctrl.open(false);
ctrl.redraw();
},
modal: true,
noClickAway: true,
vnodes: [
h(
Expand Down
1 change: 1 addition & 0 deletions ui/analyse/src/study/studySearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function view(ctrl: SearchCtrl) {
onClose() {
ctrl.open(false);
},
modal: true,
vnodes: [
h('input', {
attrs: { autofocus: 1, placeholder: `Search in ${ctrl.studyName}`, value: ctrl.query() },
Expand Down
1 change: 1 addition & 0 deletions ui/analyse/src/study/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const formView = (ctrl: TopicsCtrl, userId?: string): VNode =>
ctrl.open(false);
ctrl.redraw();
},
modal: true,
vnodes: [
h('h2', i18n.study.topics),
h(
Expand Down
4 changes: 3 additions & 1 deletion ui/analyse/src/view/actionMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export function view(ctrl: AnalyseCtrl): VNode {
h(
'a',
{
hook: bind('click', () => domDialog({ cash: $('.continue-with.g_' + d.game.id), show: 'modal' })),
hook: bind('click', () =>
domDialog({ cash: $('.continue-with.g_' + d.game.id), modal: true, show: true }),
),
attrs: dataIcon(licon.Swords),
},
i18n.site.continueFromHere,
Expand Down
3 changes: 2 additions & 1 deletion ui/bits/src/bits.cropDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export async function initModule(o?: CropOpts): Promise<void> {
const dlg = await domDialog({
class: 'crop-viewer',
css: [{ hashed: 'bits.cropDialog' }, { url: 'npm/cropper.min.css' }],
modal: true,
htmlText: `<h2>Crop image to desired shape</h2>
<div class="crop-view"></div>
<span class="dialog-actions"><button class="button button-empty cancel">cancel</button>
Expand All @@ -81,7 +82,7 @@ export async function initModule(o?: CropOpts): Promise<void> {
},
});

dlg.showModal();
dlg.show();

async function crop() {
const view = dlg.view.querySelector('.crop-view') as HTMLElement;
Expand Down
3 changes: 2 additions & 1 deletion ui/bits/src/bits.diagnosticDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function initModule(): Promise<void> {
const dlg = await domDialog({
class: 'diagnostic',
css: [{ hashed: 'bits.diagnosticDialog' }],
modal: true,
htmlText: `
<h2>Diagnostics</h2>${flash}
<pre tabindex="0" class="err">${escaped}</pre>
Expand All @@ -52,7 +53,7 @@ export async function initModule(): Promise<void> {
setTimeout(() => copied.remove(), 2000);
}),
);
dlg.showModal();
dlg.show();
}

const storageProxy: { [key: string]: { storageKey: string; validate: (val?: string) => boolean } } = {
Expand Down
6 changes: 4 additions & 2 deletions ui/bits/src/bits.forum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ site.load.then(() => {
domDialog({
cash: $('.forum-delete-modal'),
attrs: { view: { action: link.href } },
modal: true,
}).then(dlg => {
$(dlg.view)
.find('form')
Expand All @@ -22,7 +23,7 @@ site.load.then(() => {
dlg.close();
});
$(dlg.view).find('form button.cancel').on('click', dlg.close);
dlg.showModal();
dlg.show();
});
return false;
})
Expand All @@ -31,10 +32,11 @@ site.load.then(() => {
domDialog({
cash: $('.forum-relocate-modal'),
attrs: { view: { action: link.href } },
modal: true,
}).then(dlg => {
$(dlg.view).find('form').attr('action', link.href);
$(dlg.view).find('form button.cancel').on('click', dlg.close);
dlg.showModal();
dlg.show();
});
return false;
})
Expand Down
4 changes: 2 additions & 2 deletions ui/bits/src/bits.publicChats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ site.load.then(() => {

$('#communication').on('click', '.line:not(.lichess)', function (this: HTMLDivElement) {
const $l = $(this);
domDialog({ cash: $('.timeout-modal') }).then(dlg => {
domDialog({ cash: $('.timeout-modal'), modal: true }).then(dlg => {
$('.username', dlg.view).text($l.find('.user-link').text());
$('.text', dlg.view).text($l.text().split(' ').slice(1).join(' '));
$('.button', dlg.view).on('click', function (this: HTMLButtonElement) {
Expand All @@ -58,7 +58,7 @@ site.load.then(() => {
}).then(_ => setTimeout(reloadNow, 1000));
dlg.close();
});
dlg.showModal();
dlg.show();
});
});
};
Expand Down
3 changes: 2 additions & 1 deletion ui/ceval/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const sharedWasmMemory = (lo: number, hi = 32767): WebAssembly.Memory =>
export function showEngineError(engine: string, error: string): void {
domDialog({
class: 'engine-error',
modal: true,
htmlText:
`<h2>${escapeHtml(engine)} <bad>error</bad></h2>` +
(error.includes('Status 503')
Expand All @@ -57,6 +58,6 @@ export function showEngineError(engine: string, error: string): void {
window.getSelection()?.addRange(range);
}, 0);
dlg.view.querySelector('.err')?.addEventListener('focus', select);
dlg.showModal();
dlg.show();
});
}
3 changes: 2 additions & 1 deletion ui/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ function help() {
domDialog({
css: [{ hashed: 'cli.help' }],
class: 'clinput-help',
show: 'modal',
modal: true,
show: true,
htmlText:
'<div><h3>Commands</h3>' +
commandHelp('/tv /follow', ' <user>', 'Watch someone play') +
Expand Down
11 changes: 10 additions & 1 deletion ui/common/css/component/_dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ dialog {
@include if-rtl {
transform: translate(50%, -50%);
}
z-index: $z-modal-111;
padding: 0;
border: none;
background: $c-bg-high;
z-index: $z-modal-111;
&:has(.dialog-content.alert) {
z-index: $z-modal-alert-200;
}

&::backdrop {
background: $c-page-mask;
Expand Down Expand Up @@ -80,6 +83,12 @@ dialog {
}
}

// applied to dialog wrapper div so we can fake HTMLDialogElement.showModal() in a snab render loop
.snab-modal-mask {
@extend %fullscreen-mask, %flex-center;
justify-content: center;
}

.dialog-content {
text-align: center;
padding: 2em;
Expand Down
Loading

0 comments on commit 58f0a1a

Please sign in to comment.