diff --git a/mailpoet/assets/css/src/components-public/_public.scss b/mailpoet/assets/css/src/components-public/_public.scss index 5a28ee4c4b..53ef545e4f 100644 --- a/mailpoet/assets/css/src/components-public/_public.scss +++ b/mailpoet/assets/css/src/components-public/_public.scss @@ -1,6 +1,7 @@ @use 'sass:math'; $form-break-small-width: 500px; +$form-container-break-small-width: 400px; $form-block-margin: 20px; $form-columns-with-background-padding: 10px; $form-columns-space-between: 20px; @@ -242,6 +243,11 @@ div.mailpoet_form:not(.mailpoet_form_fixed_bar) { } } +.mailpoet_form_columns_container { + container-name: columns; + container-type: inline-size; +} + .mailpoet_form_columns { display: flex; flex-wrap: nowrap; @@ -258,19 +264,17 @@ div.mailpoet_form:not(.mailpoet_form_fixed_bar) { &.mailpoet_vertically_align_bottom { align-items: flex-start; } +} - &.mailpoet_stack_on_mobile { - @include breakpoint-max-width(#{($form-break-small-width - 1)}) { - @include maxWidthColumns; - } - } - - .mailpoet_form_tight_container &.mailpoet_stack_on_mobile { +@container columns (width < #{($form-container-break-small-width)}) { + .mailpoet_form_columns.mailpoet_stack_on_mobile { @include maxWidthColumns; } } .mailpoet_form_column { + container-name: column; + container-type: inline-size; display: flex; flex-direction: column; flex-grow: 1; @@ -288,23 +292,16 @@ div.mailpoet_form:not(.mailpoet_form_fixed_bar) { align-self: flex-end; } - @include breakpoint-min-width($form-break-small-width) { - .mailpoet_form_form:not(.mailpoet_form_tight_container) - .mailpoet_column_with_background - & - .mailpoet_paragraph:last-child { - margin-bottom: 0 !important; - } - } - .mailpoet_stack_on_mobile & { @include breakpoint-max-width(#{($form-break-small-width - 1)}) { @include maxWidthColumn; } } +} - .mailpoet_form_tight_container .mailpoet_stack_on_mobile & { - @include maxWidthColumn; +@container column (width > #{($form-container-break-small-width)}) { + .mailpoet_paragraph:last-child { + margin-bottom: 0; } } diff --git a/mailpoet/assets/js/src/form-editor/form-preview.ts b/mailpoet/assets/js/src/form-editor/form-preview.ts index cf8153ad4d..6d967f587d 100644 --- a/mailpoet/assets/js/src/form-editor/form-preview.ts +++ b/mailpoet/assets/js/src/form-editor/form-preview.ts @@ -142,12 +142,6 @@ jQuery(($) => { ); } } - - // Detect tight container - $previewForm.removeClass('mailpoet_form_tight_container'); - if ($previewForm.width() < 400) { - $previewForm.addClass('mailpoet_form_tight_container'); - } }; window.addEventListener('message', updateForm, false); diff --git a/mailpoet/assets/js/src/public.tsx b/mailpoet/assets/js/src/public.tsx index c5ecfc0174..1baca1a80a 100644 --- a/mailpoet/assets/js/src/public.tsx +++ b/mailpoet/assets/js/src/public.tsx @@ -241,17 +241,6 @@ jQuery(($) => { setTimeout(renderCaptcha, 400, element, 1); }); - /** - * @param form jQuery object of form form.mailpoet_form - */ - function checkFormContainer(form) { - if (form.width() < 400) { - form.addClass('mailpoet_form_tight_container'); - } else { - form.removeClass('mailpoet_form_tight_container'); - } - } - /** * Sets the cookie for the form after dismissing the form * Uses cookie expiration time defined on the form @@ -312,7 +301,6 @@ jQuery(($) => { function doDisplayForm(formDiv, showOverlay) { formDiv.addClass('active'); - checkFormContainer(formDiv); if (showOverlay) { formDiv.prev('.mailpoet_form_popup_overlay').addClass('active'); @@ -424,19 +412,10 @@ jQuery(($) => { showForm(formDiv, showOverlay); }); - $(window).on('resize', () => { - $('.mailpoet_form').each((_, element) => { - // Detect form is placed in tight container - const formDiv = $(element); - checkFormContainer(formDiv); - }); - }); - // setup form validation $('form.mailpoet_form').each((_, element) => { const form = $(element); // Detect form is placed in tight container - checkFormContainer(form.closest('div.mailpoet_form')); form.parsley().on('form:validated', () => { // clear messages form.find('.mailpoet_message > p').hide(); diff --git a/mailpoet/lib/Form/Block/Columns.php b/mailpoet/lib/Form/Block/Columns.php index 079f1a28a8..9680298e12 100644 --- a/mailpoet/lib/Form/Block/Columns.php +++ b/mailpoet/lib/Form/Block/Columns.php @@ -15,7 +15,7 @@ class Columns { } public function render(array $block, string $content): string { - return "
getClass($block['params'] ?? [])}{$this->getStyles($block['params'] ?? [])}>$content
"; + return "
getClass($block['params'] ?? [])}{$this->getStyles($block['params'] ?? [])}>$content
"; } private function getStyles(array $params): string { diff --git a/mailpoet/tests/unit/Form/Block/ColumnsTest.php b/mailpoet/tests/unit/Form/Block/ColumnsTest.php index aa4a984cbf..e6c2c1563c 100644 --- a/mailpoet/tests/unit/Form/Block/ColumnsTest.php +++ b/mailpoet/tests/unit/Form/Block/ColumnsTest.php @@ -30,14 +30,14 @@ class ColumnsTest extends \MailPoetUnitTest { public function testItShouldRenderColumns() { $html = $this->columns->render($this->block, 'content'); - verify($html)->equals('
content
'); + verify($html)->stringContainsString('
content
'); } public function testItShouldRenderVerticalAlignClass() { $block = $this->block; $block['params']['vertical_alignment'] = 'top'; $html = $this->columns->render($block, 'content'); - $column = $this->htmlParser->getElementByXpath($html, '//div[1]'); + $column = $this->htmlParser->getElementByXpath($html, '//div[contains(@class, \'mailpoet_form_columns\')]/div[1]'); $class = $this->htmlParser->getAttribute($column, 'class'); verify($class->textContent)->stringContainsString('mailpoet_vertically_align_top'); } @@ -46,7 +46,7 @@ class ColumnsTest extends \MailPoetUnitTest { $block = $this->block; $block['params']['class_name'] = 'my-class'; $html = $this->columns->render($block, 'content'); - $column = $this->htmlParser->getElementByXpath($html, '//div[1]'); + $column = $this->htmlParser->getElementByXpath($html, '//div[contains(@class, \'mailpoet_form_columns\')]/div[1]'); $class = $this->htmlParser->getAttribute($column, 'class'); verify($class->textContent)->stringContainsString('my-class'); } @@ -54,7 +54,7 @@ class ColumnsTest extends \MailPoetUnitTest { public function testItShouldRenderStackOnMobileClassWhenFlagIsNotSet() { $block = $this->block; $html = $this->columns->render($block, 'content'); - $column = $this->htmlParser->getElementByXpath($html, '//div[1]'); + $column = $this->htmlParser->getElementByXpath($html, '//div[contains(@class, \'mailpoet_form_columns\')]/div[1]'); $class = $this->htmlParser->getAttribute($column, 'class'); verify($class->textContent)->stringContainsString('mailpoet_stack_on_mobile'); } @@ -63,7 +63,7 @@ class ColumnsTest extends \MailPoetUnitTest { $block = $this->block; $block['params']['is_stacked_on_mobile'] = '1'; $html = $this->columns->render($block, 'content'); - $column = $this->htmlParser->getElementByXpath($html, '//div[1]'); + $column = $this->htmlParser->getElementByXpath($html, '//div[contains(@class, \'mailpoet_form_columns\')]/div[1]'); $class = $this->htmlParser->getAttribute($column, 'class'); verify($class->textContent)->stringContainsString('mailpoet_stack_on_mobile'); } @@ -72,7 +72,7 @@ class ColumnsTest extends \MailPoetUnitTest { $block = $this->block; $block['params']['is_stacked_on_mobile'] = '0'; $html = $this->columns->render($block, 'content'); - $column = $this->htmlParser->getElementByXpath($html, '//div[1]'); + $column = $this->htmlParser->getElementByXpath($html, '//div[contains(@class, \'mailpoet_form_columns\')]/div[1]'); $class = $this->htmlParser->getAttribute($column, 'class'); verify($class->textContent)->stringNotContainsString('mailpoet_stack_on_mobile'); } @@ -81,7 +81,7 @@ class ColumnsTest extends \MailPoetUnitTest { $block = $this->block; $block['params']['background_color'] = '#ffffff'; $html = $this->columns->render($block, 'content'); - $columns = $this->htmlParser->getElementByXpath($html, '//div[1]'); + $columns = $this->htmlParser->getElementByXpath($html, '//div[contains(@class, \'mailpoet_form_columns\')]/div[1]'); $style = $this->htmlParser->getAttribute($columns, 'style'); verify($style->textContent)->stringContainsString('background-color:#ffffff;'); $class = $this->htmlParser->getAttribute($columns, 'class'); @@ -92,7 +92,7 @@ class ColumnsTest extends \MailPoetUnitTest { $block = $this->block; $block['params']['text_color'] = '#ffffee'; $html = $this->columns->render($block, 'content'); - $columns = $this->htmlParser->getElementByXpath($html, '//div[1]'); + $columns = $this->htmlParser->getElementByXpath($html, '//div[contains(@class, \'mailpoet_form_columns\')]/div[1]'); $style = $this->htmlParser->getAttribute($columns, 'style'); verify($style->textContent)->stringContainsString('color:#ffffee;'); } @@ -101,7 +101,7 @@ class ColumnsTest extends \MailPoetUnitTest { $block = $this->block; $block['params']['gradient'] = 'linear-gradient(red, yellow)'; $html = $this->columns->render($block, 'content'); - $columns = $this->htmlParser->getElementByXpath($html, '//div[1]'); + $columns = $this->htmlParser->getElementByXpath($html, '//div[contains(@class, \'mailpoet_form_columns\')]/div[1]'); $style = $this->htmlParser->getAttribute($columns, 'style'); verify($style->textContent)->stringContainsString('background:linear-gradient(red, yellow);'); $class = $this->htmlParser->getAttribute($columns, 'class'); @@ -112,7 +112,7 @@ class ColumnsTest extends \MailPoetUnitTest { $block = $this->block; $block['params']['padding'] = ['top' => '1em', 'right' => '2em', 'bottom' => '3em', 'left' => '4em']; $html = $this->columns->render($block, 'content'); - $columns = $this->htmlParser->getElementByXpath($html, '//div[1]'); + $columns = $this->htmlParser->getElementByXpath($html, '//div[contains(@class, \'mailpoet_form_columns\')]/div[1]'); $style = $this->htmlParser->getAttribute($columns, 'style'); verify($style->textContent)->stringContainsString('padding:1em 2em 3em 4em;'); }