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

[Autocomplete] Tom Select Options Plugins #2657

Closed
wants to merge 4 commits into from

Conversation

luchidalgo
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fix #2656
License MIT

@carsonbot carsonbot added Autocomplete Bug Bug Fix Status: Needs Review Needs to be reviewed labels Mar 25, 2025
Copy link

github-actions bot commented Mar 25, 2025

📊 Packages dist files size difference

Thanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
Please review the changes and make sure they are expected.

FileBefore (Size / Gzip)After (Size / Gzip)
Autocomplete
controller.js 16.71 kB / 3.97 kB 16.93 kB+1% 📈 / 4.02 kB+1% 📈

Comment on lines +152 to +156
if ('plugins' in this.tomSelectOptionsValue && Array.isArray(this.tomSelectOptionsValue.plugins)) {
this.tomSelectOptionsValue.plugins.forEach((pluginName) => {
plugins[pluginName] = {};
});
}
Copy link
Member

@Kocal Kocal Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given examples (https://tom-select.js.org/plugins/caret-position/ and https://tom-select.js.org/plugins/checkbox-options/) it looks like plugins can also be a key-value object.

Can't we use a more simple solution like this?

Suggested change
if ('plugins' in this.tomSelectOptionsValue && Array.isArray(this.tomSelectOptionsValue.plugins)) {
this.tomSelectOptionsValue.plugins.forEach((pluginName) => {
plugins[pluginName] = {};
});
}
plugins = this.tomSelectOptionsValue.plugins || [];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is treaky : https://tom-select.js.org/docs/plugins/ says we can put just plugin names (simple array) or plugin with options (object in js side). Also with simple assignment we override plugins configuration added line 138 to 150

@@ -214,7 +220,7 @@ export default class extends Controller {
config.shouldLoad = () => false;
}

return this.#mergeObjects(config, this.tomSelectOptionsValue);
return this.#mergeObjects(this.tomSelectOptionsValue, config);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure about that, it looks like a BC no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By doing this, we prevent user-provided options from overwriting the configuration created within this function, especially for plugins.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @Kocal said, it is BC break. By looking at the code, the original idea is: if a user provides some config values, these values always win over default config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can revert this change and merge the config with a copy of tomSelectOptionsValue, without the plugins previously merged by a specific process, in order to avoid them being replaced ?

@carsonbot carsonbot added Status: Needs Work Additional work is needed and removed Status: Needs Review Needs to be reviewed labels Mar 27, 2025
@luchidalgo luchidalgo closed this Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Autocomplete Bug Bug Fix Status: Needs Work Additional work is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Autocomplete] Tom Select Options Plugins
4 participants