# Input Interactions

Our component library supports two way interactions with components.

You can pass value to the components and also receive back any changed/entered value.

The below attributes can be used to interact with any applicable form component.

### **Getting Values/Updates from a component:**

<table><thead><tr><th>Property</th><th>Description</th><th>Type</th></tr></thead><tbody><tr><td><p></p><pre class="language-typescriptreact"><code class="lang-typescriptreact">getValue
</code></pre></td><td>This method returns the selected/entered value.<br>The method returns the selected/entered value.</td><td><strong>Method()</strong></td></tr><tr><td><p></p><pre class="language-typescriptreact"><code class="lang-typescriptreact">onChanged
</code></pre></td><td>This is an event emitted every time there is a change in current value of the component.<br>In the <strong>event.detail</strong> you will find the selected/entered value.</td><td><strong>Event Listener</strong></td></tr><tr><td><p></p><pre class="language-typescriptreact"><code class="lang-typescriptreact">onBlurred
</code></pre></td><td>This is an event emitted every time the component loses focus.<br>In the <strong>event.detail</strong> you will find the selected/entered value.</td><td><strong>Event Listener</strong></td></tr><tr><td><p></p><pre class="language-typescriptreact"><code class="lang-typescriptreact">input
</code></pre></td><td>This is the default event that is fired once the value of the element is changed.<br>You will receive the event as a value.</td><td><strong>Event Listener</strong></td></tr><tr><td><p></p><pre class="language-typescriptreact"><code class="lang-typescriptreact">keydown
</code></pre></td><td>This is the default event that is fired once any key is pressed on the element in focus.<br>You will receive the event as a value.</td><td></td></tr></tbody></table>

### **Setting/Updating Value to a component:**

<table><thead><tr><th>Property</th><th>Description</th><th>Type</th></tr></thead><tbody><tr><td><p></p><pre class="language-typescriptreact"><code class="lang-typescriptreact">setValue
</code></pre></td><td>This method sets the selected/entered value.</td><td><strong>Method()</strong></td></tr><tr><td><p></p><pre class="language-typescriptreact"><code class="lang-typescriptreact">onChanged
</code></pre></td><td>This is an event emitted every time there is a change in current value of the component.<br>In the <strong>event.detail</strong> you will find the selected/entered value.</td><td><strong>Event Listener</strong></td></tr><tr><td><p></p><pre class="language-typescriptreact"><code class="lang-typescriptreact">onBlurred
</code></pre></td><td>This is an event emitted every time the component loses focus.<br>In the <strong>event.detail</strong> you will find the selected/entered value.</td><td><strong>Event Listener</strong></td></tr></tbody></table>

### Example Usage

#### **React JS**

<pre class="language-jsx"><code class="lang-jsx">import { useState } from "react";
// Import the component
import { DdaTextarea } from "@dubai-design-system/components-react";

function App() {
      const [text, setText] = useState("");
      
      return (
<strong>            &#x3C;>
</strong>                  &#x3C;DdaTextarea
                      onInput={(event) => {
                        console.log(event.currentTarget.getValue());
                        setText(event.currentTarget.getValue());
                      }}
                  />
                  &#x3C;p>{text}&#x3C;/p>
            &#x3C;/>
      )
}

</code></pre>

#### Angular JS

app.component.ts

```javascript
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent {
  text = '';

  async handleInput(event: Event) {
    const target = event.target as any;
    const value = await target.getValue();
    console.log(value);
    this.text = value;
  }
}
```

app.component.html

```html
<dda-textarea (input)="handleInput($event)"></dda-textarea>
<p>{{ text }}</p>
```

#### Vanilla JS

```html
<div>
    <dda-textarea id="dda-textarea"></dda-textarea>
    <p id="output"></p>
</div>

<script>
      const textareaEl = document.getElementById('dda-textarea');
      const outputEl = document.getElementById('output');

      textareaEl.addEventListener('input', (event) => {
        const value = textareaEl.getValue();
        console.log(value);
        outputEl.textContent = value;
      });
</script>
```

#### Setting a Value

```jsx
import { useState } from "react";
import { DdaInput } from "@dubai-design-system/components-react";

function App() {
  const [text, setText] = useState("");
  return (
    <>
      <div className="card">
        <DdaInput
          onInput={(event) => {
            console.log(event.currentTarget.getValue());
            setText(event.currentTarget.getValue());
          }}
          id="myInputId"
        />
        <p>{text}</p>

        <button
          onClick={() => {
            document.getElementById("myInputId").setValue("Sample Value");
            setText("Sample Value");
          }}
        >
          Set Sample Value
        </button>
      </div>
    </>
  );
}

export default App;

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://designsystem.dubai.ae/developers/input-interactions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
