Improve focus behaviour on search boxes and chats

This commit is contained in:
Gimle Larpes 2025-06-01 04:48:42 +02:00
parent e6f4eeca8e
commit 737f2bbd29
3 changed files with 12 additions and 2 deletions

View file

@ -29,6 +29,7 @@ export function SearchInput({ active, loading, searchInputRef, onSearch, onReset
ref={searchInputRef}
style={{ paddingRight: config.space.S300 }}
name="searchInput"
autoFocus
size="500"
variant="Background"
placeholder="Search for keyword"

View file

@ -1,9 +1,10 @@
import React, { useCallback, useRef } from 'react';
import React, { useCallback, useEffect, useRef } from 'react';
import { Box, Text, config } from 'folds';
import { EventType, Room } from 'matrix-js-sdk';
import { ReactEditor } from 'slate-react';
import { isKeyHotkey } from 'is-hotkey';
import { useStateEvent } from '../../hooks/useStateEvent';
import { ScreenSize, useScreenSizeContext } from '../../hooks/useScreenSize';
import { StateEvent } from '../../../types/matrix/room';
import { usePowerLevelsAPI, usePowerLevelsContext } from '../../hooks/usePowerLevels';
import { useMatrixClient } from '../../hooks/useMatrixClient';
@ -63,6 +64,8 @@ export function RoomView({ room, eventId }: { room: Room; eventId?: string }) {
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
const screenSize = useScreenSizeContext();
const { roomId } = room;
const editor = useEditor();
@ -99,6 +102,12 @@ export function RoomView({ room, eventId }: { room: Room; eventId?: string }) {
)
);
useEffect(() => {
if (screenSize === ScreenSize.Desktop) {
ReactEditor.focus(editor);
}
}, [editor, screenSize]);
return (
<Page ref={roomViewRef}>
<RoomViewHeader />

View file

@ -273,7 +273,7 @@ function InviteUser({ isOpen, roomId, searchTerm, onRequestClose }) {
searchUser(usernameRef.current.value);
}}
>
<Input value={searchTerm} forwardRef={usernameRef} label="Name or userId" />
<Input value={searchTerm} forwardRef={usernameRef} label="Name or userId" autoFocus />
<Button disabled={isSearching} iconSrc={UserIC} variant="primary" type="submit">
Search
</Button>