29 lines
947 B
JavaScript
29 lines
947 B
JavaScript
// Rôle : conserve le brouillon d'un mémo et ajuste la hauteur de son champ.
|
|
import { useLayoutEffect } from "react";
|
|
import { useInlineEdit } from "../../../hooks/useInlineEdit.js";
|
|
|
|
export function MemoTextEditor({ text, textContent, onCommit }) {
|
|
const { draft, setDraft, inputRef, commit } = useInlineEdit({ value: text, onCommit, commitUnchanged: true });
|
|
|
|
useLayoutEffect(() => {
|
|
const element = inputRef.current;
|
|
if (!element) return;
|
|
element.style.height = "auto";
|
|
element.style.height = `${element.scrollHeight + 2}px`;
|
|
});
|
|
|
|
return (
|
|
<textarea
|
|
className="nds-textarea"
|
|
data-size="sm"
|
|
data-variant="ghost"
|
|
ref={inputRef}
|
|
value={draft}
|
|
rows={3}
|
|
placeholder={textContent.placeholder || "Mémo court..."}
|
|
onChange={(event) => setDraft(event.target.value)}
|
|
onBlur={() => commit()}
|
|
aria-label={textContent.editLabel || "Modifier le mémo"}
|
|
/>
|
|
);
|
|
}
|