<div class="demo-caption">A comment with a character count</div>
<form class="demo-comment" id="demo-comment">
<ray-avatar name="Ada Lovelace" color="pink" size="md"></ray-avatar>
<div class="demo-comment-body">
<ray-textarea id="demo-comment-text" name="comment" aria-label="Write a comment" placeholder="Write a comment… (⌘↵ to post)" autosize max-rows="8"></ray-textarea>
<div class="demo-comment-bar">
<span class="demo-muted" id="demo-comment-count">0 / 280</span>
<span class="demo-actions"><ray-button variant="subtle" size="xs" type="reset">Cancel</ray-button><ray-button size="xs" type="submit" id="demo-comment-post" disabled>Post</ray-button></span>
</div>
<ul class="demo-comments" id="demo-comments"></ul>
</div>
</form>
<div class="demo-caption">Autosize, rows and read-only</div>
<div class="demo-grid">
<ray-textarea label="Autosize" description="Grows with the text, up to six rows." autosize max-rows="6">Type a few lines here and watch it grow.</ray-textarea>
<ray-textarea label="Six rows" rows="6" placeholder="A fixed height, with a scrollbar when it overflows."></ray-textarea>
<ray-textarea label="Release notes" readonly rows="4" description="Read-only: selectable and focusable, not editable.">1.27.39 — faster startup, per-page modules, and the sidebar keeps its scroll.</ray-textarea>
</div>
<div class="demo-caption">Variants, sizes and states</div>
<div class="demo-grid">
<ray-textarea label="Filled" variant="filled" placeholder="Filled background"></ray-textarea>
<ray-textarea label="Large" size="lg" placeholder="Larger text and padding"></ray-textarea>
<ray-textarea label="Bio" required error="Tell us a little about yourself." placeholder="Required"></ray-textarea>
<ray-textarea label="Disabled" disabled>Not editable, not submitted.</ray-textarea>
</div>
<script type="module">
const form = document.getElementById("demo-comment");
const text = document.getElementById("demo-comment-text");
const post = document.getElementById("demo-comment-post");
const count = document.getElementById("demo-comment-count");
const MAX = 280;
const check = () => {
const n = (text.value ?? "").length;
count.textContent = `${n} / ${MAX}`;
count.toggleAttribute("data-over", n > MAX);
text.error = n > MAX ? `${n - MAX} character${n - MAX === 1 ? "" : "s"} too many.` : "";
post.disabled = n === 0 || n > MAX;
};
text.addEventListener("input", check);
text.addEventListener("keydown", (e) => { if (e.key === "Enter" && (e.metaKey || e.ctrlKey) && !post.disabled) form.requestSubmit(); });
form.addEventListener("submit", (e) => {
e.preventDefault();
const li = document.createElement("li");
li.textContent = text.value;
document.getElementById("demo-comments").prepend(li);
text.value = "";
check();
});
form.addEventListener("reset", () => queueMicrotask(check));
</script>
import { RayAvatar, RayTextarea, RayButton } from "@raylang/react";
export function TextareaExample() {
return (
<>
<div className="demo-caption">A comment with a character count</div>
<form className="demo-comment" id="demo-comment">
<RayAvatar name="Ada Lovelace" color="pink" size="md" />
<div className="demo-comment-body">
<RayTextarea id="demo-comment-text" name="comment" aria-label="Write a comment" placeholder="Write a comment… (⌘↵ to post)" autosize maxRows={8} />
<div className="demo-comment-bar">
<span className="demo-muted" id="demo-comment-count">0 / 280</span>
<span className="demo-actions"><RayButton variant="subtle" size="xs" type="reset">Cancel</RayButton><RayButton size="xs" type="submit" id="demo-comment-post" disabled>Post</RayButton></span>
</div>
<ul className="demo-comments" id="demo-comments" />
</div>
</form>
<div className="demo-caption">Autosize, rows and read-only</div>
<div className="demo-grid">
<RayTextarea label="Autosize" description="Grows with the text, up to six rows." autosize maxRows={6}>Type a few lines here and watch it grow.</RayTextarea>
<RayTextarea label="Six rows" rows={6} placeholder="A fixed height, with a scrollbar when it overflows." />
<RayTextarea label="Release notes" readonly rows={4} description="Read-only: selectable and focusable, not editable.">1.27.39 — faster startup, per-page modules, and the sidebar keeps its scroll.</RayTextarea>
</div>
<div className="demo-caption">Variants, sizes and states</div>
<div className="demo-grid">
<RayTextarea label="Filled" variant="filled" placeholder="Filled background" />
<RayTextarea label="Large" size="lg" placeholder="Larger text and padding" />
<RayTextarea label="Bio" required error="Tell us a little about yourself." placeholder="Required" />
<RayTextarea label="Disabled" disabled>Not editable, not submitted.</RayTextarea>
</div>
</>
);
}
<template>
<div class="demo-caption">A comment with a character count</div>
<form class="demo-comment" id="demo-comment">
<RayAvatar name="Ada Lovelace" color="pink" size="md" />
<div class="demo-comment-body">
<RayTextarea id="demo-comment-text" name="comment" aria-label="Write a comment" placeholder="Write a comment… (⌘↵ to post)" autosize :max-rows="8" />
<div class="demo-comment-bar">
<span class="demo-muted" id="demo-comment-count">0 / 280</span>
<span class="demo-actions"><RayButton variant="subtle" size="xs" type="reset">Cancel</RayButton><RayButton size="xs" type="submit" id="demo-comment-post" disabled>Post</RayButton></span>
</div>
<ul class="demo-comments" id="demo-comments"></ul>
</div>
</form>
<div class="demo-caption">Autosize, rows and read-only</div>
<div class="demo-grid">
<RayTextarea label="Autosize" description="Grows with the text, up to six rows." autosize :max-rows="6">Type a few lines here and watch it grow.</RayTextarea>
<RayTextarea label="Six rows" :rows="6" placeholder="A fixed height, with a scrollbar when it overflows." />
<RayTextarea label="Release notes" readonly :rows="4" description="Read-only: selectable and focusable, not editable.">1.27.39 — faster startup, per-page modules, and the sidebar keeps its scroll.</RayTextarea>
</div>
<div class="demo-caption">Variants, sizes and states</div>
<div class="demo-grid">
<RayTextarea label="Filled" variant="filled" placeholder="Filled background" />
<RayTextarea label="Large" size="lg" placeholder="Larger text and padding" />
<RayTextarea label="Bio" required error="Tell us a little about yourself." placeholder="Required" />
<RayTextarea label="Disabled" disabled>Not editable, not submitted.</RayTextarea>
</div>
</template>