Improve chat panel keyboard navigation
- Focus input field when plus button is clicked - Close menu when 'Escape' key is pressed - Refactor menu navigation for better readability
This commit is contained in:
parent
039a6d0b22
commit
64ba8612c6
@ -50,6 +50,7 @@ const chatPanel = () => {
|
||||
const handlePlusClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
setMenuType('contexts');
|
||||
setMenuOpend(!menuOpend);
|
||||
inputRef.current.focus();
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
@ -289,7 +290,11 @@ const chatPanel = () => {
|
||||
};
|
||||
|
||||
const handleKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (menuOpend && menuType === 'commands') {
|
||||
if (menuOpend) {
|
||||
if (event.key === 'Escape') {
|
||||
setMenuOpend(false);
|
||||
}
|
||||
if (menuType === 'commands') {
|
||||
if (event.key === 'ArrowDown') {
|
||||
const newIndex = currentMenuIndex + 1;
|
||||
setCurrentMenuIndex(newIndex < commandMenusNode.length ? newIndex : 0);
|
||||
@ -306,6 +311,7 @@ const chatPanel = () => {
|
||||
setMenuOpend(false);
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (event.key === 'Enter' && !event.shiftKey) {
|
||||
handleSendClick(event as any);
|
||||
|
Loading…
x
Reference in New Issue
Block a user