style: side chat title input

This commit is contained in:
Jing Hua 2023-03-10 00:15:05 +08:00
parent b080c185f4
commit 5e1745fe0c

View file

@ -1,4 +1,4 @@
import React, { MouseEventHandler, useEffect, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import useStore from '@store/store'; import useStore from '@store/store';
import ChatIcon from '@icon/ChatIcon'; import ChatIcon from '@icon/ChatIcon';
@ -69,6 +69,7 @@ const ChatHistory = ({
const [isDelete, setIsDelete] = useState<boolean>(false); const [isDelete, setIsDelete] = useState<boolean>(false);
const [isEdit, setIsEdit] = useState<boolean>(false); const [isEdit, setIsEdit] = useState<boolean>(false);
const [_title, _setTitle] = useState<string>(title); const [_title, _setTitle] = useState<string>(title);
const inputRef = useRef<HTMLInputElement>(null);
const active = currentChatIndex === chatIndex; const active = currentChatIndex === chatIndex;
@ -96,6 +97,10 @@ const ChatHistory = ({
setIsEdit(false); setIsEdit(false);
}; };
useEffect(() => {
if (inputRef && inputRef.current) inputRef.current.focus();
}, [isEdit]);
return ( return (
<a <a
className={active ? ChatHistoryClass.active : ChatHistoryClass.normal} className={active ? ChatHistoryClass.active : ChatHistoryClass.normal}
@ -106,23 +111,26 @@ const ChatHistory = ({
{isEdit ? ( {isEdit ? (
<input <input
type='text' type='text'
className='text-sm border-none bg-transparent p-0 m-0 w-full mr-0' className='focus:outline-blue-600 text-sm border-none bg-transparent p-0 m-0 w-full'
value={_title} value={_title}
onChange={(e) => { onChange={(e) => {
_setTitle(e.target.value); _setTitle(e.target.value);
}} }}
ref={inputRef}
/> />
) : ( ) : (
_title _title
)} )}
<div {isEdit || (
className={ <div
active className={
? ChatHistoryClass.activeGradient active
: ChatHistoryClass.normalGradient ? ChatHistoryClass.activeGradient
} : ChatHistoryClass.normalGradient
></div> }
/>
)}
</div> </div>
{active && ( {active && (
<div className='absolute flex right-1 z-10 text-gray-300 visible'> <div className='absolute flex right-1 z-10 text-gray-300 visible'>