mirror of
https://github.com/mastodon/mastodon.git
synced 2026-05-03 11:57:17 -05:00
Add Cmd/Ctrl+Enter to submit when Textarea is focused (#37821)
This commit is contained in:
parent
c53bb3b33e
commit
8c2c94fa6c
|
|
@ -1,5 +1,5 @@
|
||||||
import type { ComponentPropsWithoutRef } from 'react';
|
import type { ComponentPropsWithoutRef } from 'react';
|
||||||
import { forwardRef } from 'react';
|
import { forwardRef, useCallback } from 'react';
|
||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
|
@ -36,12 +36,26 @@ TextAreaField.displayName = 'TextAreaField';
|
||||||
export const TextArea = forwardRef<
|
export const TextArea = forwardRef<
|
||||||
HTMLTextAreaElement,
|
HTMLTextAreaElement,
|
||||||
ComponentPropsWithoutRef<'textarea'>
|
ComponentPropsWithoutRef<'textarea'>
|
||||||
>(({ className, ...otherProps }, ref) => (
|
>(({ className, onKeyDown, ...otherProps }, ref) => {
|
||||||
|
const handleSubmitHotkey = useCallback(
|
||||||
|
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
|
onKeyDown?.(e);
|
||||||
|
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
|
||||||
|
const targetForm = e.currentTarget.form;
|
||||||
|
targetForm?.requestSubmit();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[onKeyDown],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
<textarea
|
<textarea
|
||||||
{...otherProps}
|
{...otherProps}
|
||||||
|
onKeyDown={handleSubmitHotkey}
|
||||||
className={classNames(className, classes.input)}
|
className={classNames(className, classes.input)}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
/>
|
/>
|
||||||
));
|
);
|
||||||
|
});
|
||||||
|
|
||||||
TextArea.displayName = 'TextArea';
|
TextArea.displayName = 'TextArea';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user