Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix(ui): fix the problem of triggering the form submit method by mistake

robin33637c017311
diff --git a/ui/src/components/TagSelector/index.tsx b/ui/src/components/TagSelector/index.tsx
index 4cb72a83..5a2279e5 100644
--- a/ui/src/components/TagSelector/index.tsx
+++ b/ui/src/components/TagSelector/index.tsx
@@ -155,6 +155,7 @@ const TagSelector: FC<IProps> = ({
};
const handleKeyDown = (e) => {
e.stopPropagation();
+
if (!tags) {
return;
}
@@ -166,13 +167,20 @@ const TagSelector: FC<IProps> = ({
if (keyCode === 40 && currentIndex < tags.length - 1) {
setCurrentIndex(currentIndex + 1);
}
- if (
- keyCode === 13 &&
- currentIndex > -1 &&
- currentIndex <= tags.length - 1
- ) {
+
+ if (keyCode === 13 && currentIndex > -1) {
e.preventDefault();
- handleClick(tags[currentIndex]);
+
+ if (tags.length === 0) {
+ tagModal.onShow(tag);
+ return;
+ }
+ if (currentIndex <= tags.length - 1) {
+ handleClick(tags[currentIndex]);
+ if (currentIndex === tags.length - 1 && currentIndex > 0) {
+ setCurrentIndex(currentIndex - 1);
+ }
+ }
}
};
return (