From 9fcd5ef54fadc2bc168720a3c377d43607b8b56a Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Wed, 15 Nov 2023 21:58:58 +0000 Subject: [PATCH] Auto focus search input when navigating to search page (#2224) --- src/shared/components/search.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 2b90da51..57c2f725 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -25,7 +25,7 @@ import { import type { QueryParams } from "@utils/types"; import { Choice, RouteDataResponse } from "@utils/types"; import type { NoOptionI18nKeys } from "i18next"; -import { Component, linkEvent } from "inferno"; +import { Component, linkEvent, createRef } from "inferno"; import { CommentView, CommunityView, @@ -239,6 +239,7 @@ function getListing( export class Search extends Component { private isoData = setIsoData(this.context); + searchInput = createRef(); state: SearchState = { resolveObjectRes: EMPTY_REQUEST, @@ -306,6 +307,8 @@ export class Search extends Component { } async componentDidMount() { + this.searchInput.current?.select(); + if (!this.state.isIsomorphic) { this.setState({ searchCommunitiesLoading: true, @@ -530,6 +533,7 @@ export class Search extends Component { onInput={linkEvent(this, this.handleQChange)} required minLength={1} + ref={this.searchInput} />