Commit ec716ae5 authored by Jacob Rockowitz's avatar Jacob Rockowitz Committed by Jacob Rockowitz
Browse files

Issue #2953816 by jrockowitz: Provide mobile-friendly layout for multiple value composite elements

parent 77fb88ce
Loading
Loading
Loading
Loading
+48
Changes for css/webform.element.multiple.css: 48 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -104,3 +104,51 @@
.webform-multiple-table .imce-url-button {
  display: block;
}

/**
 * Mobile support to multiple table.
 */
@media (max-width: 768px) {
  .webform-multiple-table-responsive thead {
    display: none;
  }

  .webform-multiple-table-responsive tr {
    display: block;
    padding: .5em 0;
  }

  .webform-multiple-table-responsive td {
    display: block;
    border: 0;
    background: transparent;
    text-align: inherit;
    width: inherit;
    padding: .5em 1em;
  }

  .webform-multiple-table-responsive td:after {
    content: "";
    display: table;
    clear: both;
  }

  .webform-multiple-table-responsive td.webform-multiple-table--handle,
  .webform-multiple-table-responsive td.webform-multiple-table--operations {
    display: none;
  }

  .webform-multiple-table-responsive td.webform-multiple-table--weight {
    width: 100%;
  }

  .webform-multiple-table-responsive td label.visually-hidden {
    display: block;
    position: inherit !important;
    clip: inherit;
    overflow: inherit;
    height: inherit;
    width: inherit;
    margin: .2em 0;
  }
}
+6 −1
Changes for src/Element/WebformMultiple.php: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\Element\FormElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Template\Attribute;
use Drupal\webform\Utility\WebformElementHelper;

/**
@@ -174,8 +175,12 @@ class WebformMultiple extends FormElement {
    }

    // Build table.
    $attributes = ['id' => $table_id, 'class' => ['webform-multiple-table']];
    if (count($element['#element']) > 1) {
      $attributes['class'][] = 'webform-multiple-table-responsive';
    }
    $element['items'] = [
      '#prefix' => '<div id="' . $table_id . '" class="webform-multiple-table">',
      '#prefix' => '<div' . new Attribute($attributes) . '>',
      '#suffix' => '</div>',
      '#type' => 'table',
      '#header' => $header,
+1 −1
Changes for src/Tests/Composite/WebformCompositeCustomTest.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ class WebformCompositeCustomTest extends WebformTestBase {

    // Check basic custom composite.
    $this->assertRaw('<label for="edit-webform-custom-composite-basic">webform_custom_composite_basic</label>');
    $this->assertRaw('<div id="webform_custom_composite_basic_table" class="webform-multiple-table">');
    $this->assertRaw('<div id="webform_custom_composite_basic_table" class="webform-multiple-table webform-multiple-table-responsive">');
    $this->assertRaw('<th class="webform_custom_composite_basic-table--handle webform-multiple-table--handle"></th>');
    $this->assertRaw('<th class="webform_custom_composite_basic-table--first_name webform-multiple-table--first_name">First name</th>');
    $this->assertRaw('<th class="webform_custom_composite_basic-table--last_name webform-multiple-table--last_name">Last name</th>');