From ac608431835bdbaeb3117d45abed722eac7e67a5 Mon Sep 17 00:00:00 2001 From: Joel Jacob Stephen <70131076+JoelJacobStephen@users.noreply.github.com> Date: Tue, 22 Aug 2023 20:10:41 +0530 Subject: [PATCH] refactor: autofocus can be disabled in smart input hopp ui component (#3273) Co-authored-by: Liyas Thomas --- .../hoppscotch-common/src/components.d.ts | 4 ++- .../src/components/collections/index.vue | 5 ++-- .../src/components/settings/Proxy.vue | 10 ++----- .../hoppscotch-common/src/pages/profile.vue | 4 ++- .../src/pages/realtime/websocket.vue | 1 + .../src/components/smart/Input.vue | 30 +++++++++++++------ 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index 6937ebc79..84f34ccc4 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -89,12 +89,13 @@ declare module 'vue' { HoppButtonPrimary: typeof import('@hoppscotch/ui')['HoppButtonPrimary'] HoppButtonSecondary: typeof import('@hoppscotch/ui')['HoppButtonSecondary'] HoppSmartAnchor: typeof import('@hoppscotch/ui')['HoppSmartAnchor'] - HoppSmartAutoComplete: typeof import('@hoppscotch/ui')['HoppSmartAutoComplete'] + HoppSmartAutoComplete: typeof import("@hoppscotch/ui")["HoppSmartAutoComplete"] HoppSmartCheckbox: typeof import('@hoppscotch/ui')['HoppSmartCheckbox'] HoppSmartConfirmModal: typeof import('@hoppscotch/ui')['HoppSmartConfirmModal'] HoppSmartExpand: typeof import('@hoppscotch/ui')['HoppSmartExpand'] HoppSmartFileChip: typeof import('@hoppscotch/ui')['HoppSmartFileChip'] HoppSmartInput: typeof import('@hoppscotch/ui')['HoppSmartInput'] + HoppSmartIntersection: typeof import('@hoppscotch/ui')['HoppSmartIntersection'] HoppSmartItem: typeof import('@hoppscotch/ui')['HoppSmartItem'] HoppSmartLink: typeof import('@hoppscotch/ui')['HoppSmartLink'] HoppSmartModal: typeof import('@hoppscotch/ui')['HoppSmartModal'] @@ -152,6 +153,7 @@ declare module 'vue' { IconLucideMinus: typeof import('~icons/lucide/minus')['default'] IconLucideSearch: typeof import('~icons/lucide/search')['default'] IconLucideUsers: typeof import('~icons/lucide/users')['default'] + IconLucideVerified: typeof import('~icons/lucide/verified')['default'] InterceptorsExtensionSubtitle: typeof import('./components/interceptors/ExtensionSubtitle.vue')['default'] LensesHeadersRenderer: typeof import('./components/lenses/HeadersRenderer.vue')['default'] LensesHeadersRendererEntry: typeof import('./components/lenses/HeadersRendererEntry.vue')['default'] diff --git a/packages/hoppscotch-common/src/components/collections/index.vue b/packages/hoppscotch-common/src/components/collections/index.vue index d8ad1c0b9..1d2a69fa2 100644 --- a/packages/hoppscotch-common/src/components/collections/index.vue +++ b/packages/hoppscotch-common/src/components/collections/index.vue @@ -19,11 +19,12 @@ > - diff --git a/packages/hoppscotch-common/src/components/settings/Proxy.vue b/packages/hoppscotch-common/src/components/settings/Proxy.vue index f5ff15ff8..2ec386aa3 100644 --- a/packages/hoppscotch-common/src/components/settings/Proxy.vue +++ b/packages/hoppscotch-common/src/components/settings/Proxy.vue @@ -21,17 +21,13 @@
- - + />
@@ -102,6 +102,7 @@ @@ -124,6 +125,7 @@ diff --git a/packages/hoppscotch-common/src/pages/realtime/websocket.vue b/packages/hoppscotch-common/src/pages/realtime/websocket.vue index 89e740403..3d839b177 100644 --- a/packages/hoppscotch-common/src/pages/realtime/websocket.vue +++ b/packages/hoppscotch-common/src/pages/realtime/websocket.vue @@ -7,6 +7,7 @@ import { onKeyStroke, useVModel } from "@vueuse/core" -import { defineProps, ref } from "vue" +import { defineProps, onMounted, ref, nextTick } from "vue" // Unique ID for input const inputID = `input-${inputIDCounter++}` +const inputRef = ref() + +onMounted(async () => { + if (props.autofocus) { + await nextTick() + inputRef.value?.focus() + } +}) + const props = withDefaults( defineProps<{ id: string @@ -47,6 +55,7 @@ const props = withDefaults( type: string label: string disabled: boolean + autofocus: boolean }>(), { id: "", @@ -57,6 +66,7 @@ const props = withDefaults( type: "text", label: "", disabled: false, + autofocus: true, } ) @@ -65,13 +75,15 @@ const emit = defineEmits<{ (e: "update:modelValue", v: string): void }>() -const inputRef = ref() - const inputText = useVModel(props, "modelValue", emit) -onKeyStroke("Enter", (e) => { - if (!e.repeat) { - return emit("submit") - } -}, { target: inputRef, eventName: "keydown" }) +onKeyStroke( + "Enter", + (e) => { + if (!e.repeat) { + return emit("submit") + } + }, + { target: inputRef, eventName: "keydown" } +)