Skip to content
New issue

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

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

Already on GitHub? # to your account

Provide a prop for sorting results within the Autocomplete #422

Closed
Ibabalola opened this issue Feb 28, 2023 · 1 comment · Fixed by #423
Closed

Provide a prop for sorting results within the Autocomplete #422

Ibabalola opened this issue Feb 28, 2023 · 1 comment · Fixed by #423
Labels
enhancement New feature or request
Milestone

Comments

@Ibabalola
Copy link
Contributor

Ibabalola commented Feb 28, 2023

Within the autocomplete compenent, I would like to control the way that results are ordered by providing the autocomplete component with an optional search function.

Currently results are ordered in the same order that they are given within the options prop, however I would like to have the results ordered by specified ranking function that is passed to the autocomplete as an optional prop.

// we need a way to sort the array of strings within filtered, 
// based on a provided search function passed in as a prop 
const filtered = options.filter((optionsName) =>
 optionsName.toLowerCase().includes(value.toLowerCase())
);

for example:

  quickSearch = (value: string) => {
    const queryStr = value.toLowerCase();
    options.toLowerCase().includes(queryStr);

    const filtered: string[] = options
      .filter((optionsName: string) => optionsName.toLowerCase().includes(value.toLowerCase()))
      .sort((a: string, b: string) => {
        // code that will sort the valid results
    });

    return filtered;
  };
  
  <Autocomplete 
    .. // usualy props
    search={this.quickSearch}
  />

If a search function is not provided the autocomplete should display results as it is currently doing.

@Ibabalola Ibabalola added the enhancement New feature or request label Feb 28, 2023
@Ibabalola Ibabalola added this to the 0.7 milestone Feb 28, 2023
@Ibabalola Ibabalola linked a pull request Feb 28, 2023 that will close this issue
@daniele-zurico
Copy link
Contributor

Closed by #423

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants