Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Replacement for standard search function in autocomplete #387

Merged
merged 2 commits into from
Jun 22, 2023

Conversation

mauromascarenhas
Copy link

Proposed changes

The current implementation of "onSearch" callback considers every option element when filtering, which causes undesired options to be displayed for autocompletion (see attached screenshots).

This PR aims to replace the current standard search function that should consider only the "id" and "text" attributes, if available, when filtering the given options.

Summary:

  • Enhancements in standard search function:
    • It now considers only the "id" and "text" attributes;
    • Localized "lowercase" (better internationalization);
    • Standard search still does not takes "text" into consideration if it is not provided;
    • Reduced algorithmic complexity (no longer makes two iterations over the array and does not consider every option entry).
  • Docs:
    • Removed references to "old data type";
    • Added descriptions for option "id", "text" and "image" attributes;
    • Replaced sample implementation of standard search function.

Screenshots (if appropriate) or codepen:

Current behaviour

It displays "google" as a option, even though the word does not have an "a" on its spelling (it is possible to reproduce it in the current version of the docs 😞).

Autocomplete considers "Google" as valid suggestion when "a" is typed

Autocomplete with new "standard search" implementation

Autocomplete considers only "Apple" as valid suggestion when "a" is typed

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to change).

Checklist:

  • I have read the CONTRIBUTING document.
  • My commit messages follows the conventional commit format
  • My change requires a change to the documentation, and updated it accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Standard search function no longer takes "image" into consideration:
    - Improved algorithmic "performance" O(m x 2n) -> O(n);
    - Localized "lower case" (better i18n).
- Improved description of "data array" option for Autocomplete:
    - Removed description of "old" data option.
- Added comment to "old search implementation" sample;
- Replaced "standard search function" implementation sample.
@wuda-io wuda-io merged commit 3dcfae8 into materializecss:v2-dev Jun 22, 2023
@mauromascarenhas mauromascarenhas deleted the autocomplete-function branch June 23, 2023 03:36
@wuda-io wuda-io mentioned this pull request Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants