From 60ca8850d94b9930c950f645413bcf96324bce6d Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 19 Dec 2019 15:06:33 +0200 Subject: [PATCH] Focus topic edit input by using $refs --- client/components/Chat.vue | 20 +++++++++++++++----- client/js/helpers/contextMenu.js | 4 ---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/client/components/Chat.vue b/client/components/Chat.vue index e7762842..603aed8b 100644 --- a/client/components/Chat.vue +++ b/client/components/Chat.vue @@ -20,6 +20,7 @@ {{ channel.name }}
{ + this.$refs.topicInput.focus(); + }); + } + }, }, mounted() { this.channelChanged(); + + if (this.channel.editTopic) { + this.$nextTick(() => { + this.$refs.topicInput.focus(); + }); + } }, methods: { channelChanged() { @@ -164,15 +178,11 @@ export default { editTopic() { if (this.channel.type === "channel") { this.channel.editTopic = true; - - this.$nextTick(() => { - document.querySelector(`#chan-${this.channel.id} .topic-input`).focus(); - }); } }, saveTopic() { this.channel.editTopic = false; - const newTopic = document.querySelector(`#chan-${this.channel.id} .topic-input`).value; + const newTopic = this.$refs.topicInput.value; if (this.channel.topic !== newTopic) { const target = this.channel.id; diff --git a/client/js/helpers/contextMenu.js b/client/js/helpers/contextMenu.js index a9818a0f..5c7d9066 100644 --- a/client/js/helpers/contextMenu.js +++ b/client/js/helpers/contextMenu.js @@ -98,10 +98,6 @@ export function generateChannelContextMenu($root, channel, network) { action() { channel.editTopic = true; $root.switchToChannel(channel); - - $root.$nextTick(() => - document.querySelector(`#chan-${channel.id} .topic-input`).focus() - ); }, }); items.push({