question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autofocus on searchbox not working

See original GitHub issue

Bug 🐞 When I add the autofocus attribute, it doesn’t work. No autofocus happens. In codepen I have this code (as described in the documentation):

<div class="searchbox">
   <ais-search-box autofocus />
</div>

See https://codesandbox.io/s/happy-moore-yo82c?file=/src/App.vue

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
eugenevkcommented, Oct 21, 2021

Now it works! Thanks a million. Changed the MyFocuser.js into a component by the way, but that’s a formality. Maybe for others who read this, here is my end solution:

Component: FocusSearchBox.vue

<template>
</template>

<script>
export default {
    name: 'FocusSearchBox',
    setup() {
        const input = document.querySelector('.searchbox-for-focus .ais-SearchBox-input')
        input && input.focus()
    }
}
</script>

and in my search component:

<template>
  ...
  <ais-search-box class="searchbox-for-focus" />

  <ais-state-results>
    <FocusSearchBox />
  </ais-state-results>
</template>

<script>
import FocusSearchBox from '@/components/FocusSearchBox.vue'

import { algoliaSearchClient } from '@/algolia/config'

export default {
  name: 'Search',
  components: {
    FocusSearchBox
  },
  setup() {
   ...
  }
0reactions
Haroenvcommented, Oct 21, 2021

I’m not referring to a slot but to a class @eugenevk

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Run] Search box does not auto focus · Issue #8876 - GitHub
I found such case which should be reproducible. I believe that the problem occurs when taskbar doesn't "return" back focus. Consider this ...
Read more >
Why is jQuery-select2 autofocus not working and how do I fix it?
I'm using select2 in all my projects and it works fine. But in my new project, my select2 input doesn't focus as it...
Read more >
autofocus for search bar - WordPress.org
Hello, I have a problem with the autofocus of the search bar. Unfortunately, since activating the plugin, you still have to click in...
Read more >
How to auto focus on Searchbox on page load?
I'm using CoveoSearchbox component for input, so no possible way to add autofocus attribute to input element.
Read more >
Why would the search input field not get focus when the page ...
Keyboard/screen-reader users will need to step out of the search field when it was focused automatically to make use of other ways to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found