From eb73048b0f8e6852f047a512c2044d0406bc9195 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 13 Jul 2020 12:43:06 +0200 Subject: [PATCH] DEV: Allow displaying both title and panels in modals (#10220) --- .../discourse/app/lib/show-modal.js | 2 + .../app/templates/components/d-modal.hbs | 18 +++--- app/assets/stylesheets/common/base/modal.scss | 3 +- test/javascripts/acceptance/modal-test.js | 56 ++++++++++++++++++- 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/show-modal.js b/app/assets/javascripts/discourse/app/lib/show-modal.js index 514c49f3ee4..37c6b8efe3f 100644 --- a/app/assets/javascripts/discourse/app/lib/show-modal.js +++ b/app/assets/javascripts/discourse/app/lib/show-modal.js @@ -39,6 +39,8 @@ export default function(name, opts) { route.render(fullName, renderArgs); if (opts.title) { modalController.set("title", I18n.t(opts.title)); + } else { + modalController.set("title", null); } if (opts.panels) { diff --git a/app/assets/javascripts/discourse/app/templates/components/d-modal.hbs b/app/assets/javascripts/discourse/app/templates/components/d-modal.hbs index e9e608d6438..b676b34e12b 100644 --- a/app/assets/javascripts/discourse/app/templates/components/d-modal.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/d-modal.hbs @@ -6,6 +6,16 @@ {{d-button icon="times" action=(route-action "closeModal" "initiatedByCloseButton") class="btn-flat modal-close close" title="modal.close"}} {{/if}} + {{#if title}} +
+

{{title}}

+ + {{#if subtitle}} +

{{subtitle}}

+ {{/if}} +
+ {{/if}} + {{#if panels}} - {{else}} -
-

{{title}}

- - {{#if subtitle}} -

{{subtitle}}

- {{/if}} -
{{/if}} diff --git a/app/assets/stylesheets/common/base/modal.scss b/app/assets/stylesheets/common/base/modal.scss index 289051c0cd2..e7b8dd7c404 100644 --- a/app/assets/stylesheets/common/base/modal.scss +++ b/app/assets/stylesheets/common/base/modal.scss @@ -59,6 +59,8 @@ align-items: center; .title { + margin-right: 1em; + h3 { margin-bottom: 0; } @@ -749,7 +751,6 @@ .modal-tabs { display: inline-flex; flex-wrap: wrap; - width: calc(100% - 20px); flex: 1 0 auto; margin: 0; diff --git a/test/javascripts/acceptance/modal-test.js b/test/javascripts/acceptance/modal-test.js index d07e5a916cb..7f20a68733e 100644 --- a/test/javascripts/acceptance/modal-test.js +++ b/test/javascripts/acceptance/modal-test.js @@ -1,8 +1,25 @@ +import I18n from "I18n"; import { run } from "@ember/runloop"; import { acceptance, controllerFor } from "helpers/qunit-helpers"; import showModal from "discourse/lib/show-modal"; -acceptance("Modal"); +acceptance("Modal", { + beforeEach() { + this._translations = I18n.translations; + + I18n.translations = { + en: { + js: { + test_title: "Test title" + } + } + }; + }, + + afterEach() { + I18n.translations = this._translations; + } +}); QUnit.skip("modal", async function(assert) { await visit("/"); @@ -73,6 +90,43 @@ QUnit.test("rawTitle in modal panels", async function(assert) { ); }); +QUnit.test("modal title", async function(assert) { + Ember.TEMPLATES["modal/test-title"] = Ember.HTMLBars.compile(""); + Ember.TEMPLATES["modal/test-title-with-body"] = Ember.HTMLBars.compile( + "{{#d-modal-body}}test{{/d-modal-body}}" + ); + + await visit("/"); + + run(() => showModal("test-title", { title: "test_title" })); + assert.equal( + find(".d-modal .title") + .text() + .trim(), + "Test title", + "it should display the title" + ); + + await click(".d-modal .close"); + + run(() => showModal("test-title-with-body", { title: "test_title" })); + assert.equal( + find(".d-modal .title") + .text() + .trim(), + "Test title", + "it should display the title when used with d-modal-body" + ); + + await click(".d-modal .close"); + + run(() => showModal("test-title")); + assert.ok( + find(".d-modal .title").length === 0, + "it should not re-use the previous title" + ); +}); + acceptance("Modal Keyboard Events", { loggedIn: true }); QUnit.test("modal-keyboard-events", async function(assert) {