Before going any further, know this:
Much of the work on this task took place here: #2346973: Improve usability and accessibility of long select lists. It eventually became apparent that this needed its own issue
- Are you looking for the issue regarding a drop-in replacement for jQuery UI autocomplete, for stuff like entity reference fields? this is that issue
- Are you looking for the issue regarding UX improvments to
<select>
elements, making it easier to deal with long lists of options? That is a different issue, and it is here: #2346973: Improve usability and accessibility of long select lists
Problem/Motivation
We are in the process of deprecating jQuery UI in core. jQuery UI's autocomplete is among the components that need to be removed/replaced.
As mentioned in the parent issue: #3067261: [Plan] Remove jQuery UI components used by Drupal core and replace with a set of supported solutions
The OpenJS Foundation lists jQuery UI as an Emeritus project in https://openjsf.org/projects/ which is described as:
Emeritus projects are those which the maintainers feel have reached or are nearing end-of-life
Well before the need to deprecate jQueryUI emerged in mid-2019, there has been interest in replacing jQueryUI with something with better UX and accessibility (which is evident in this issue being created several years prior to mid-2019).
Proposed resolution
First, some context regarding the decisions made in this specific resolution
Because it was clear the new autocomplete would not be fully backwards compatible with jQuery Ui autocomplete, it was decided to introduce the new Autocomplete as an experimental module and leave jQuery UI autocomplete as the default until Drupal 10. This would provide sites with adequate time to make any changes required
The original plan for this was to replace jQuery UI with another library. Awesomplete was literally the only library without significant accessibility regressions compared to jQueryUI and one that could be added with the least disruption so that was the library we chose.
It was then observed that the amount of customization required for the Awesomplete implementation was significant enough that we were using very little of the library itself, and it may be simpler to make the solution entirely custom.
Then after that, it was observed that this new autocomplete may be a good candidate for being a standalone library that doesn't depend on Drupal, which would adhere to the policy here: #3176918: [policy, no patch] Publishing / Maintaining JS libraries produced by Drupal that do not have a dependency on Drupal
With that context out of the way, this is the current proposed solution
How it will work in Drupal:
- Create a new A11y_autocomplete standalone npm package that can work independent of Core.
- A11y_autocomplete will be added to /vendor. It will replace the jQuery UI autocomplete library. There will be a backwards-compatible shim that translates any jQuery UI autocomplete usages to work with A11y_autocomplete.
- When the shim is used, deprecation warnings will be triggered.
- The shim also needs to provide Backwards compatible markup
- The shimmed (backwards compatible with jQuery UI) autocomplete will be the default autocomplete. The non-shimmed can be used by setting
<code>#use-drupal-10-autocomplete
to true on the form element render array. - Drupal-specific functionality such as calls to Drupal.t() and Drupal.announce() will take place in a different file. Class methods will be overridden as needed.
- Accessibility implementation will use Accessible Autocomplete from GOV.UK as reference, as it was informed by extensive testing and research. (the accessible autocomplete library was not an option as something Drupal could use as the feature set did not cover what core would need from an autocomplete.
Steps taken prior to the proposed resolution
Several other options were evaluated. Note that all links to evaluations go a separate issue: #2346973: Improve usability and accessibility of long select lists, the issue that this originated from.
- https://github.com/jshjohnson/ChoicesEvaluation (#189)
- https://harvesthq.github.io/chosen/Evaluation (#194)
- https://github.com/Mobius1/SelectrEvaluation (#195)
- https://github.com/alphagov/accessible-autocomplete (prototype at #182, great accessibility but not considered as it does not support select/multiselect It is strictly for providing suggestions to single-value text fields)
- https://github.com/HemantNegi/jquery.sumoselectEvaluation (#201)
- http://ivaynberg.github.io/select2 (of which https://github.com/woocommerce/selectwoo is a fork of, created to improve accessibility) Evalulation (#193)
- Custom library based on https://react-select.comEvaluation (#200)
- https://selectize.github.io/selectize.js/Evaluation (#199)
- https://leaverou.github.io/awesomplete/Evaluation and prototype (#223)
- https://github.com/github/auto-complete-elementEvaluation (#222)
Other than Awesomplete, nontrivial accessibility problems identified in each evaluation. These problems were discovered from general accessibility testing. In each case, enough issues were found that it wasn't worth devoting additional time to strictly checking against W3 specs.
Remaining tasks
- Accessibility review
- JS review
- FE Manager review
- UX review
- Product Manager review
- (probably more reviews, this is a major change)
User interface changes
Yes.
API changes
Yes.
Release Notes Snippet
jQuery UI autocomplete has been deprecated and removed, replaced by Drupal's Accessible Autocomplete library. A backwards compatible shim has been added to provide an API surface and markup that is unchanged from jQuery UI Autocomplete. When the shim is used, a deprecation message will be triggered. This shim will be removed in Drupal 10.0.
Deprecation messages can be addressed by setting '#use-drupal-10-autocomplete' => TRUE
on an autocomplete input's render array. This will bypass the shim and deliver the markup and API surface of the Autocomplete as it will be in Drupal 10. If a site's contrib/custom code does not include calls to $().autocomplete
, nor does it have custom styles that impact the autocomplete input's appearance, there is little risk in setting '#use-drupal-10-autocomplete' => TRUE
.