JavaScript & React libraryAPI

Class: Search<T>

A plain TypeScript and HTML implementation of an autosuggest search component.

This component renders a text input and an autosuggest list. It uses the provided search function to find specific items in the data and returns them via onInput and onEnter callbacks.

Type Parameters

Type ParameterDescription
TThe type of suggestion item.

Constructors

Constructor

new Search<T>(container, config?): Search<T>

Creates an instance of the Search component.

Parameters

ParameterTypeDescription
containerHTMLElementThe HTML element that will contain the search component.
config?SearchConfigInterface<T>Optional configuration for the search component.

Returns

Search<T>

Accessors

suggestionList

Get Signature

get suggestionList(): HTMLElement

Returns

HTMLElement

Methods

getHighlightedMatch()

getHighlightedMatch(text): string

Returns a highlighted match of the input text if `highlightMatch` is true. Automatically applied if `suggestionRenderer` is undefined or returns string.

Parameters

ParameterTypeDescription
textstringThe text to highlight.

Returns

string

The text marked with a tag of highlighted match or the original text if `highlightMatch` is false or no match is found.


setDisabled()

setDisabled(disabled): void

Sets the disabled state of the search component.

Parameters

ParameterTypeDescription
disabledbooleanWhether the search component should be disabled.

Returns

void


isDisabled()

isDisabled(): boolean

Returns whether the search component is currently disabled.

Returns

boolean

True if the search component is disabled, false otherwise.


setConfig()

setConfig(config?): void

Sets the configuration for the search component.

Parameters

ParameterTypeDescription
config?SearchConfigInterface<T>The new configuration to apply.

Returns

void


destroy()

destroy(): void

Destroys the component and cleans up DOM elements and event listeners.

Returns

void


clearInput()

clearInput(): void

Clears the input and suggestion list.

Returns

void


hideSuggestions()

hideSuggestions(): void

Hides the suggestion dropdown without altering the current input value.

Returns

void


focus()

focus(): void

Returns

void


blur()

blur(): void

Returns

void