# HasContainerCollection

> Provides an immutable API for managing the container element and its attributes.

[API reference](/docs/api/index.md) › [HTML Mixin](/docs/extensions/html-mixin/reference/index.md) › HasContainerCollection

| trait | `UIAwesome\Html\Mixin\HasContainerCollection` |
| --- | --- |
| Source | [`src/HasContainerCollection.php`](https://github.com/ui-awesome/html-mixin/blob/main/src/HasContainerCollection.php#L14) |

Provides an immutable API for managing the container element and its attributes.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-container"></span>`$container` protected | `bool` | Whether to render the container. Default: `false`. | `HasContainerCollection` |
| <span id="property-containerAttributes"></span>`$containerAttributes` protected | `array` | HTML attributes array for the container element. Default: `[]`. | `HasContainerCollection` |
| <span id="property-containerTag"></span>`$containerTag` protected | `false\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Tag name for the container element, or `false` to disable. Default: `false`. | `HasContainerCollection` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`container()`](#method-container) | Sets whether to render the container. | `HasContainerCollection` |
| [`containerAttributes()`](#method-containerAttributes) | Sets the container attributes. | `HasContainerCollection` |
| [`containerClass()`](#method-containerClass) | Adds a CSS class to the container element attributes. | `HasContainerCollection` |
| [`containerRemoveAttribute()`](#method-containerRemoveAttribute) | Removes a specific HTML attribute from the container element. | `HasContainerCollection` |
| [`containerSetAttribute()`](#method-containerSetAttribute) | Sets a single HTML attribute for the container element. | `HasContainerCollection` |
| [`containerTag()`](#method-containerTag) | Sets the container tag name. | `HasContainerCollection` |
| [`getContainerAttribute()`](#method-getContainerAttribute) | Returns the value of a single HTML attribute for the container element attributes. | `HasContainerCollection` |
| [`getContainerAttributes()`](#method-getContainerAttributes) | Returns the `array` of HTML attributes for the container element. | `HasContainerCollection` |
| [`getContainerTag()`](#method-getContainerTag) | Returns the tag name for the container element. | `HasContainerCollection` |
| [`isContainer()`](#method-isContainer) | Returns whether the container element should be rendered. | `HasContainerCollection` |

## Method details

### container() <span id="method-container"></span>

```php
public function container(bool $value): static
```

Sets whether to render the container.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `bool` | Set to `true` to render the container element, or `false` to skip rendering. |

**Returns**

`static`: New instance with the updated `container` value.

### containerAttributes() <span id="method-containerAttributes"></span>

```php
public function containerAttributes(array $attributes): static
```

Sets the container attributes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$attributes` | `array` | Array of attributes to apply to the container element. |

**Returns**

`static`: New instance with the updated `containerAttributes` value.

### containerClass() <span id="method-containerClass"></span>

```php
public function containerClass(string|Stringable|UnitEnum|null $value, bool $override = false): static
```

Adds a CSS class to the container element attributes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php)`\|null` | CSS class name to add. |
| `$override` | `bool` | Whether to override existing class value. |

**Returns**

`static`: New instance with the updated `containerAttributes` value.

### containerRemoveAttribute() <span id="method-containerRemoveAttribute"></span>

```php
public function containerRemoveAttribute(string|UnitEnum $key): static
```

Removes a specific HTML attribute from the container element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Attribute name to remove. |

**Returns**

`static`: New instance without the specified container attribute.

### containerSetAttribute() <span id="method-containerSetAttribute"></span>

```php
public function containerSetAttribute(string|UnitEnum $key, mixed $value): static
```

Sets a single HTML attribute for the container element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Attribute name. |
| `$value` | `mixed` | Attribute value. |

**Returns**

`static`: New instance with the updated `containerAttributes` value.

### containerTag() <span id="method-containerTag"></span>

```php
public function containerTag(false|UnitEnum $value): static
```

Sets the container tag name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `false\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Tag name for the container element, or `false` to disable. |

**Returns**

`static`: New instance with the updated `containerTag` value.

### getContainerAttribute() <span id="method-getContainerAttribute"></span>

```php
public function getContainerAttribute(string|UnitEnum $key, mixed $default = null): mixed
```

Returns the value of a single HTML attribute for the container element attributes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Attribute name. |
| `$default` | `mixed` | Default value when the attribute is missing. |

**Returns**

`mixed`: Attribute value or default.

### getContainerAttributes() <span id="method-getContainerAttributes"></span>

```php
public function getContainerAttributes(): array
```

Returns the `array` of HTML attributes for the container element.

**Returns**

`array`: Attributes `array` assigned to the container element.

### getContainerTag() <span id="method-getContainerTag"></span>

```php
public function getContainerTag(): false|UnitEnum
```

Returns the tag name for the container element.

**Returns**

`false|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php): Tag name for the container element, or `false` to disable.

### isContainer() <span id="method-isContainer"></span>

```php
public function isContainer(): bool
```

Returns whether the container element should be rendered.

**Returns**

`bool`: `true` if the container element should be rendered, or `false` to skip rendering.