Auto-focus click-to-edit fields instead of requiring a second click
Type/Client/Facture/Libellé all swap a span for an <input>/<select> via v-if -- Vue doesn't focus a newly created element on its own, so the first click only revealed the field and a second click was needed to actually type into it. Added a v-focus directive (mounted() calls el.focus() + el.select(), firing exactly once per v-if true-flip) to all four. Verified live: a single click on each of the four editable cells now moves document.activeElement into the field immediately.
This commit is contained in:
@@ -1292,7 +1292,20 @@
|
|||||||
const root = context.querySelector ? context.querySelector('#figli-home-app') : null;
|
const root = context.querySelector ? context.querySelector('#figli-home-app') : null;
|
||||||
if (root && !root.dataset.figliInitialized) {
|
if (root && !root.dataset.figliInitialized) {
|
||||||
root.dataset.figliInitialized = '1';
|
root.dataset.figliInitialized = '1';
|
||||||
Vue.createApp(App).mount(root);
|
Vue.createApp(App)
|
||||||
|
// Click-to-edit cells (type/client/facture/libellé) swap a
|
||||||
|
// span for an <input>/<select> via v-if -- Vue doesn't focus a
|
||||||
|
// newly created element on its own, so without this the first
|
||||||
|
// click only opened the field and a second click was needed to
|
||||||
|
// actually type into it. mounted() fires once per v-if
|
||||||
|
// true-flip, i.e. exactly when the field appears.
|
||||||
|
.directive('focus', {
|
||||||
|
mounted(el) {
|
||||||
|
el.focus();
|
||||||
|
if (typeof el.select === 'function') el.select();
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.mount(root);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -147,6 +147,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<input
|
<input
|
||||||
v-if="isEditingCell(item, 'client')"
|
v-if="isEditingCell(item, 'client')"
|
||||||
|
v-focus
|
||||||
type="text"
|
type="text"
|
||||||
class="figli-inline-input"
|
class="figli-inline-input"
|
||||||
list="figli-client-datalist"
|
list="figli-client-datalist"
|
||||||
@@ -160,6 +161,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<select
|
<select
|
||||||
v-if="editingTypeId === item.id"
|
v-if="editingTypeId === item.id"
|
||||||
|
v-focus
|
||||||
class="figli-type-select"
|
class="figli-type-select"
|
||||||
:value="item.type"
|
:value="item.type"
|
||||||
@change="saveType(item, $event)"
|
@change="saveType(item, $event)"
|
||||||
@@ -178,6 +180,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<input
|
<input
|
||||||
v-if="isEditingCell(item, 'facture')"
|
v-if="isEditingCell(item, 'facture')"
|
||||||
|
v-focus
|
||||||
type="text"
|
type="text"
|
||||||
class="figli-inline-input"
|
class="figli-inline-input"
|
||||||
:value="item.facture"
|
:value="item.facture"
|
||||||
@@ -190,6 +193,7 @@
|
|||||||
<td class="figli-libelle">
|
<td class="figli-libelle">
|
||||||
<input
|
<input
|
||||||
v-if="isEditingCell(item, 'libelle')"
|
v-if="isEditingCell(item, 'libelle')"
|
||||||
|
v-focus
|
||||||
type="text"
|
type="text"
|
||||||
class="figli-inline-input"
|
class="figli-inline-input"
|
||||||
:value="item.libelle"
|
:value="item.libelle"
|
||||||
|
|||||||
Reference in New Issue
Block a user