mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-17 09:59:10 +00:00
add databinding for editor actions and message
This commit is contained in:
parent
67fac31ab4
commit
b0c8b2378b
7 changed files with 57 additions and 16 deletions
|
@ -94,18 +94,27 @@ const StyledTextarea = styled.textarea`
|
|||
export const MultilineTextInput = (
|
||||
props: TextInputProps<HTMLTextAreaElement> & { rows?: number }
|
||||
) => {
|
||||
const { ...rest } = props;
|
||||
const { children, ...rest } = props;
|
||||
const [value, setValue] = React.useState(String(props.value));
|
||||
const rows = Math.min(10, Math.max(props.rows || 2, value.split(/\r?\n/).length));
|
||||
const rows = React.useMemo(
|
||||
() => Math.min(10, Math.max(props.rows || 2, value.split(/\r?\n/).length)),
|
||||
[value]
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
setValue(String(props.value));
|
||||
}, [props.value]);
|
||||
|
||||
return (
|
||||
<StyledTextarea
|
||||
{...rest}
|
||||
rows={rows}
|
||||
value={value}
|
||||
onChange={(eventData) => {
|
||||
setValue(eventData.target.value);
|
||||
props.onChange?.(eventData);
|
||||
}}
|
||||
/>
|
||||
>
|
||||
{value}
|
||||
</StyledTextarea>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue