# HasPrefixCollection

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

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

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

Used by 2 types:

- [`UIAwesome\Html\Core\Element\BaseInline`](/docs/extensions/html-core/reference/element/baseinline/index.md)
- [`UIAwesome\Html\Core\Element\BaseInput`](/docs/extensions/html-core/reference/element/baseinput/index.md)

Provides an immutable API for managing prefix element and its attributes.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-prefix"></span>`$prefix` protected | `string` | Prefix content string assigned to the element. Default: `''`. | `HasPrefixCollection` |
| <span id="property-prefixAttributes"></span>`$prefixAttributes` protected | `array` | HTML attributes array for the prefix element. Default: `[]`. | `HasPrefixCollection` |
| <span id="property-prefixTag"></span>`$prefixTag` protected | `false\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Tag name for the prefix element, or `false` to disable. Default: `false`. | `HasPrefixCollection` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`getPrefix()`](#method-getPrefix) | Returns the prefix content string assigned to the element. | `HasPrefixCollection` |
| [`getPrefixAttribute()`](#method-getPrefixAttribute) | Returns the value of a single HTML attribute for the prefix element attributes. | `HasPrefixCollection` |
| [`getPrefixAttributes()`](#method-getPrefixAttributes) | Returns the `array` of HTML attributes for the prefix element. | `HasPrefixCollection` |
| [`getPrefixTag()`](#method-getPrefixTag) | Returns the tag name for the prefix element. | `HasPrefixCollection` |
| [`prefix()`](#method-prefix) | Sets the prefix content string for the element. | `HasPrefixCollection` |
| [`prefixAttributes()`](#method-prefixAttributes) | Sets the HTML attributes for the prefix element. | `HasPrefixCollection` |
| [`prefixClass()`](#method-prefixClass) | Adds a CSS class to the prefix element attributes. | `HasPrefixCollection` |
| [`prefixRemoveAttribute()`](#method-prefixRemoveAttribute) | Removes a specific HTML attribute from the prefix element. | `HasPrefixCollection` |
| [`prefixSetAttribute()`](#method-prefixSetAttribute) | Sets a single HTML attribute for the prefix element. | `HasPrefixCollection` |
| [`prefixTag()`](#method-prefixTag) | Sets the tag name for the prefix element. | `HasPrefixCollection` |

## Method details

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

```php
public function getPrefix(): string
```

Returns the prefix content string assigned to the element.

**Returns**

`string`: Prefix content string assigned to the element.

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

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

Returns the value of a single HTML attribute for the prefix 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. |
| `$prefix` | `string` | Prefix to ensure (for example, `aria-`, `data-`, `on`). |

**Returns**

`mixed`: Attribute value or default.

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

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

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

**Returns**

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

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

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

Returns the tag name for the prefix element.

**Returns**

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

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

```php
public function prefix(string|Stringable ...$values): static
```

Sets the prefix content string for the element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `...$values` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Prefix content to set for the element. |

**Returns**

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

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

```php
public function prefixAttributes(array $values, string $prefix = ''): static
```

Sets the HTML attributes for the prefix element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$values` | `array` | Associative array of attribute keys and values. |
| `$prefix` | `string` | Prefix to ensure (for example, `aria-`, `data-`, `on`). |

**Returns**

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

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

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

Adds a CSS class to the prefix 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 `prefixAttributes` value.

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

```php
public function prefixRemoveAttribute(string|UnitEnum $key, string $prefix = ''): static
```

Removes a specific HTML attribute from the prefix element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Attribute name to remove. |
| `$prefix` | `string` | Prefix to ensure (for example, `aria-`, `data-`, `on`). |

**Returns**

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

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

```php
public function prefixSetAttribute(string|UnitEnum $key, mixed $value, string $prefix = ''): static
```

Sets a single HTML attribute for the prefix element.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string\|`[`UnitEnum`](https://www.php.net/manual/en/class.unitenum.php) | Attribute name. |
| `$value` | `mixed` | Attribute value. |
| `$prefix` | `string` | Prefix to ensure (for example, `aria-`, `data-`, `on`). |

**Returns**

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

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

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

Sets the tag name for the prefix element.

**Parameters**

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

**Returns**

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