Skip to content

Commit 58b06f5

Browse files
committed
fix: 🐛 Automatically focus composer text input when opened
1 parent 569666f commit 58b06f5

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

components/composer/composer.vue

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Input v-model:model-value="state.contentWarning" v-if="state.sensitive"
77
placeholder="Put your content warning here" />
88

9-
<Textarea :placeholder="chosenSplash" v-model:model-value="state.content"
9+
<Textarea id="text-input" :placeholder="chosenSplash" v-model:model-value="state.content"
1010
class="!border-none !ring-0 !outline-none rounded-none p-0 max-h-full min-h-48 !ring-offset-0"
1111
:disabled="sending" />
1212

@@ -122,6 +122,13 @@ const { Control_Enter, Command_Enter } = useMagicKeys();
122122
const ctrlEnterSend = useSetting(SettingIds.CtrlEnterToSend);
123123
const fileInput = ref<HTMLInputElement | null>(null);
124124
125+
onMounted(() => {
126+
// Wait 0.3s for the dialog to open
127+
setTimeout(() => {
128+
document.getElementById("text-input")?.focus();
129+
}, 300);
130+
});
131+
125132
watch([Control_Enter, Command_Enter], () => {
126133
if (sending.value || !ctrlEnterSend.value.value) {
127134
return;
@@ -296,4 +303,4 @@ const visibilities = {
296303
text: m.lucky_mean_robin_link(),
297304
},
298305
};
299-
</script>
306+
</script>

components/composer/dialog.vue

+10-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ useListen("composer:quote", (note) => {
4444
useListen("composer:close", () => {
4545
open.value = false;
4646
relation.value = null;
47+
// Unfocus the active element
48+
activeElement.value?.blur();
4749
});
4850
51+
const activeElement = useActiveElement();
4952
const open = ref(false);
5053
const relation = ref(
5154
null as {
@@ -57,7 +60,12 @@ const relation = ref(
5760
</script>
5861

5962
<template>
60-
<Dialog v-model:open="open" @update:open="o => { if (!o) { relation = null } }">
63+
<Dialog v-model:open="open" @update:open="o => {
64+
if (!o) {
65+
relation = null; // Unfocus the active element
66+
activeElement?.blur();
67+
}
68+
}">
6169
<DialogContent :hide-close="true"
6270
class="sm:max-w-xl max-w-full w-full grid-rows-[minmax(0,1fr)_auto] max-h-[90dvh] p-5 pt-6 top-0 sm:top-1/2 translate-y-0 sm:-translate-y-1/2">
6371
<DialogTitle class="sr-only">
@@ -71,4 +79,4 @@ const relation = ref(
7179
<Composer :relation="relation ?? undefined" />
7280
</DialogContent>
7381
</Dialog>
74-
</template>
82+
</template>

0 commit comments

Comments
 (0)