Struggling to achieve input focus inside v-expansion-panels upon hitting enter? While I've successfully made the next expansion panel open and accessed the input via the $refs API, I'm unable to make the input focus. Check out a snippet of my code below:
<v-expansion-panels v-model="openedPanel" :accordion="true">
<v-expansion-panel class="panel">
<!-- Unidade Produtiva -->
<v-expansion-panel-header>Unidade produtiva</v-expansion-panel-header>
<v-expansion-panel-content eager>
<label class="panel-label">Número do Talhão</label>
<v-container>
<v-row>
<v-col class="spacing-container" cols="12" md="12">
<ValidationProvider name="production-field" rules="required">
<input
ref="field"
v-on:keyup.enter="$refs.height.focus"
class="default-input"
v-model="production.field"
type="number"
placeholder="Ex.: 1"
/>
</ValidationProvider>
</v-col>
</v-row>
</v-container>
<label class="panel-label">Tamanho do Canteiro</label>
<v-container>
<v-row>
<v-col class="spacing-container" cols="12" md="6">
<label class="input-label">Comprimento (m)</label>
<ValidationProvider name="production-height" rules="required">
<input
ref="height"
v-on:keyup.enter="$refs.width.focus"
class="default-input"
v-model="production.height"
type="number"
step="0.001"
min="0.001"
placeholder="Ex.: 1.23"
/>
</ValidationProvider>
</v-col>
<v-col class="spacing-container" cols="12" md="6">
<label class="input-label">Largura (m)</label>
<ValidationProvider name="production-width" rules="required">
<input
ref="width"
v-on:keyup.enter="$refs.spacew.focus"
class="default-input"
v-model="production.width"
type="number"
step="0.001"
min="0.001"
placeholder="Ex.: 1.23"
/>
</ValidationProvider>
</v-col>
</v-row>
</v-container>
<label class="panel-label">Espaçamento</label>
<v-container>
<v-row>
<v-col class="spacing-container" cols="12" md="6">
<label class="input-label">Entre linhas (cm)</label>
<ValidationProvider name="production-spacew" rules="required">
<input
ref="spacew"
v-on:keyup.enter="$refs.spaceh.focus"
class="default-input"
v-model="production.spacew"
type="number"
step="0.001"
min="0.001"
placeholder="Ex.: 1.23"
/>
</ValidationProvider>
</v-col>
<v-col class="spacing-container" cols="12" md="6">
<label class="input-label">Entre colunas (cm)</label>
<ValidationProvider name="production-spaceh" rules="required">
<input
ref="spaceh"
v-on:keyup.enter="handleNext(1, 'name')"
class="default-input"
v-model="production.spaceh"
type="number"
step="0.001"
min="0.001"
placeholder="Ex.: 1.23"
/>
</ValidationProvider>
</v-col>
</v-row>
</v-container>
</v-expansion-panel-content>
</v-expansion-panel>
<v-expansion-panel class="panel">
<!-- Nome do produto -->
<v-expansion-panel-header>Nome do produto</v-expansion-panel-header>
<v-expansion-panel-content eager>
<label class="panel-label">Nome</label>
<ValidationProvider name="production-name" rules="required">
<input
ref="name"
v-on:keyup.enter="handleNext(2, 'bed')"
class="default-input"
v-model="production.name"
type="text"
placeholder="Ex.: Macaxeira"
/>
</ValidationProvider>
</v-expansion-panel-content>
</v-expansion-panel>
</v-expansion-panels>
Snippet of methods being utilized:
openPanel(index) {
this.openedPanel = index;
},
closeAllPanels() {
this.openedPanel = null;
},
handleNext(index, refInput) {
this.closeAllPanels();
this.openPanel(index);
this.$refs[refInput].focus();
console.log(refInput);
console.log(this.$refs[refInput]);
},
Note: Edited "focus" to "focus()", though it remains unresolved.