Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:retained input reference on x icon click #36268

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class SearchComponent extends React.Component<
SearchProps,
{ localValue: string }
> {
private inputRef = React.createRef<HTMLInputElement>();
onDebouncedSearch = debounce(this.props.onSearch, 400);
constructor(props: SearchProps) {
super(props);
Expand All @@ -112,12 +113,16 @@ class SearchComponent extends React.Component<
clearSearch = () => {
this.setState({ localValue: "" });
this.onDebouncedSearch("");
if (this.inputRef.current) {
this.inputRef.current.focus();
}
};

render() {
return (
<SearchComponentWrapper>
<SearchInputWrapper
inputRef={this.inputRef}
autoFocus={this.props.autoFocus}
className={`${this.props.className} t--search-input`}
leftIcon="search"
Expand Down
11 changes: 10 additions & 1 deletion app/client/src/widgets/MultiSelectTreeWidget/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,16 @@ function MultiTreeSelectComponent({
const clearButton = useMemo(
() =>
filter ? (
<Button icon="cross" minimal onClick={() => setFilter("")} />
<Button
icon="cross"
minimal
onClick={() => {
if (inputRef.current) {
inputRef.current.focus();
}
setFilter("");
}}
/>
) : null,
[filter],
);
Expand Down
11 changes: 10 additions & 1 deletion app/client/src/widgets/MultiSelectWidgetV2/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,16 @@ function MultiSelectComponent({
const clearButton = useMemo(
() =>
filter ? (
<Button icon="cross" minimal onClick={() => setFilter("")} />
<Button
icon="cross"
minimal
onClick={() => {
if (inputRef.current) {
inputRef.current.focus();
}
setFilter("");
}}
/>
) : null,
[filter],
);
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/widgets/SelectWidget/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class SelectComponent extends React.Component<
};

onQueryChange = debounce((filterValue: string) => {
console.log(">> inside query change")
if (equal(filterValue, this.props.filterText)) return;
this.props.onFilterChange(filterValue);
this.listRef?.current?.scrollTo(0);
Expand Down Expand Up @@ -409,6 +410,7 @@ class SelectComponent extends React.Component<
onClose: this.handleCloseList,
// onActiveItemChange is called twice abd puts the focus on the first item https://github.com/palantir/blueprint/issues/4192
onOpening: () => {
console.log(">>> opend...")
if (!this.props.selectedIndex) {
return this.handleActiveItemChange(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,16 @@ function SingleSelectTreeComponent({
const clearButton = useMemo(
() =>
filter ? (
<Button icon="cross" minimal onClick={() => setFilter("")} />
<Button
icon="cross"
minimal
onClick={() => {
if (inputRef.current) {
inputRef.current.focus();
}
setFilter("");
}}
/>
) : null,
[filter],
);
Expand Down