Skip to content

Commit

Permalink
rename threshold to minCharacters
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspk06 committed Sep 21, 2023
1 parent 75156c6 commit aa86292
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ export interface RadarAutocompleteUIOptions {
container: string | HTMLElement;
near?: string | Location; // bias for location results
debounceMS?: number, // Debounce time in milliseconds
threshold?: number, // Minimum number of characters to trigger autocomplete
threshold?: number, // DEPRECATED(use minCharacters instead)
minCharacters?: number, // Minimum number of characters to trigger autocomplete
limit?: number, // Maximum number of autocomplete results
layers?: RadarGeocodeLayer[];
countryCode?: string;
Expand All @@ -485,7 +486,8 @@ export interface RadarAutocompleteUIOptions {
export interface RadarAutocompleteConfig extends RadarAutocompleteUIOptions {
container: string | HTMLElement;
debounceMS: number, // Debounce time in milliseconds
threshold: number, // Minimum number of characters to trigger autocomplete
threshold: number, // DEPRECATED(use minCharacters instead)
minCharacters: number, // Minimum number of characters to trigger autocomplete
limit: number, // Maximum number of autocomplete results
placeholder: string, // Placeholder text for the input field
disabled: boolean,
Expand Down
17 changes: 12 additions & 5 deletions src/ui/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ARIA = {
const defaultAutocompleteOptions: RadarAutocompleteUIOptions = {
container: 'autocomplete',
debounceMS: 200, // Debounce time in milliseconds
threshold: 3, // Minimum number of characters to trigger autocomplete
minCharacters: 3, // Minimum number of characters to trigger autocomplete
limit: 8, // Maximum number of autocomplete results
placeholder: 'Search address', // Placeholder text for the input field
responsive: true,
Expand Down Expand Up @@ -101,6 +101,12 @@ class AutocompleteUI {
this.results = [];
this.highlightedIndex = -1;

// set threshold alias
if (this.config.threshold !== undefined) {
this.config.minCharacters = this.config.threshold;
Logger.warn('AutocompleteUI option "threshold" is deprecated, use "minCharacters" instead.');
}

if (options.near) {
if (typeof options.near === 'string') {
this.near = options.near;
Expand Down Expand Up @@ -165,7 +171,7 @@ class AutocompleteUI {
// setup event listeners
this.inputField.addEventListener('input', this.handleInput.bind(this));
this.inputField.addEventListener('keydown', this.handleKeyboardNavigation.bind(this));
if (this.config.hideResultsOnBlur){
if (this.config.hideResultsOnBlur) {
this.inputField.addEventListener('blur', this.close.bind(this), true);
}

Expand All @@ -175,7 +181,7 @@ class AutocompleteUI {
public handleInput() {
// Fetch autocomplete results and display them
const query = this.inputField.value;
if (query.length < this.config.threshold) {
if (query.length < this.config.minCharacters) {
return;
}

Expand Down Expand Up @@ -494,8 +500,9 @@ class AutocompleteUI {
return this;
}

public setThreshold(threshold: number) {
this.config.threshold = threshold;
public setMinCharacters(minCharacters: number) {
this.config.minCharacters = minCharacters;
this.config.threshold = minCharacters;
return this;
}

Expand Down

0 comments on commit aa86292

Please sign in to comment.