Skip to content

Commit

Permalink
Fix search input 'autofocus after search' on Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
YellowFish085 committed Dec 10, 2020
1 parent c14fe22 commit 61ee0c5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/components/search/inputs/InputSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
id="search"
class="input h-full w-full"
autocomplete="off"
autofocus="on"
:class="{ disabled: disabled }"
:placeholder="i18n('S_SearchPlaceholder')"
:disabled="disabled"
Expand All @@ -34,6 +35,7 @@ import {
Mixins,
Prop,
Vue,
Watch,
} from 'vue-property-decorator';
import ButtonIcon from '@/components/ui/buttons/ButtonIcon.vue';
import MixinI18n from '@/mixins/I18n';
Expand All @@ -57,6 +59,20 @@ export default class InputSearch extends Mixins(Vue, MixinI18n) {
/** Search timeout. */
timeout: number | null = null;
/**
* Watch for disabled state.
*/
@Watch('disabled')
onDisabledChanged(newValue: boolean) {
// Note: When input is enabled after being disabled, Chrome does not focus the input again.
// So we need to force the focus again. We also need a small delay here to let Chrome
// correctly remove the `disabled` property on the input, else the focus wont work because
// Chrome will still see the input as being disabled.
if (!newValue) {
setTimeout(this.focusOnInput, 100);
}
}
/**
* Force focus on input.
*/
Expand Down

0 comments on commit 61ee0c5

Please sign in to comment.