# ElementInput

Class · category: User Interface

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/framework/input/element-input.js#L356

Handles mouse and touch events for [ElementComponent](https://api.playcanvas.com/engine/classes/ElementComponent.md)s. When input events occur on an
ElementComponent this fires the appropriate events on the ElementComponent.

Relevant Engine API examples:

- [Input events](https://playcanvas.github.io/#/user-interface/input-events)

## Constructors

### constructor

```ts
new ElementInput(domElement: Element, options?: object)
```

Create a new ElementInput instance.

**Parameters**

- `domElement` (`Element`): The DOM element.
- `options` (`object`, optional): Optional arguments.
    - `options.useMouse` (`boolean`, optional): Whether to allow mouse input. Defaults to true.
    - `options.useTouch` (`boolean`, optional): Whether to allow touch input. Defaults to true.
    - `options.useXr` (`boolean`, optional): Whether to allow XR input sources. Defaults to true.

## Methods

### addElement

```ts
addElement(element: ElementComponent): void
```

Add a [ElementComponent](https://api.playcanvas.com/engine/classes/ElementComponent.md) to the internal list of ElementComponents that are being
checked for input.

**Parameters**

- `element` ([`ElementComponent`](https://api.playcanvas.com/engine/classes/ElementComponent.md)): The
  ElementComponent.

### attach

```ts
attach(domElement: Element): void
```

Attach mouse and touch events to a DOM element.

**Parameters**

- `domElement` (`Element`): The DOM element.

### detach

```ts
detach(): void
```

Remove mouse and touch events from the DOM element that it is attached to.

### removeElement

```ts
removeElement(element: ElementComponent): void
```

Remove a [ElementComponent](https://api.playcanvas.com/engine/classes/ElementComponent.md) from the internal list of ElementComponents that are being
checked for input.

**Parameters**

- `element` ([`ElementComponent`](https://api.playcanvas.com/engine/classes/ElementComponent.md)): The
  ElementComponent.
