feat: autofocus textarea on iOS

This commit is contained in:
Shusui MOYATANI
2024-01-08 09:31:49 +09:00
parent 3d0fdca254
commit 1ecb3ebcc6
3 changed files with 13 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
import { createSignal, createMemo, onMount, Show, For, type Component, type JSX } from 'solid-js'; import { createSignal, createMemo, Show, For, type Component, type JSX } from 'solid-js';
import { createMutation } from '@tanstack/solid-query'; import { createMutation } from '@tanstack/solid-query';
import ExclamationTriangle from 'heroicons/24/outline/exclamation-triangle.svg'; import ExclamationTriangle from 'heroicons/24/outline/exclamation-triangle.svg';
@@ -344,13 +344,6 @@ const NotePostForm: Component<NotePostFormProps> = (props) => {
onEmojiSelect: handleEmojiSelect, onEmojiSelect: handleEmojiSelect,
})); }));
onMount(() => {
setTimeout(() => {
textAreaRef?.click();
textAreaRef?.focus();
}, 50);
});
return ( return (
<div class="p-1"> <div class="p-1">
<Show when={props.replyTo != null}> <Show when={props.replyTo != null}>

View File

@@ -93,7 +93,7 @@ const SideBar: Component = () => {
createEffect(() => { createEffect(() => {
if (formOpened() && textAreaRef != null) { if (formOpened() && textAreaRef != null) {
setTimeout(() => focusTextArea(), 100); focusTextArea();
} }
}); });

View File

@@ -23,13 +23,20 @@ export type TextNoteProps = {
}; };
const TextNote: Component<TextNoteProps> = (props) => { const TextNote: Component<TextNoteProps> = (props) => {
let textAreaRef: HTMLTextAreaElement | undefined;
const i18n = useTranslation(); const i18n = useTranslation();
const { showProfile } = useModalState(); const { showProfile } = useModalState();
const timelineContext = useTimelineContext(); const timelineContext = useTimelineContext();
const [showReplyForm, setShowReplyForm] = createSignal(false); const [showReplyForm, setShowReplyForm] = createSignal(false);
const closeReplyForm = () => setShowReplyForm(false); const closeReplyForm = () => setShowReplyForm(false);
const toggleReplyForm = () => setShowReplyForm((current) => !current); const toggleReplyForm = () => {
setShowReplyForm((current) => !current);
if (showReplyForm() && textAreaRef != null) {
textAreaRef.focus();
}
};
const event = createMemo(() => textNote(props.event)); const event = createMemo(() => textNote(props.event));
@@ -113,6 +120,9 @@ const TextNote: Component<TextNoteProps> = (props) => {
footer={ footer={
<Show when={showReplyForm()}> <Show when={showReplyForm()}>
<NotePostForm <NotePostForm
textAreaRef={(el) => {
textAreaRef = el;
}}
mode="reply" mode="reply"
replyTo={props.event} replyTo={props.event}
onClose={closeReplyForm} onClose={closeReplyForm}