mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-03 04:50:14 +08:00
I think the idea behind that feature was to trigger the submit flow when user was pressing enter on a form instead of going to the new line which was usefull when user was using the textarea as a way to copy and paste their private key. Now there's a better approach for this, this was likely dead code
36 lines
969 B
JavaScript
36 lines
969 B
JavaScript
import React, { useRef, useState, useLayoutEffect } from "react";
|
|
|
|
import "./textarea.scss";
|
|
|
|
export function Textarea({ ...props }) {
|
|
const $el = useRef();
|
|
const [className, setClassName] = useState(
|
|
"component_textarea" +
|
|
(/Firefox/.test(navigator.userAgent) ? " firefox" : "") +
|
|
(props.value && props.value.length > 0 ? " hasText" : ""),
|
|
);
|
|
|
|
useLayoutEffect(() => {
|
|
if ($el.current && $el.current.value.length > 0 &&
|
|
className.indexOf("hasText") === -1) {
|
|
setClassName(`${className} hasText`);
|
|
}
|
|
}, []);
|
|
|
|
const inputProps = (p) => {
|
|
return Object.keys(p).reduce((acc, key) => {
|
|
if (key === "disabledEnter") return acc;
|
|
acc[key] = p[key];
|
|
return acc;
|
|
}, {});
|
|
};
|
|
|
|
return (
|
|
<textarea
|
|
{...inputProps(props)}
|
|
className={className}
|
|
ref={$el}>
|
|
</textarea>
|
|
);
|
|
}
|