Skip to content

Commit

Permalink
feat: auto focus on first input in modals
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Dec 11, 2020
1 parent 797ab70 commit 1476e89
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/renderer/components/ModalAskCredentials.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</div>
<div class="col-9">
<input
ref="firstInput"
v-model="credentials.user"
class="form-input"
type="text"
Expand Down Expand Up @@ -63,6 +64,11 @@ export default {
}
};
},
created () {
setTimeout(() => {
this.$refs.firstInput.focus();
}, 20);
},
methods: {
closeModal () {
this.$emit('close-asking');
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/ModalEditConnection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</div>
<div class="col-8 col-sm-12">
<input
ref="firstInput"
v-model="localConnection.name"
class="form-input"
type="text"
Expand Down Expand Up @@ -172,6 +173,10 @@ export default {
created () {
this.localConnection = Object.assign({}, this.connection);
window.addEventListener('keydown', this.onKey);
setTimeout(() => {
this.$refs.firstInput.focus();
}, 20);
},
beforeDestroy () {
window.removeEventListener('keydown', this.onKey);
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/components/ModalEditDatabase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
<label class="form-label">{{ $t('word.collation') }}:</label>
</div>
<div class="col-9">
<select v-model="database.collation" class="form-select">
<select
ref="firstInput"
v-model="database.collation"
class="form-select"
>
<option
v-for="collation in collations"
:key="collation.id"
Expand Down Expand Up @@ -114,6 +118,10 @@ export default {
};
window.addEventListener('keydown', this.onKey);
setTimeout(() => {
this.$refs.firstInput.focus();
}, 20);
},
beforeDestroy () {
window.removeEventListener('keydown', this.onKey);
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/ModalNewConnection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</div>
<div class="col-8 col-sm-12">
<input
ref="firstInput"
v-model="connection.name"
class="form-input"
type="text"
Expand Down Expand Up @@ -182,6 +183,10 @@ export default {
},
created () {
window.addEventListener('keydown', this.onKey);
setTimeout(() => {
this.$refs.firstInput.focus();
}, 20);
},
beforeDestroy () {
window.removeEventListener('keydown', this.onKey);
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/components/ModalNewDatabase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</div>
<div class="col-9">
<input
ref="firstInput"
v-model="database.name"
class="form-input"
type="text"
Expand Down Expand Up @@ -89,6 +90,9 @@ export default {
created () {
this.database = { ...this.database, collation: this.defaultCollation };
window.addEventListener('keydown', this.onKey);
setTimeout(() => {
this.$refs.firstInput.focus();
}, 20);
},
beforeDestroy () {
window.removeEventListener('keydown', this.onKey);
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/ModalNewTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</label>
<div class="column">
<input
ref="firstInput"
v-model="localOptions.name"
class="form-input"
type="text"
Expand Down Expand Up @@ -112,6 +113,10 @@ export default {
mounted () {
this.localOptions.collation = this.defaultCollation;
this.localOptions.engine = this.defaultEngine;
setTimeout(() => {
this.$refs.firstInput.focus();
}, 20);
},
methods: {
confirmOptionsChange () {
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/components/ModalNewTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
<div class="input-group col-8 col-sm-12">
<ForeignKeySelect
v-if="foreignKeys.includes(field.name)"
ref="formInput"
class="form-select"
:value.sync="localRow[field.name]"
:key-usage="getKeyUsage(field.name)"
:disabled="fieldsToExclude.includes(field.name)"
/>
<input
v-else-if="inputProps(field).mask"
ref="formInput"
v-model="localRow[field.name]"
v-mask="inputProps(field).mask"
class="form-input"
Expand All @@ -41,6 +43,7 @@
>
<input
v-else-if="inputProps(field).type === 'file'"
ref="formInput"
class="form-input"
type="file"
:disabled="fieldsToExclude.includes(field.name)"
Expand All @@ -49,6 +52,7 @@
>
<input
v-else
ref="formInput"
v-model="localRow[field.name]"
class="form-input"
:type="inputProps(field).type"
Expand Down Expand Up @@ -192,6 +196,12 @@ export default {
}
this.localRow = { ...rowObj };
// Auto focus
setTimeout(() => {
const firstSelectableInput = this.$refs.formInput.find(input => !input.disabled);
firstSelectableInput.focus();
}, 20);
},
beforeDestroy () {
window.removeEventListener('keydown', this.onKey);
Expand Down
15 changes: 14 additions & 1 deletion src/renderer/components/WorkspacePropsIndexesModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@
</div>
</div>
</form>
<div v-if="!indexesProxy.length" class="empty">
<div class="empty-icon">
<i class="mdi mdi-key-outline mdi-48px" />
</div>
<p class="empty-title h5">
{{ $t('message.thereAreNoIndexes') }}
</p>
<div class="empty-action">
<button class="btn btn-primary" @click="addIndex">
{{ $t('message.createNewIndex') }}
</button>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -216,7 +229,7 @@ export default {
});
},
resetSelectedID () {
this.selectedIndexID = this.indexesProxy[0]._id;
this.selectedIndexID = this.indexesProxy.length ? this.indexesProxy[0]._id : '';
}
}
};
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/WorkspacePropsOptionsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</label>
<div class="column">
<input
ref="firstInput"
v-model="optionsProxy.name"
class="form-input"
:class="{'is-error': !isTableNameValid}"
Expand Down Expand Up @@ -112,6 +113,10 @@ export default {
},
created () {
this.optionsProxy = JSON.parse(JSON.stringify(this.localOptions));
setTimeout(() => {
this.$refs.firstInput.focus();
}, 20);
},
methods: {
confirmOptionsChange () {
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/i18n/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ module.exports = {
deleteTable: 'Delete table',
emptyCorfirm: 'Do you confirm to empty',
unsavedChanges: 'Unsaved changes',
discardUnsavedChanges: 'You have some unsaved changes. By leaving this tab these changes will be discarded.'
discardUnsavedChanges: 'You have some unsaved changes. By leaving this tab these changes will be discarded.',
thereAreNoIndexes: 'There are no indexes'
},
// Date and Time
short: {
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,7 @@ body {
visibility: hidden;
}
}

.empty {
color: $body-font-color;
}

0 comments on commit 1476e89

Please sign in to comment.