refactor: autofocus can be disabled in smart input hopp ui component (#3273)
Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
This commit is contained in:
committed by
GitHub
parent
3c3fb1e4a9
commit
ac60843183
@@ -89,12 +89,13 @@ declare module 'vue' {
|
|||||||
HoppButtonPrimary: typeof import('@hoppscotch/ui')['HoppButtonPrimary']
|
HoppButtonPrimary: typeof import('@hoppscotch/ui')['HoppButtonPrimary']
|
||||||
HoppButtonSecondary: typeof import('@hoppscotch/ui')['HoppButtonSecondary']
|
HoppButtonSecondary: typeof import('@hoppscotch/ui')['HoppButtonSecondary']
|
||||||
HoppSmartAnchor: typeof import('@hoppscotch/ui')['HoppSmartAnchor']
|
HoppSmartAnchor: typeof import('@hoppscotch/ui')['HoppSmartAnchor']
|
||||||
HoppSmartAutoComplete: typeof import('@hoppscotch/ui')['HoppSmartAutoComplete']
|
HoppSmartAutoComplete: typeof import("@hoppscotch/ui")["HoppSmartAutoComplete"]
|
||||||
HoppSmartCheckbox: typeof import('@hoppscotch/ui')['HoppSmartCheckbox']
|
HoppSmartCheckbox: typeof import('@hoppscotch/ui')['HoppSmartCheckbox']
|
||||||
HoppSmartConfirmModal: typeof import('@hoppscotch/ui')['HoppSmartConfirmModal']
|
HoppSmartConfirmModal: typeof import('@hoppscotch/ui')['HoppSmartConfirmModal']
|
||||||
HoppSmartExpand: typeof import('@hoppscotch/ui')['HoppSmartExpand']
|
HoppSmartExpand: typeof import('@hoppscotch/ui')['HoppSmartExpand']
|
||||||
HoppSmartFileChip: typeof import('@hoppscotch/ui')['HoppSmartFileChip']
|
HoppSmartFileChip: typeof import('@hoppscotch/ui')['HoppSmartFileChip']
|
||||||
HoppSmartInput: typeof import('@hoppscotch/ui')['HoppSmartInput']
|
HoppSmartInput: typeof import('@hoppscotch/ui')['HoppSmartInput']
|
||||||
|
HoppSmartIntersection: typeof import('@hoppscotch/ui')['HoppSmartIntersection']
|
||||||
HoppSmartItem: typeof import('@hoppscotch/ui')['HoppSmartItem']
|
HoppSmartItem: typeof import('@hoppscotch/ui')['HoppSmartItem']
|
||||||
HoppSmartLink: typeof import('@hoppscotch/ui')['HoppSmartLink']
|
HoppSmartLink: typeof import('@hoppscotch/ui')['HoppSmartLink']
|
||||||
HoppSmartModal: typeof import('@hoppscotch/ui')['HoppSmartModal']
|
HoppSmartModal: typeof import('@hoppscotch/ui')['HoppSmartModal']
|
||||||
@@ -152,6 +153,7 @@ declare module 'vue' {
|
|||||||
IconLucideMinus: typeof import('~icons/lucide/minus')['default']
|
IconLucideMinus: typeof import('~icons/lucide/minus')['default']
|
||||||
IconLucideSearch: typeof import('~icons/lucide/search')['default']
|
IconLucideSearch: typeof import('~icons/lucide/search')['default']
|
||||||
IconLucideUsers: typeof import('~icons/lucide/users')['default']
|
IconLucideUsers: typeof import('~icons/lucide/users')['default']
|
||||||
|
IconLucideVerified: typeof import('~icons/lucide/verified')['default']
|
||||||
InterceptorsExtensionSubtitle: typeof import('./components/interceptors/ExtensionSubtitle.vue')['default']
|
InterceptorsExtensionSubtitle: typeof import('./components/interceptors/ExtensionSubtitle.vue')['default']
|
||||||
LensesHeadersRenderer: typeof import('./components/lenses/HeadersRenderer.vue')['default']
|
LensesHeadersRenderer: typeof import('./components/lenses/HeadersRenderer.vue')['default']
|
||||||
LensesHeadersRendererEntry: typeof import('./components/lenses/HeadersRendererEntry.vue')['default']
|
LensesHeadersRendererEntry: typeof import('./components/lenses/HeadersRendererEntry.vue')['default']
|
||||||
|
|||||||
@@ -19,11 +19,12 @@
|
|||||||
>
|
>
|
||||||
<WorkspaceCurrent :section="t('tab.collections')" />
|
<WorkspaceCurrent :section="t('tab.collections')" />
|
||||||
|
|
||||||
<input
|
<HoppSmartInput
|
||||||
v-model="filterTexts"
|
v-model="filterTexts"
|
||||||
:placeholder="t('action.search')"
|
:placeholder="t('action.search')"
|
||||||
class="py-2 pl-4 pr-2 bg-transparent !border-0"
|
input-styles="py-2 pl-4 pr-2 bg-transparent !border-0"
|
||||||
type="search"
|
type="search"
|
||||||
|
:autofocus="false"
|
||||||
:disabled="collectionsType.type === 'team-collections'"
|
:disabled="collectionsType.type === 'team-collections'"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -21,17 +21,13 @@
|
|||||||
<div class="flex items-center py-4 space-x-2">
|
<div class="flex items-center py-4 space-x-2">
|
||||||
<HoppSmartInput
|
<HoppSmartInput
|
||||||
v-model="PROXY_URL"
|
v-model="PROXY_URL"
|
||||||
|
:autofocus="false"
|
||||||
styles="flex-1"
|
styles="flex-1"
|
||||||
placeholder=" "
|
placeholder=" "
|
||||||
|
:label="t('settings.proxy_url')"
|
||||||
input-styles="input floating-input"
|
input-styles="input floating-input"
|
||||||
:disabled="!proxyEnabled"
|
:disabled="!proxyEnabled"
|
||||||
>
|
/>
|
||||||
<template #label>
|
|
||||||
<label for="url">
|
|
||||||
{{ t("settings.proxy_url") }}
|
|
||||||
</label>
|
|
||||||
</template>
|
|
||||||
</HoppSmartInput>
|
|
||||||
<HoppButtonSecondary
|
<HoppButtonSecondary
|
||||||
v-tippy="{ theme: 'tooltip' }"
|
v-tippy="{ theme: 'tooltip' }"
|
||||||
:title="t('settings.reset_default')"
|
:title="t('settings.reset_default')"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<div v-else class="space-y-8">
|
<div v-else class="space-y-8">
|
||||||
<div
|
<div
|
||||||
class="h-24 rounded bg-primaryLight -mb-11 md:h-32"
|
class="h-24 rounded bg-primaryLight -mb-11 md:h-32"
|
||||||
style="background-image: url("/images/cover.svg")"
|
style="background-image: url(/images/cover.svg)"
|
||||||
></div>
|
></div>
|
||||||
<div class="flex flex-col justify-between px-4 space-y-8 md:flex-row">
|
<div class="flex flex-col justify-between px-4 space-y-8 md:flex-row">
|
||||||
<div class="flex items-end">
|
<div class="flex items-end">
|
||||||
@@ -102,6 +102,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<HoppSmartInput
|
<HoppSmartInput
|
||||||
v-model="displayName"
|
v-model="displayName"
|
||||||
|
:autofocus="false"
|
||||||
styles="mt-2 md:max-w-sm"
|
styles="mt-2 md:max-w-sm"
|
||||||
:placeholder="`${t('settings.profile_name')}`"
|
:placeholder="`${t('settings.profile_name')}`"
|
||||||
>
|
>
|
||||||
@@ -124,6 +125,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<HoppSmartInput
|
<HoppSmartInput
|
||||||
v-model="emailAddress"
|
v-model="emailAddress"
|
||||||
|
:autofocus="false"
|
||||||
styles="flex mt-2 md:max-w-sm"
|
styles="flex mt-2 md:max-w-sm"
|
||||||
:placeholder="`${t('settings.profile_name')}`"
|
:placeholder="`${t('settings.profile_name')}`"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<HoppSmartInput
|
<HoppSmartInput
|
||||||
v-model="url"
|
v-model="url"
|
||||||
type="url"
|
type="url"
|
||||||
|
:autofocus="false"
|
||||||
styles="!inline-flex flex-1 space-x-2"
|
styles="!inline-flex flex-1 space-x-2"
|
||||||
input-styles="w-full px-4 py-2 border rounded !bg-primaryLight border-divider text-secondaryDark"
|
input-styles="w-full px-4 py-2 border rounded !bg-primaryLight border-divider text-secondaryDark"
|
||||||
:placeholder="`${t('websocket.url')}`"
|
:placeholder="`${t('websocket.url')}`"
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
ref="inputRef"
|
ref="inputRef"
|
||||||
:class="inputStyles"
|
:class="inputStyles"
|
||||||
v-model="inputText"
|
v-model="inputText"
|
||||||
v-focus
|
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:type="type"
|
:type="type"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
@@ -32,11 +31,20 @@ let inputIDCounter = 564275
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onKeyStroke, useVModel } from "@vueuse/core"
|
import { onKeyStroke, useVModel } from "@vueuse/core"
|
||||||
import { defineProps, ref } from "vue"
|
import { defineProps, onMounted, ref, nextTick } from "vue"
|
||||||
|
|
||||||
// Unique ID for input
|
// Unique ID for input
|
||||||
const inputID = `input-${inputIDCounter++}`
|
const inputID = `input-${inputIDCounter++}`
|
||||||
|
|
||||||
|
const inputRef = ref()
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
if (props.autofocus) {
|
||||||
|
await nextTick()
|
||||||
|
inputRef.value?.focus()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
id: string
|
id: string
|
||||||
@@ -47,6 +55,7 @@ const props = withDefaults(
|
|||||||
type: string
|
type: string
|
||||||
label: string
|
label: string
|
||||||
disabled: boolean
|
disabled: boolean
|
||||||
|
autofocus: boolean
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
id: "",
|
id: "",
|
||||||
@@ -57,6 +66,7 @@ const props = withDefaults(
|
|||||||
type: "text",
|
type: "text",
|
||||||
label: "",
|
label: "",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
autofocus: true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -65,13 +75,15 @@ const emit = defineEmits<{
|
|||||||
(e: "update:modelValue", v: string): void
|
(e: "update:modelValue", v: string): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const inputRef = ref()
|
|
||||||
|
|
||||||
const inputText = useVModel(props, "modelValue", emit)
|
const inputText = useVModel(props, "modelValue", emit)
|
||||||
|
|
||||||
onKeyStroke("Enter", (e) => {
|
onKeyStroke(
|
||||||
|
"Enter",
|
||||||
|
(e) => {
|
||||||
if (!e.repeat) {
|
if (!e.repeat) {
|
||||||
return emit("submit")
|
return emit("submit")
|
||||||
}
|
}
|
||||||
}, { target: inputRef, eventName: "keydown" })
|
},
|
||||||
|
{ target: inputRef, eventName: "keydown" }
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user