diff --git a/src/renderer/components/input/search-input-url.tsx b/src/renderer/components/input/search-input-url.tsx index 9ee4c8a5bb..aef8df26ca 100644 --- a/src/renderer/components/input/search-input-url.tsx +++ b/src/renderer/components/input/search-input-url.tsx @@ -5,65 +5,62 @@ import React from "react"; import debounce from "lodash/debounce"; -import { autorun, observable, makeObservable } from "mobx"; +import { action, autorun, makeObservable, observable } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; -import type { InputProps } from "./input"; -import { SearchInput } from "./search-input"; +import { SearchInput, type SearchInputProps } from "./search-input"; import { createPageParam } from "../../navigation"; +import { autoBind } from "../../../common/utils"; export const searchUrlParam = createPageParam({ name: "search", defaultValue: "", }); -export interface SearchInputUrlProps extends InputProps { - compact?: boolean; // show only search-icon when not focused +export interface SearchInputUrlProps extends SearchInputProps { } @observer export class SearchInputUrl extends React.Component { - @observable inputVal = ""; // fix: use empty string on init to avoid react warnings + @observable inputValueFromLocation = this.props.value ?? ""; updateUrl = debounce((val: string) => searchUrlParam.set(val), 250); - componentDidMount(): void { + constructor(props: SearchInputProps) { + super(props); + makeObservable(this); + autoBind(this); + disposeOnUnmount(this, [ - autorun(() => this.inputVal = searchUrlParam.get()), + autorun(() => this.inputValueFromLocation = searchUrlParam.get()), ]); } - setValue = (value: string) => { - this.inputVal = value; + @action + setValue(value: string) { + this.inputValueFromLocation = value; this.updateUrl(value); - }; - - clear = () => { - this.setValue(""); this.updateUrl.flush(); - }; + } - onChange = (val: string, evt: React.ChangeEvent) => { + clear() { + this.setValue(""); + this.props.onClear?.(); + } + + onChange(val: string, evt: React.ChangeEvent) { this.setValue(val); - - if (this.props.onChange) { - this.props.onChange(val, evt); - } - }; - - constructor(props: SearchInputUrlProps) { - super(props); - makeObservable(this); + this.props.onChange?.(val, evt); } render() { - const { inputVal } = this; + const { value, ...searchInputProps } = this.props; return ( ); } diff --git a/src/renderer/components/item-object-list/header.tsx b/src/renderer/components/item-object-list/header.tsx index d3063c4fc7..abff88257b 100644 --- a/src/renderer/components/item-object-list/header.tsx +++ b/src/renderer/components/item-object-list/header.tsx @@ -100,7 +100,12 @@ export class ItemListLayoutHeader extends React.Component< ) } {filters} - {searchFilters.length > 0 && searchProps && } + {searchFilters.length > 0 && searchProps && ( + + )} ); }