Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<UInput> template ref does not work #3644

Closed
maciekkand opened this issue Mar 21, 2025 · 3 comments
Closed

<UInput> template ref does not work #3644

maciekkand opened this issue Mar 21, 2025 · 3 comments
Labels
bug Something isn't working v3 #1289

Comments

@maciekkand
Copy link

maciekkand commented Mar 21, 2025

Environment

Is this bug related to Nuxt or Vue?

Nuxt

Version

Nuxt UI 3.0

Reproduction

<template>
<UInput
      v-model="translation"
      ref="translationField"      
  />
</template>

<script setup>
const translationField = ref(null)

function nextCard() {
   translationField.value.focus()  // throws: 'focus is not a function'
 
  nextTick(() => {
     translationField.value.focus()  // same error
  })

  // below works ok
  nextTick(() => {
      const input = translationField.value?.$el?.querySelector('input')
      if (input) {
        input.focus()
      }
    })
}
</script>

Description

Standard Vue method of using template ref (for setting a focus, here) throws: 'focus() is not a function'
In the above code snippet I included workaround (credits to Sonnet 3.5)
Tried it dozen of times and checked this place to see if it has not been solved earlier.

Additional context

No response

Logs

@maciekkand maciekkand added bug Something isn't working triage v3 #1289 labels Mar 21, 2025
@HugoRCD
Copy link
Member

HugoRCD commented Mar 21, 2025

@maciekkand Have you tried usingTemplateRef in this way?
https://ui.nuxt.com/components/input#with-keyboard-shortcut

@maciekkand
Copy link
Author

maciekkand commented Mar 21, 2025 via email

@HugoRCD
Copy link
Member

HugoRCD commented Mar 21, 2025

Don't worry, we are here to help ! 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v3 #1289
Projects
None yet
Development

No branches or pull requests

3 participants