Skip to content

Ontology Autocomplete (hpo-ontology-autocomplete) ​

The OntologyAutocompleteComponent is a lightweight, high-performance lookup widget built with plain HTML/CSS.

It supports both instant selection and an optional two-step confirmation flow.

Backend Integration ​

The widget expects all option suggestions to implement the OntologyMatch contract.

This component relies on a backend (e.g., a Rust-based autocompleter via Tauri invokes) transformed into an Observable stream:

typescript
protected performHpoAutocomplete(query: string): Observable<OntologyMatch[]> {
  return from(this.configService.performHpoAutocomplete(query)).pipe(
    catchError(err => {
      this.notificationService.showError(String(err));
      return of([]); // Fail gracefully with empty results
    })
  );
}

This can then be passed to the component with this definition

typescript
autocompleteProvider: (query: string) => Observable<OntologyMatch[]>;

In our applications, this is implemented using fenominal.

rust
 pub fn perform_hpo_autocomplete(&self, query: String) -> Result<Vec<OntologyMatch>, String> {
        let autocompleter = self.autocompleter.as_ref().ok_or_else(|| "Autocomplete not initialized".to_string())?;
        let n_term_limit = 20;
        Ok(autocompleter.search_hpo(&query, n_term_limit))
    }

then in our component, we need to transform this into observables:

Implementation Examples ​

  1. Simple Integration (Instant Selection)
html
 <hpo-ontology-autocomplete
  placeholder="Search clinical phenotypes (e.g., Seizures)..."
  [autocompleteProvider]="hpoSearcher"
  (selected)="onHpoTermSelected($event)" />
}

with

typescript
import { Component, inject } from '@angular/core';
import { ConfigService, OntologyMatch } from 'ng-hpo-uikit';

@Component({
  selector: 'app-setup-view',
  standalone: true,
  imports: [OntologyAutocompleteComponent],
  templateUrl: './setup-view.component.html'
})
export class SetupViewComponent {
  private configService = inject(ConfigService);

  // Preserve lexical 'this' context using an arrow function
  hpoSearcher = (query: string) => this.performHpoAutocomplete(query);

  onHpoTermSelected(term: OntologyMatch) {
    console.log('Selected term:', term);
  }
}

2. Two-Step Confirmation Workflow ​

Use this mode when you want to guard selections with an explicit confirmation action before committing changes to the parent workspace state.

html
<hpo-ontology-autocomplete
  [autocompleteProvider]="hpoSearcher"
  [requireConfirmation]="true"
  (selected)="addTermToWorkspace($event)">
</hpo-ontology-autocomplete>

API Reference ​

Component Selector

typescript
<hpo-ontology-autocomplete />

Inputs (Signal Inputs) ​

Input NameTypeDefault ValueDescription
placeholderstring'Search ontology term...'The placeholder string displayed inside the text input box.
inputStringstring''Initial or programmatic text value to seed into the input control field. Changing this triggers an immediate focus and select text animation.
autocompleteProvider(query: string) => Observable<OntologyMatch[]>RequiredA closure callback function executing your custom backend network request filter payload.
requireConfirmationbooleanfalseIf true, adds a dedicated "Confirm" button step instead of emitting the value instantly upon dropdown selection.

Outputs (output) ​

Output NameTypeDescription
selectedEventEmitter<OntologyMatch>Emits the complete OntologyMatch data object whenever a user explicitly clicks on a term from the autocomplete dropdown list.