Skip to content

Commit c1ff87d

Browse files
committed
Use autogrowing textareas in dialogs
1 parent e83f39e commit c1ff87d

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Next version
1919
- Added styles to selected nodes so that e.g. selected horizontal rules are
2020
shown as such.
2121
- Started including source maps again.
22+
- Convert textareas to use autogrow.
2223

2324

2425
0.11 (2025-04-16)

django_prose_editor/static/django_prose_editor/editor.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

django_prose_editor/static/django_prose_editor/editor.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/editor.css

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@
189189

190190
.prose-editor-dialog input:not([type="checkbox"], [type="radio"]),
191191
.prose-editor-dialog select,
192-
.prose-editor-dialog textarea {
192+
.prose-editor-dialog textarea,
193+
.prose-editor-grow-wrap::after {
193194
width: 100%;
194195
padding: 0.5em;
195196
border: 1px solid var(--_r);
@@ -199,6 +200,7 @@
199200
transition:
200201
border-color 0.2s,
201202
box-shadow 0.2s;
203+
font: inherit;
202204
}
203205

204206
.prose-editor-dialog input:focus,
@@ -340,3 +342,25 @@ label:empty:has(+ .prose-editor) {
340342
max-width: 100%;
341343
height: auto;
342344
}
345+
346+
/* Autogrowing textareas */
347+
.prose-editor-grow-wrap {
348+
display: grid;
349+
}
350+
.prose-editor-grow-wrap::after {
351+
content: attr(data-value) " ";
352+
white-space: pre-wrap;
353+
visibility: hidden;
354+
}
355+
.prose-editor-grow-wrap > textarea {
356+
resize: none;
357+
overflow: hidden;
358+
}
359+
.prose-editor-grow-wrap > textarea,
360+
.prose-editor-grow-wrap::after {
361+
border: 1px solid black;
362+
padding: 0.5rem;
363+
font: inherit;
364+
365+
grid-area: 1 / 1 / 2 / 2;
366+
}

src/utils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ const formFieldForProperty = (name, config, attrValue, id) => {
3030
])
3131
}
3232
if (config.format === "textarea") {
33-
widget = crel("textarea", { id, name, value, cols: 80, rows: 30 })
33+
const textarea = crel("textarea", { id, name, value, cols: 80, rows: 3 })
34+
widget = crel(
35+
"div",
36+
{ className: "prose-editor-grow-wrap", "data-value": textarea.value },
37+
[textarea],
38+
)
39+
textarea.addEventListener("input", () => {
40+
widget.dataset.value = textarea.value
41+
})
3442
} else if (config.enum) {
3543
widget = crel(
3644
"select",

0 commit comments

Comments
 (0)