Textarea

Accept multiple lines of text, such as descriptions, notes, or messages.

Live preview
Interact with the component to see results here.
View code
HTML
<sy-textarea
  label="Project description"
  placeholder="Tell us about your project"
  rows="4"
  max="200"
  resize="vertical"
  size="medium"
  counter
  id="sample"
  name="description"
></sy-textarea>

Usage guide

#

Accept long, multiline text, such as notes or detailed descriptions. Use Input for a single line.

  1. Write the error message in the error slot.

    Inside the component, add <span slot="error">Error message</span>. You can include links and other guidance as well as text. For inputs supporting noNativeValidity, enable it to show this guidance instead of a browser popup. Switch always displays errors below the component.

  2. Report business rule failures with setCustomError().

    For example, if the server rejects a duplicate value, update the error slot and call setCustomError(). This method does not take a message argument. A custom error also blocks form submission.

  3. Clear the error after resolving it and check whether submission is allowed.

    Use clearCustomError() to clear a business rule error. Required-field and format validation remain active. await checkValidity() returns true or false; reportValidity() validates and displays errors. Read valid named values through FormData on submission.

Input area
Set the initial height with rows. resize="vertical" allows height adjustment while preserving width.
Length guidance
Show the character count with counter and limit length with min and max.
Required
Use required to validate empty submissions and provide error feedback.

Examples

#

Character count and maximum length

Accept up to 100 characters and display the current count.

View code
HTML
<sy-textarea
  label="Short introduction"
  counter
  max="100"
  rows="3"
  value="Great interfaces. One Syidax."
></sy-textarea>

Adjust height

Drag the bottom-right handle to resize the input vertically.

View code
HTML
<sy-textarea
  label="Notes"
  resize="vertical"
  rows="3"
></sy-textarea>

Disabled and read only

From top to bottom: default, disabled, and read only. Disabled fields cannot receive focus or input. Read-only fields keep their value but prevent editing.

View code
HTML
<div style="display:grid;gap:16px;width:100%">
  <sy-textarea rows="2" value="Project notes"></sy-textarea>
  <sy-textarea
    rows="2"
    value="Project notes"
    disabled
  ></sy-textarea>
  <sy-textarea
    rows="2"
    value="Project notes"
    readonly
  ></sy-textarea>
</div>

Events and payloads

Interact with the component and inspect the latest event name and detail. The code includes subscriptions to events emitted by this component and its children.

View code
HTML
<sy-textarea
  label="Project description"
  placeholder="Tell us about your project"
  rows="4"
  max="200"
  resize="vertical"
  size="medium"
  counter
  id="sample"
  name="description"
></sy-textarea>
<output id="demo-events" aria-live="polite">Interact with the component to see
  its latest event and payload.</output>

<script type="module">
  const describeResult = value => JSON.stringify(value, (_key, item) => {
    if (item instanceof File) return {
      name: item.name,
      size: item.size,
      type: item.type
    };
    if (item instanceof Element) return `<${item.localName}>`;
    return item;
  }) ?? 'Done';
  for (const name of ["changed", "blured", "focused"]) {
    document.addEventListener(name, event => {
      document.querySelector('#demo-events').textContent =
        `${event.target.localName} · ${name}: ${describeResult(event.detail)}`;
    });
  }
</script>

Clear existing text

Use the clear control to remove a prefilled project description.

View code
HTML
<sy-textarea
  label="Project description"
  placeholder="Tell us about your project"
  rows="4"
  max="200"
  resize="vertical"
  size="medium"
  counter
  clearable
  value="A shared workspace for the design team."
  id="sample"
  name="description"
></sy-textarea>

<script type="module">
  const component1 = document.querySelector("#sample");
  Object.assign(component1, {
    "clearable": true,
    "value": "A shared workspace for the design team."
  });
</script>

Forms and validation

Submit an empty value to trigger required-field validation. Enter a value and submit to inspect the form data, then try enabling and clearing a custom error.

View code
HTML
<form style="display:grid;gap:16px">
  <sy-textarea
    name="field"
    required
    label="Description"
    min="10"
    max="200"
    counter
    rows="3"
    id="sample"
  ><span slot="error">Enter at least 10 characters.</span></sy-textarea>
  <div style="display:flex;flex-wrap:wrap;gap:8px">
    <sy-button type="submit" variant="primary">Submit</sy-button>
    <sy-button type="reset">Reset</sy-button>
  </div>
</form>
<div class="demo-actions"
  style="display:flex;flex-wrap:wrap;gap:8px;margin-top:16px"
>
  <sy-button id="action-0" size="small">Check validity</sy-button>
  <sy-button id="action-1" size="small">Show error</sy-button>
  <sy-button id="action-2" size="small">Clear error</sy-button>
</div>
<output id="demo-result" aria-live="polite"></output>

<script type="module">
  const describeResult = value => JSON.stringify(value, (_key, item) => {
    if (item instanceof File) return {
      name: item.name,
      size: item.size,
      type: item.type
    };
    if (item instanceof Element) return `<${item.localName}>`;
    return item;
  }) ?? 'Done';
  const actionTarget0 = document.querySelector("#sample");
  document.querySelector('#action-0').addEventListener('click', async () => {
    const result = await actionTarget0.checkValidity();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
  const actionTarget1 = document.querySelector("#sample");
  document.querySelector('#action-1').addEventListener('click', async () => {
    const result = await actionTarget1.setCustomError();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
  const actionTarget2 = document.querySelector("#sample");
  document.querySelector('#action-2').addEventListener('click', async () => {
    const result = await actionTarget2.clearCustomError();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
  document.querySelector('form').addEventListener('submit', event => {
    event.preventDefault();
    document.querySelector('#demo-result').textContent = describeResult([...new FormData(event
      .currentTarget)]);
  });
</script>

Read validation results and error states

Validate before submitting or display errors on screen. Check an empty required field, then fill it to see how the return value changes. Querying the state distinguishes custom errors from required-field errors.

View code
HTML
<form style="display:grid;gap:16px">
  <sy-textarea
    name="field"
    required
    label="Description"
    min="10"
    max="200"
    counter
    rows="3"
    id="sample"
  ><span slot="error">Enter at least 10 characters.</span></sy-textarea>
  <div style="display:flex;flex-wrap:wrap;gap:8px">
    <sy-button type="submit" variant="primary">Submit</sy-button>
    <sy-button type="reset">Reset</sy-button>
  </div>
</form>
<div class="demo-actions"
  style="display:flex;flex-wrap:wrap;gap:8px;margin-top:16px"
>
  <sy-button id="action-0" size="small">Check validity</sy-button>
  <sy-button id="action-1" size="small">Show error</sy-button>
  <sy-button id="action-2" size="small">Clear error</sy-button>
  <sy-button id="action-3" size="small">Validate with errors</sy-button>
  <sy-button id="action-4" size="small">Query validation state</sy-button>
</div>
<output id="demo-result" aria-live="polite"></output>

<script type="module">
  const describeResult = value => JSON.stringify(value, (_key, item) => {
    if (item instanceof File) return {
      name: item.name,
      size: item.size,
      type: item.type
    };
    if (item instanceof Element) return `<${item.localName}>`;
    return item;
  }) ?? 'Done';
  const actionTarget0 = document.querySelector("#sample");
  document.querySelector('#action-0').addEventListener('click', async () => {
    const result = await actionTarget0.checkValidity();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
  const actionTarget1 = document.querySelector("#sample");
  document.querySelector('#action-1').addEventListener('click', async () => {
    const result = await actionTarget1.setCustomError();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
  const actionTarget2 = document.querySelector("#sample");
  document.querySelector('#action-2').addEventListener('click', async () => {
    const result = await actionTarget2.clearCustomError();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
  const actionTarget3 = document.querySelector("#sample");
  document.querySelector('#action-3').addEventListener('click', async () => {
    const result = await actionTarget3.reportValidity();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
  const actionTarget4 = document.querySelector("#sample");
  document.querySelector('#action-4').addEventListener('click', async () => {
    const result = await actionTarget4.getStatus();
    document.querySelector('#demo-result').textContent = describeResult(result);
  });
  document.querySelector('form').addEventListener('submit', event => {
    event.preventDefault();
    document.querySelector('#demo-result').textContent = describeResult([...new FormData(event
      .currentTarget)]);
  });
</script>

Custom error messages

Display a custom error for server-side duplicate checks or business rules. Change the message below and submit to verify that it is blocked. After clearing the error, required-field constraints must still be satisfied.

View code
HTML
<label for="error-message">Error message to display</label><input
  id="error-message"
  value="The server did not accept this value. Please review it."
  type="text"
>
<form style="display:grid;gap:16px">
  <sy-textarea
    nonativevalidity
    name="field"
    required
    label="Description"
    min="10"
    max="200"
    counter
    rows="3"
    id="sample"
  ><span slot="error">Enter at least 10 characters.</span></sy-textarea>
  <div style="display:flex;flex-wrap:wrap;gap:8px">
    <sy-button type="submit" variant="primary">Submit</sy-button>
    <sy-button type="reset">Reset</sy-button>
  </div>
</form>
<div class="demo-actions">
  <sy-button id="show-custom-error" variant="primary">Show error</sy-button>
  <sy-button id="clear-custom-error">Clear error</sy-button>
</div>
<output id="custom-error-result" aria-live="polite"></output>
<output id="demo-result" aria-live="polite"></output>

<script type="module">
  const describeResult = value => JSON.stringify(value, (_key, item) => {
    if (item instanceof File) return {
      name: item.name,
      size: item.size,
      type: item.type
    };
    if (item instanceof Element) return `<${item.localName}>`;
    return item;
  }) ?? 'Done';
  await (async function customErrorSetup(root) {
    const field = root.querySelector('#sample');
    const message = root.querySelector('[slot="error"]');
    const input = root.querySelector('#error-message');
    const output = root.querySelector('#custom-error-result');
    const update = async () => {
      message.textContent = input.value.trim() || _msg("m_4eea8cef81c6");
      await field.setCustomError();
      output.textContent = _msg("m_e00bd46236d3", [message.textContent]);
    };
    input.addEventListener('input', update);
    root.querySelector('#show-custom-error').addEventListener('click', update);
    root.querySelector('#clear-custom-error').addEventListener('click', async () => {
      await field.clearCustomError();
      output.textContent = await field.checkValidity() ? _msg("m_c454251167b2") : _msg(
        "m_5b8cb48627e5");
    });
    root.querySelector('form').addEventListener('invalid', () => {
      output.textContent = _msg("m_c702c7778166");
    }, true);
    root.querySelector('form').addEventListener('reset', () => {
      output.textContent = _msg("m_b90c2b4dc30f");
    });
    await update();
  })(document);
  document.querySelector('form').addEventListener('submit', event => {
    event.preventDefault();
    document.querySelector('#demo-result').textContent = describeResult([...new FormData(event
      .currentTarget)]);
  });
</script>

API reference

#

Hover over a name or focus it with the keyboard to see the code. On touch screens, tap the name.

<sy-textarea>

Properties

Attribute / PropertyTypeDefaultDescription
booleanfalseFocus the input when it first connects.
booleanfalseHide the default border.
booleanfalseShow a button to clear the current value.
booleanfalseShow the input character count.
booleanfalseBlock user interaction and keyboard focus.
string""Label describing the item.
numberNumber.MAX_SAFE_INTEGERMaximum input character count.
number0Minimum required character count.
string""Placeholder shown when the value is empty.
booleanfalseDisplay the current value while preventing edits.
booleanfalseFail form validation when no value is provided.
"none" | "horizontal" | "vertical" | "both""none"Directions in which the user can resize.
number4Default number of rows in the input area.
"small" | "medium" | "large""medium"Component size.
'default' | 'warning' | 'error' | 'success''default'Visually represent default, success, warning, or error states.
string""Current value or item identifier.
string""Field name used in FormData.
booleanfalseUse the app's error UI instead of the browser's built-in error display. checkValidity still performs validation.

Events

EventDetailDescription
CustomEvent<{ value: string; length: number; isValid: boolean; status: string }>Emitted when the value or selection state changes.
CustomEvent<{ value: string; isValid: boolean; status: string }>Emitted when focus is lost.
CustomEvent<{ value: string; isValid: boolean; status: string }>Emitted when focus is received.

Methods

MethodReturnsDescription
Promise<void>Move keyboard focus to the input or action element.
Promise<void>Remove focus from the input element.
Promise<boolean>Return true if the current constraints are satisfied, otherwise false.
Promise<boolean>Validate the current value and display errors to the user.
Promise<void>Set a custom error state.
Promise<void>Clear the custom error state.
Promise<"" | "custom" | "valueMissing" | "tooShort" | "tooLong">Return the current validation state.

Slots

SlotDescription
Validation error message.