# HasType

> Provides an immutable API for the type attribute of form controls.

[API reference](/docs/api/index.md) › [HTML Attribute](/docs/extensions/html-attribute/reference/index.md) › HasType

| trait | `UIAwesome\Html\Attribute\HasType` |
| --- | --- |
| Source | [`src/HasType.php`](https://github.com/ui-awesome/html-attribute/blob/main/src/HasType.php#L23) |

Used by 1 type:

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

Provides an immutable API for the `type` attribute of form controls.

Restricted to the `<input>` control types. Elements that read `type` as an open MIME hint declare their own setter
instead of using this trait.

See also: <https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#input_types>.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`type()`](#method-type) | Sets the `type` attribute. | `HasType` |

## Method details

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

```php
public function type(string|Stringable|UnitEnum|null $value): static
```

Sets the `type` attribute.

Restricts the value to the `<input>` control types. Empty and `null` values bypass validation and produce no
rendered attribute.

**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` | Input control type, or `null` to remove the attribute. |

**Returns**

`static`: New instance with the updated `type` attribute. [`Type`](/docs/extensions/html-attribute/reference/values/type/index.md) for predefined enum values.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): If a non-empty value is not an `<input>` control type.