Skip to content

Commit

Permalink
Merge pull request #706 from TheRestartProject/RES-1952_autofocus_item
Browse files Browse the repository at this point in the history
RES-1952 Only auto-focus for devices when adding.
  • Loading branch information
edwh authored Nov 27, 2023
2 parents 58eaa0a + 5b2f17e commit 38b3c3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
22 changes: 15 additions & 7 deletions resources/js/components/DeviceType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export default {
type: [Boolean, Number],
required: false,
default: false
},
autoFocus: {
type: Boolean,
required: false,
default: false
}
},
computed: {
Expand Down Expand Up @@ -85,13 +90,16 @@ export default {
}
},
mounted() {
// Focus on the input. This is a bit hacky as the typeahead component doesn't expose the input element. So we
// add our own class and then find it.
try {
this.currentType = this.type
document.getElementsByClassName('theinput-' + this.uid)[0].focus()
} catch (e){
console.error('Input focus failed', e)
this.currentType = this.type
if (this.autoFocus) {
// Focus on the input. This is a bit hacky as the typeahead component doesn't expose the input element. So we
// add our own class and then find it.
try {
document.getElementsByClassName('theinput-' + this.uid)[0].focus()
} catch (e){
console.error('Input focus failed', e)
}
}
// Fetch the item types. We do this here because it's slow, and we don't want to block the page load.
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/EventDevice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:icon-variant="add ? 'black' : 'brand'" :disabled="disabled"
:suppress-type-warning="suppressTypeWarning" :powered="powered"
:unknown.sync="unknownItemType"
:auto-focus="add"
/>
<DeviceCategorySelect :class="{
'mb-2': true,
Expand Down

0 comments on commit 38b3c3e

Please sign in to comment.