We’re using Selectize quite a lot in XWiki (46 files match the word “selectize” in xwiki-platform) to implement various suggest input pickers. Unfortunately this library is not maintained since 2022 and its last release has serious regressions that make it unusable (see Loading...):
Moreover, Selectize depends on jQuery and it uses deprecated jQuery APIs, preventing us from upgrading jQuery to version 4.x where those APIs have been removed.
Given this, I started looking for alternatives, but you have to know that replacing Selectize is not simple and will for sure lead to some regressions / breakages in our extensions. Even though we have a wrapper around Selectize, xwiki-selectize, we expose directly the Selectize JavaScript API, and there is of course the HTML structure and the CSS classes that some extensions may rely on as well.
There are two libraries that offer similar features and seem to be maintained:
The later is particularly interesting because it started as a fork of Selectize, so we can expect less API breakage. With this in mind, I started updating the xwiki-platform code to replace Selectize with Tom Select to see how well it works and to evaluate how big is the breakage. The result is:
It works quite well. I haven’t noticed any regressions in behavior compared to Selectize.
It doesn’t provide a Bootstrap 3 CSS but it provides CSS for Bootstrap 4 and 5, so we’ll have to tweak a bit the CSS to be consistent with the rest of our form controls (but it generally looks good out of the box).
I haven’t noticed any API breakage on the JavaScript side, which is quite surprising.
But the HTML structure is slightly different and the CSS classes have changed (ts-* vs. selectize-*). This means I had to update our CSS, the test page objects and all the rest of the code that was using selectize-* CSS classes.
I also noticed an incompatibility with Prototype.js but fortunately we have ways to patch Prototype.js to workaround this.
Overall it looks good. I’m currently running the integration tests to see if I missed anything. If all is OK I’d like to push this change on 18.2.0RC1 along with the jQuery 4.x upgrade.
When testing before a push, can you run some docker tests with WCAG turned on to make sure the base select does not violate WCAG? There might be new violations in some specific use cases, but the most important to check before a first merge is that we don’t flood the report with violation and fail too many test suites at once.
@mflorea we’ll need to plan a call at some point to define a good API for an equivalent UI component in the Abstract Design System. I think this is a good step to avoid having to redo this kind of breaking migration again in the future.
Do those two CSS breakages have significant consequences for contrib extensions using Selectize?
Definitely. The way we used and exposed Selectize is very messy… Replacing it with Tom Select is a short / medium term solution to allow us to upgrade jQuery. Long term we need to hide the underlying implementation and expose our own API.
They can. I checked quickly the xwiki-contrib matches for “selectize” and I noticed 3 possible failures:
Thanks for explicating the risks.
I guess I’m still +1 because I can’t think of a better option.
Some brainstorming to limit the breakages: can we tweak the build to serve a custom version of css/selectize.bootstrap3.css?
I check the code to see if customizing the classes was an option, but using ts- is a documented breaking change and is hardcoded everywhere…
For the rest, I don’t think we can do much.
I was thinking to load the Tom Select CSS automatically, from JavaScript, to avoid hard-coding it in so many places. With this, the load of the Selectize CSS will fail (if the WebJar is uninstalled, which might not happen on upgrade) but the end user won’t notice.
For the last item, I can provide $.fn.selectize() as a shortcut for $.fn.xwikiSelectize(), when not set already, for backward compatibility.
For the changed CSS selectors I don’t have a solution. When used inside CSS, the breakage should be minimal I think. But if they were used in JavaScript, to locate some DOM elements, the breakage could be serious. Fortunately, I haven’t seen Selectize CSS selectors used in JavaScript code when scanning the “selectize” matches for xwiki-contrib.