From 7b7947570022ea903bad15fe8e7d9ea98f5cdaea Mon Sep 17 00:00:00 2001 From: Edward Hibbert Date: Mon, 27 Nov 2023 10:49:07 +0000 Subject: [PATCH 1/2] Only auto-focus for devices when adding. --- resources/js/components/DeviceType.vue | 21 ++++++++++++++------- resources/js/components/EventDevice.vue | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/resources/js/components/DeviceType.vue b/resources/js/components/DeviceType.vue index 8cd159dd6..eeb2788f1 100644 --- a/resources/js/components/DeviceType.vue +++ b/resources/js/components/DeviceType.vue @@ -52,6 +52,11 @@ export default { type: [Boolean, Number], required: false, default: false + }, + autoFocus: { + type: Boolean, + required: false, + default: false } }, computed: { @@ -87,13 +92,15 @@ 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) + 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 { + this.currentType = this.type + document.getElementsByClassName('theinput-' + this.uid)[0].focus() + } catch (e){ + console.error('Input focus failed', e) + } } }, watch: { diff --git a/resources/js/components/EventDevice.vue b/resources/js/components/EventDevice.vue index 3bcf423fe..a0515078f 100644 --- a/resources/js/components/EventDevice.vue +++ b/resources/js/components/EventDevice.vue @@ -11,6 +11,7 @@ :icon-variant="add ? 'black' : 'brand'" :item-types="itemTypes" :disabled="disabled" :suppress-type-warning="suppressTypeWarning" :powered="powered" :unknown.sync="unknownItemType" + :auto-focus="add" />