Focus topic edit input by using $refs
This commit is contained in:
parent
456cdb2f54
commit
60ca8850d9
@ -20,6 +20,7 @@
|
|||||||
<span class="title">{{ channel.name }}</span>
|
<span class="title">{{ channel.name }}</span>
|
||||||
<div v-if="channel.editTopic === true" class="topic-container">
|
<div v-if="channel.editTopic === true" class="topic-container">
|
||||||
<input
|
<input
|
||||||
|
ref="topicInput"
|
||||||
:value="channel.topic"
|
:value="channel.topic"
|
||||||
class="topic-input"
|
class="topic-input"
|
||||||
placeholder="Set channel topic"
|
placeholder="Set channel topic"
|
||||||
@ -138,9 +139,22 @@ export default {
|
|||||||
channel() {
|
channel() {
|
||||||
this.channelChanged();
|
this.channelChanged();
|
||||||
},
|
},
|
||||||
|
"channel.editTopic"(newValue) {
|
||||||
|
if (newValue) {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.$refs.topicInput.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.channelChanged();
|
this.channelChanged();
|
||||||
|
|
||||||
|
if (this.channel.editTopic) {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.$refs.topicInput.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
channelChanged() {
|
channelChanged() {
|
||||||
@ -164,15 +178,11 @@ export default {
|
|||||||
editTopic() {
|
editTopic() {
|
||||||
if (this.channel.type === "channel") {
|
if (this.channel.type === "channel") {
|
||||||
this.channel.editTopic = true;
|
this.channel.editTopic = true;
|
||||||
|
|
||||||
this.$nextTick(() => {
|
|
||||||
document.querySelector(`#chan-${this.channel.id} .topic-input`).focus();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveTopic() {
|
saveTopic() {
|
||||||
this.channel.editTopic = false;
|
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) {
|
if (this.channel.topic !== newTopic) {
|
||||||
const target = this.channel.id;
|
const target = this.channel.id;
|
||||||
|
@ -98,10 +98,6 @@ export function generateChannelContextMenu($root, channel, network) {
|
|||||||
action() {
|
action() {
|
||||||
channel.editTopic = true;
|
channel.editTopic = true;
|
||||||
$root.switchToChannel(channel);
|
$root.switchToChannel(channel);
|
||||||
|
|
||||||
$root.$nextTick(() =>
|
|
||||||
document.querySelector(`#chan-${channel.id} .topic-input`).focus()
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
items.push({
|
items.push({
|
||||||
|
Loading…
Reference in New Issue
Block a user