Skip to content

feature(Autocomplete) select options #584

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

Merged

Conversation

gselderslaghs
Copy link
Member

Proposed changes

This pull request fixes #552 and allows multiple selection by method call

Example:

M.Autocomplete.init(document.querySelectorAll('.autocomplete'), {
    isMultiSelect: true,
    data: [
        { id: 'Value A' },
        { id: 'Value B' },
        { id: 'Value C' }
    ],
});
M.Autocomplete.getInstance(document.querySelector('.autocomplete')).selectOptions(['Value A']);

Additionally I put setValues in deprecated state as it causes issues as described in #552, it still can be used but I would recommend switching to setOption and setOptions methods for selecting values as it would be better to remove the method in one of the next releases, except if someone has another opinion, please shoot

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.

@gselderslaghs
Copy link
Member Author

Changelog

  • Resolved conflicts
  • Fixed typo in spec test description

@wuda-io
Copy link
Member

wuda-io commented Feb 24, 2025

I think we should keep setValues and keep changing the options (which can then be selected) dynamically. For example when loading small batches of a long list from a database. Or how would you handle this usecase?

@gselderslaghs
Copy link
Member Author

Since my bug notices in #552 I don't use this method, it works well with setMenuItems, from my opinion it's duplicates in expected behavior and setMenuItems works as expected while setValues results in different outcomes

@wuda-io
Copy link
Member

wuda-io commented Feb 24, 2025

ok that makes sense! Thanks for the quick reply 👍

@wuda-io wuda-io merged commit fe0a6a4 into materializecss:v2-dev Feb 24, 2025
1 check failed
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