feat(textarea): handle "/" keys
This commit is contained in:
parent
92abbc5b98
commit
c4f52adb45
|
@ -18,14 +18,21 @@ const EmptyChatMessageInput = ({
|
||||||
|
|
||||||
const inputRef = useRef<HTMLTextAreaElement | null>(null);
|
const inputRef = useRef<HTMLTextAreaElement | null>(null);
|
||||||
|
|
||||||
const handleKeyDown = (e: KeyboardEvent) => {
|
|
||||||
if (e.key === '/') {
|
|
||||||
e.preventDefault();
|
|
||||||
inputRef.current?.focus();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
const activeElement = document.activeElement;
|
||||||
|
|
||||||
|
const isInputFocused =
|
||||||
|
activeElement?.tagName === 'INPUT' ||
|
||||||
|
activeElement?.tagName === 'TEXTAREA' ||
|
||||||
|
activeElement?.hasAttribute('contenteditable');
|
||||||
|
|
||||||
|
if (e.key === '/' && !isInputFocused) {
|
||||||
|
e.preventDefault();
|
||||||
|
inputRef.current?.focus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
document.addEventListener('keydown', handleKeyDown);
|
document.addEventListener('keydown', handleKeyDown);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|
|
@ -27,14 +27,21 @@ const MessageInput = ({
|
||||||
|
|
||||||
const inputRef = useRef<HTMLTextAreaElement | null>(null);
|
const inputRef = useRef<HTMLTextAreaElement | null>(null);
|
||||||
|
|
||||||
const handleKeyDown = (e: KeyboardEvent) => {
|
|
||||||
if (e.key === '/') {
|
|
||||||
e.preventDefault();
|
|
||||||
inputRef.current?.focus();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
const activeElement = document.activeElement;
|
||||||
|
|
||||||
|
const isInputFocused =
|
||||||
|
activeElement?.tagName === 'INPUT' ||
|
||||||
|
activeElement?.tagName === 'TEXTAREA' ||
|
||||||
|
activeElement?.hasAttribute('contenteditable');
|
||||||
|
|
||||||
|
if (e.key === '/' && !isInputFocused) {
|
||||||
|
e.preventDefault();
|
||||||
|
inputRef.current?.focus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
document.addEventListener('keydown', handleKeyDown);
|
document.addEventListener('keydown', handleKeyDown);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|
Loading…
Reference in New Issue