|
| 1 | +--- |
| 2 | +group: ui-components-guide |
| 3 | +title: Container component |
| 4 | +contributor_name: Jehangir Wahid |
| 5 | +contributor_link: https://github.com/Jehangir-Wahid |
| 6 | +--- |
| 7 | + |
| 8 | +The Container [UI component](https://glossary.magento.com/ui-component) is used for wrapping fields or other ui-components with descriptive text. It may be used without any field to display a notice or description of a fieldset. |
| 9 | + |
| 10 | +## Configuration options |
| 11 | + |
| 12 | +Component options are set in the UI-component's configuration `.xml` file as follows: |
| 13 | + |
| 14 | +| Option | Description | Type | Default | |
| 15 | +| --- | --- | --- | --- | |
| 16 | +| `component` | Path to the component's `.js` file. | String | `''` | |
| 17 | +| `template` | Path to the component's `.html` template. | String | `ui/form/components/complex` | |
| 18 | +| `sortOrder` | Sort order of the Container. | Number | `0` | |
| 19 | +| `label` | Label displayed for the Container. | String | `''` | |
| 20 | +| `additionalClasses` | CSS class(es) applied to the root node of the component's `.html` template. | String | `''` | |
| 21 | +| `text` | Description for the Container. | String | `''` | |
| 22 | + |
| 23 | +## Source files |
| 24 | + |
| 25 | +- [`Magento/Ui/view/base/web/templates/form/components/complex.html`]({{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Ui/view/base/web/templates/form/components/complex.html) |
| 26 | + |
| 27 | +## Examples |
| 28 | + |
| 29 | +### Container with a component |
| 30 | + |
| 31 | +The following sample is an example of the Container component contain a `Select` component. |
| 32 | + |
| 33 | +```xml |
| 34 | +<container name="container_name"> |
| 35 | + <argument name="data" xsi:type="array"> |
| 36 | + <item name="config" xsi:type="array"> |
| 37 | + <item name="template" xsi:type="string">ui/form/components/complex</item> |
| 38 | + <item name="sortOrder" xsi:type="number">10</item> |
| 39 | + <item name="label" xsi:type="string">Container Label</item> |
| 40 | + <item name="additionalClasses" xsi:type="string">sample-additional-class</item> |
| 41 | + <item name="text" xsi:type="string" translate="true"><![CDATA[ |
| 42 | + <p> |
| 43 | + Container Text. |
| 44 | + </p> |
| 45 | + ]]></item> |
| 46 | + </item> |
| 47 | + </argument> |
| 48 | + <field name="sort_direction" |
| 49 | + sortOrder="20" |
| 50 | + formElement="select"> |
| 51 | + <settings> |
| 52 | + <dataType>text</dataType> |
| 53 | + <label translate="true">Sort Direction</label> |
| 54 | + <dataScope>data.sort_direction</dataScope> |
| 55 | + </settings> |
| 56 | + <formElements> |
| 57 | + <select> |
| 58 | + <settings> |
| 59 | + <options class="Vendor\Module\Model\Source\Config\SortDirection" /> |
| 60 | + <caption translate="true">-- Please Select --</caption> |
| 61 | + </settings> |
| 62 | + </select> |
| 63 | + </formElements> |
| 64 | + </field> |
| 65 | +</container> |
| 66 | +``` |
| 67 | +#### Result |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +### Container without any fields |
| 72 | + |
| 73 | +The following sample is an example of the Container component only. |
| 74 | + |
| 75 | +```xml |
| 76 | +<container name="container_name"> |
| 77 | + <argument name="data" xsi:type="array"> |
| 78 | + <item name="config" xsi:type="array"> |
| 79 | + <item name="template" xsi:type="string">ui/form/components/complex</item> |
| 80 | + <item name="sortOrder" xsi:type="number">10</item> |
| 81 | + <item name="label" xsi:type="string">Container Label</item> |
| 82 | + <item name="additionalClasses" xsi:type="string">sample-additional-class</item> |
| 83 | + <item name="text" xsi:type="string" translate="true"><![CDATA[ |
| 84 | + <p> |
| 85 | + Change these settings if you do not want to apply the global display configurations. |
| 86 | + </p> |
| 87 | + ]]></item> |
| 88 | + </item> |
| 89 | + </argument> |
| 90 | +</container> |
| 91 | +``` |
| 92 | + |
| 93 | +#### Result |
| 94 | + |
| 95 | +The `text` of this container is styled using the `additionalClasses` value, i.e. `sample-additional-class`. |
| 96 | + |
| 97 | + |
0 commit comments