Skip to content

Commit

Permalink
Auto focus search input when navigating to search page (LemmyNet#2224)
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessOne1917 authored Nov 15, 2023
1 parent 795dcdb commit 9fcd5ef
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/shared/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -239,6 +239,7 @@ function getListing(

export class Search extends Component<any, SearchState> {
private isoData = setIsoData<SearchData>(this.context);
searchInput = createRef<HTMLInputElement>();

state: SearchState = {
resolveObjectRes: EMPTY_REQUEST,
Expand Down Expand Up @@ -306,6 +307,8 @@ export class Search extends Component<any, SearchState> {
}

async componentDidMount() {
this.searchInput.current?.select();

if (!this.state.isIsomorphic) {
this.setState({
searchCommunitiesLoading: true,
Expand Down Expand Up @@ -530,6 +533,7 @@ export class Search extends Component<any, SearchState> {
onInput={linkEvent(this, this.handleQChange)}
required
minLength={1}
ref={this.searchInput}
/>
</div>
<div className="col-auto">
Expand Down

0 comments on commit 9fcd5ef

Please sign in to comment.