mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
fixed ref forwarding on textareas
This commit is contained in:
parent
2b7b756212
commit
140e36b6b7
5 changed files with 58 additions and 44 deletions
|
@ -1,14 +1,18 @@
|
|||
import React, { FC, KeyboardEventHandler, useCallback } from 'react';
|
||||
import React, {
|
||||
forwardRef,
|
||||
KeyboardEventHandler,
|
||||
TextareaHTMLAttributes,
|
||||
useCallback,
|
||||
} from 'react';
|
||||
import { Textarea } from '~/components/input/Textarea';
|
||||
import { useCommentFormContext } from '~/hooks/comments/useCommentFormFormik';
|
||||
import { useRandomPhrase } from '~/constants/phrases';
|
||||
|
||||
interface IProps {
|
||||
interface IProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
|
||||
isLoading?: boolean;
|
||||
setRef?: (r: HTMLTextAreaElement) => void;
|
||||
}
|
||||
|
||||
const LocalCommentFormTextarea: FC<IProps> = ({ setRef }) => {
|
||||
const LocalCommentFormTextarea = forwardRef<HTMLTextAreaElement, IProps>(({ ...rest }, ref) => {
|
||||
const { values, handleChange, handleSubmit, isSubmitting } = useCommentFormContext();
|
||||
|
||||
const onKeyDown = useCallback<KeyboardEventHandler<HTMLTextAreaElement>>(
|
||||
|
@ -22,14 +26,15 @@ const LocalCommentFormTextarea: FC<IProps> = ({ setRef }) => {
|
|||
|
||||
return (
|
||||
<Textarea
|
||||
{...rest}
|
||||
ref={ref}
|
||||
value={values.text}
|
||||
handler={handleChange('text')}
|
||||
onKeyDown={onKeyDown}
|
||||
disabled={isSubmitting}
|
||||
placeholder={placeholder}
|
||||
ref={setRef}
|
||||
/>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
export { LocalCommentFormTextarea };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue