Skip to content

Commit

Permalink
vsx: fix search input behavior
Browse files Browse the repository at this point in the history
The commit fixes the search input behavior which would always move the
cursor to the end of the input when inputting characters, even those in
between.

The issue was the mismatch of react controlled and uncontrolled input,
which would mean keeping a state about the cursor during updates.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Jul 29, 2021
1 parent 86995b7 commit 103e19b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/vsx-registry/src/browser/vsx-extensions-search-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export class VSXExtensionsSearchBar extends ReactWidget {
protected init(): void {
this.id = 'vsx-extensions-search-bar';
this.addClass('theia-vsx-extensions-search-bar');
this.model.onDidChangeQuery(() => this.update());
this.model.onDidChangeQuery((query: string) => this.updateSearchTerm(query));
}

protected input: HTMLInputElement | undefined;

protected render(): React.ReactNode {
return <input type='text'
ref={input => this.input = input || undefined}
value={this.model.query}
defaultValue={this.model.query}
className='theia-input'
placeholder='Search Extensions in Open VSX Registry'
onChange={this.updateQuery}>
Expand All @@ -46,6 +46,12 @@ export class VSXExtensionsSearchBar extends ReactWidget {

protected updateQuery = (e: React.ChangeEvent<HTMLInputElement>) => this.model.query = e.target.value;

protected updateSearchTerm(term: string): void {
if (this.input) {
this.input.value = term;
}
}

protected onActivateRequest(msg: Message): void {
super.onActivateRequest(msg);
if (this.input) {
Expand Down

0 comments on commit 103e19b

Please sign in to comment.