Fix focusing on firefox

This commit is contained in:
fayazara 2022-12-15 19:13:41 +05:30
parent 785b303166
commit ed8929b55c
2 changed files with 23 additions and 50 deletions

View file

@ -1,23 +0,0 @@
<template>
<div />
</template>
<script>
export default {
mounted() {
this.handler = event => {
event.preventDefault();
this.$emit('keyup', event);
};
window.addEventListener('keyup', this.handler);
},
beforeDestroy() {
window.removeEventListener('keyup', this.handler);
},
};
</script>
<style scoped>
div {
display: none;
}
</style>

View file

@ -1,31 +1,23 @@
<template> <template>
<div> <div class="input-container">
<search-focus @keyup="focusSearch" /> <div class="icon-container">
<div class="input-container"> <fluent-icon icon="search" class="icon" aria-hidden="true" />
<div class="icon-container"> </div>
<fluent-icon icon="search" class="icon" aria-hidden="true" /> <input
</div> ref="searchInput"
<input type="search"
ref="searchInput" :placeholder="$t('SEARCH.INPUT_PLACEHOLDER')"
type="search" :value="searchQuery"
:placeholder="$t('SEARCH.INPUT_PLACEHOLDER')" @input="debounceSearch"
:value="searchQuery" />
@input="debounceSearch" <div class="key-binding">
/> <span>{{ $t('SEARCH.PLACEHOLDER_KEYBINDING') }}</span>
<div class="key-binding">
<span>{{ $t('SEARCH.PLACEHOLDER_KEYBINDING') }}</span>
</div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import SearchFocus from './SearchFocus.vue';
export default { export default {
components: {
SearchFocus,
},
data() { data() {
return { return {
searchQuery: '', searchQuery: '',
@ -33,6 +25,16 @@ export default {
}, },
mounted() { mounted() {
this.$refs.searchInput.focus(); this.$refs.searchInput.focus();
this.handler = e => {
if (e.key === '/') {
e.preventDefault();
this.$refs.searchInput.focus();
}
};
document.addEventListener('keydown', this.handler);
},
beforeDestroy() {
window.removeEventListener('keydown', this.handler);
}, },
methods: { methods: {
debounceSearch(e) { debounceSearch(e) {
@ -44,12 +46,6 @@ export default {
} }
}, 500); }, 500);
}, },
focusSearch(e) {
if (e.key === '/') {
e.preventDefault();
this.$refs.searchInput.focus();
}
},
}, },
}; };
</script> </script>