From 359663bfdba1c82c0212a2e9362fc4317f2d62d2 Mon Sep 17 00:00:00 2001 From: Lauri Eskola Date: Wed, 7 Jun 2017 10:06:42 +0300 Subject: [PATCH] Issue #2828912 by tedbow, RajeevK, tim.plunkett, a-fro: Offcanvas width is not reset if tray is open with different width and not closed --- .../src/Ajax/OpenOffCanvasDialogCommand.php | 11 +++++++++++ .../outside_in/src/Tests/Ajax/OffCanvasDialogTest.php | 1 + .../tests/src/FunctionalJavascript/OffCanvasTest.php | 6 +++++- .../src/Unit/Ajax/OpenOffCanvasDialogCommandTest.php | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/modules/outside_in/src/Ajax/OpenOffCanvasDialogCommand.php b/core/modules/outside_in/src/Ajax/OpenOffCanvasDialogCommand.php index 9989d91f652..2371483ed53 100644 --- a/core/modules/outside_in/src/Ajax/OpenOffCanvasDialogCommand.php +++ b/core/modules/outside_in/src/Ajax/OpenOffCanvasDialogCommand.php @@ -11,6 +11,11 @@ use Drupal\Core\Ajax\OpenDialogCommand; */ class OpenOffCanvasDialogCommand extends OpenDialogCommand { + /** + * The dialog width to use if none is provided. + */ + const DEFAULT_DIALOG_WIDTH = 300; + /** * Constructs an OpenOffCanvasDialogCommand object. * @@ -42,6 +47,12 @@ class OpenOffCanvasDialogCommand extends OpenDialogCommand { // @todo drupal.ajax.js does not respect drupalAutoButtons properly, pass an // empty set of buttons until https://www.drupal.org/node/2793343 is in. $this->dialogOptions['buttons'] = []; + // If no width option is provided then use the default width to avoid the + // dialog staying at the width of the previous instance when opened + // more than once, with different widths, on a single page. + if (!isset($this->dialogOptions['width'])) { + $this->dialogOptions['width'] = static::DEFAULT_DIALOG_WIDTH; + } } /** diff --git a/core/modules/outside_in/src/Tests/Ajax/OffCanvasDialogTest.php b/core/modules/outside_in/src/Tests/Ajax/OffCanvasDialogTest.php index 41d66dde3f0..e2b451e1a7d 100644 --- a/core/modules/outside_in/src/Tests/Ajax/OffCanvasDialogTest.php +++ b/core/modules/outside_in/src/Tests/Ajax/OffCanvasDialogTest.php @@ -46,6 +46,7 @@ class OffCanvasDialogTest extends AjaxTestBase { 'draggable' => FALSE, 'drupalAutoButtons' => FALSE, 'buttons' => [], + 'width' => 300, ], 'effect' => 'fade', 'speed' => 1000, diff --git a/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php b/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php index 3254ca981ec..94c18f039a9 100644 --- a/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php +++ b/core/modules/outside_in/tests/src/FunctionalJavascript/OffCanvasTest.php @@ -63,7 +63,11 @@ class OffCanvasTest extends OutsideInJavascriptTestBase { $this->assertEquals('', $header_text); $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style'); - self::assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.'); + $this->assertTrue(strstr($style, 'width: 555px;') !== FALSE, 'Dialog width respected.'); + $page->clickLink("Click Me 1!"); + $this->waitForOffCanvasToOpen(); + $style = $page->find('css', '.ui-dialog-off-canvas')->getAttribute('style'); + $this->assertTrue(strstr($style, 'width: 555px;') === FALSE, 'Dialog width reset to default.'); } else { // Check that header is correct. diff --git a/core/modules/outside_in/tests/src/Unit/Ajax/OpenOffCanvasDialogCommandTest.php b/core/modules/outside_in/tests/src/Unit/Ajax/OpenOffCanvasDialogCommandTest.php index 92103b401a1..d822415d61a 100644 --- a/core/modules/outside_in/tests/src/Unit/Ajax/OpenOffCanvasDialogCommandTest.php +++ b/core/modules/outside_in/tests/src/Unit/Ajax/OpenOffCanvasDialogCommandTest.php @@ -31,6 +31,7 @@ class OpenOffCanvasDialogCommandTest extends UnitTestCase { 'draggable' => FALSE, 'drupalAutoButtons' => FALSE, 'buttons' => [], + 'width' => 300, ], 'effect' => 'fade', 'speed' => 1000,