Skip to content

Commit

Permalink
fix: focus search bars only on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
JackHamer09 committed Jun 1, 2023
1 parent 65f195d commit aaf161e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions components/common/SmallInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useFocus } from "@vueuse/core";
import type { Component, PropType } from "vue";
import { isMobile } from "@/utils/helpers";
import { TransitionOpacity } from "@/utils/transitions";
const props = defineProps({
Expand All @@ -47,7 +48,7 @@ const props = defineProps({
default: "text",
},
autofocus: {
type: Boolean,
type: [Boolean, String] as PropType<boolean | "desktop">,
default: false,
},
});
Expand All @@ -57,7 +58,9 @@ const emit = defineEmits<{
}>();
const inputElement = ref<HTMLInputElement | null>(null);
const { focused } = useFocus(inputElement, { initialValue: !!props.autofocus });
const { focused } = useFocus(inputElement, {
initialValue: props.autofocus === true || (props.autofocus === "desktop" && isMobile() === false),
});
const inputted = computed({
get: () => props.modelValue,
Expand Down
2 changes: 1 addition & 1 deletion components/token/TokenSelectDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<CommonModal v-model:opened="isModalOpened" class="token-select-modal" :title="title" @after-leave="search = ''">
<Combobox v-model="selectedToken">
<!-- TODO: Refactor this to use ComboboxInput as main component but look like CommonSmallInput -->
<CommonSmallInput v-model.trim="search" class="mb-4" placeholder="Symbol or address" autofocus>
<CommonSmallInput v-model.trim="search" class="mb-4" placeholder="Symbol or address" autofocus="desktop">
<template #icon>
<MagnifyingGlassIcon aria-hidden="true" />
</template>
Expand Down
2 changes: 1 addition & 1 deletion pages/contacts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</CommonButton>
</div>
<div>
<CommonSmallInput v-model.trim="search" class="mb-4" placeholder="Address or name" autofocus>
<CommonSmallInput v-model.trim="search" class="mb-4" placeholder="Address or name" autofocus="desktop">
<template #icon>
<MagnifyingGlassIcon aria-hidden="true" />
</template>
Expand Down
4 changes: 4 additions & 0 deletions utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ export const getNetworkUrl = (network: ExtendedChain, routePath: string) => {
}
return network.hostnames[0] + routePath;
};

export const isMobile = () => {
return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent);
};
2 changes: 1 addition & 1 deletion views/SelectAddress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div>
<CommonBackButton @click="emit('back')" />
<h1 class="h1">{{ title }}</h1>
<CommonSmallInput v-model.trim="search" class="mb-4" placeholder="Address or name" autofocus>
<CommonSmallInput v-model.trim="search" class="mb-4" placeholder="Address or name" autofocus="desktop">
<template #icon>
<MagnifyingGlassIcon aria-hidden="true" />
</template>
Expand Down

0 comments on commit aaf161e

Please sign in to comment.