Before going any further, know this:

There's a patch of comments - #175-#235 - that may be a bit confusing as some of what was discussed spun off into a different issue: #3076171: Provide a new library to replace jQuery UI autocomplete

Anything in this issue that specifically discusses replacing jQueryUI with Awesomplete is no longer relevant to this issue and can be ignored. Everything else particularly the library evaluations, are still fully relevant. The desired improvements to select elements will need to be accomplished with a different library than what is used for autocomplete.

In other words: The stuff about Awesomplete is not relevant to this issue, but everything else is. . This is about improving the UX of select lists.

Problem/Motivation

Improve usability and accessibility of long select lists and autocomplete tagging widgets.

Proposed resolution

  • Evaluate possible libraries
  • Create a pro / con list and required feature list for the library candidates, for example
    • Code style
    • Maturity
    • Responsiveness
    • Accessibility
    • UX
    • UI
    • Modularity
    • AJAX support
    • Single / multi select
    • Filter search
    • ...
  • Choose the best matching library for Drupal's needs.

Libraries evaluated so far

(disregard the Awsomplete evaluations - it is a great library, just not relevant to this issue)

Remaining tasks

  • Determine specific requirements for new functionality
  • Compare against the libraries reviewed so far, and evaluate additional ones when discovered
  • Confirm the desired replacement is sufficiently accessible

User interface changes

Yes.

API changes

Yes.

CommentFileSizeAuthor
#223 awesomplete-prototype.patch75.81 KBbnjmnm
#193 select2-commas-and-spaces.patch103.45 KBbnjmnm
#188 react-select-prototype.patch254.69 KBbnjmnm
#188 select2-prototype.patch103.31 KBbnjmnm
#188 choices-feasible-prototype.patch253.45 KBbnjmnm
#182 accessibleautocomplete-prototype.patch168.47 KBbnjmnm
#182 choicesjs-prototype-libfix.patch248.04 KBbnjmnm
#181 choicesjs-prototype.patch248.29 KBbnjmnm
#158 2346973-comment-time.png67.86 KBnithinkolekar
#142 replace_jquery_ui-2346973-142.patch470.35 KBpk188
#132 interdiff-2346973-126-132.txt1.76 KBchr.fritsch
#132 replace_jquery_ui-2346973-132.patch610.46 KBchr.fritsch
#126 2346973-126.patch610.51 KBphenaproxima
#123 replace_jquery_ui-2346973-123.patch20.91 KBManuel Garcia
#120 jQuery_autocomplete_ui_replace-2346973-120.patch20.91 KBjoginderpc
#117 2346973-117.patch397.23 KBvprocessor
#66 interdiff.txt414 bytesamateescu
#66 2346973-66.patch350.65 KBamateescu
#61 interdiff.txt1.36 KBamateescu
#61 2346973-61.patch350.71 KBamateescu
#61 2346973-61-drupal-only-changes-do-not-test.patch30.81 KBamateescu
#60 core-js-autocomplete-tokenizer-2346973-60-do-not-test.patch6.56 KBnod_
#59 interdiff.txt2.45 KBamateescu
#59 2346973-59.patch346.22 KBamateescu
#59 2346973-59-drupal-only-changes-do-not-test.patch26.32 KBamateescu
#58 select2-tokenizer.txt2.51 KBamateescu
#56 interdiff.txt5.18 KBamateescu
#56 2346973-56.patch346.85 KBamateescu
#56 2346973-56-drupal-only-changes-do-not-test.patch26.95 KBamateescu
#55 screen.png5.59 KBaspilicious
#55 screen2.png7.19 KBaspilicious
#55 author.png5.11 KBaspilicious
#55 screen3.png6.71 KBaspilicious
#54 interdiff.txt12.46 KBamateescu
#54 2346973-54.patch343.02 KBamateescu
#54 2346973-54-drupal-only-changes-do-not-test.patch23.12 KBamateescu
#43 interdiff.txt1.27 KBamateescu
#43 2346973-43.patch352.04 KBamateescu
#41 interdiff.txt22.99 KBamateescu
#41 2346973-41.patch350.77 KBamateescu
#41 2346973-41-drupal-only-changes-do-not-test.patch30.87 KBamateescu
#37 interdiff.txt7.34 KBamateescu
#37 2346973-the-full-thing.patch333.79 KBamateescu
#37 2346973-drupal-only-changes-do-not-test.patch13.89 KBamateescu
#2 Tags_edit_text_list_1_item.png53.5 KBmgifford
#2 4_results_first_accurate.png26.24 KBmgifford
#2 4_results_ONLY_3.png31.7 KBmgifford
#2 frog_chosen.png26.54 KBmgifford
#2 NO_Please_enter_1_or_more_character.png40.22 KBmgifford
#1 One_result_is_available.png181.92 KBmgifford
#1 You_are_currently_francais.png155.83 KBmgifford
#1 6_results_are_available.png142.75 KBmgifford
#1 94_results_are_available.png244.98 KBmgifford
#1 English_pop_up_button.png223.71 KBmgifford
core-js-select2.patch320.52 KBnod_
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mgifford’s picture

This looks sharp. Works as expected without a mouse which is great.

I've only looked at this with VoiceOver, but there are some issues here. I've asked for a blind user to review this and provide better feedback. As a sighted person, my use of a screen reader is pretty basic.

When I first go to the screen I'm simply informed that there is an English pop up button:
Screenshot of VoiceOver's comments on select2 dropdown

I go down and I get all 94 results:
Screenshot of VoiceOver's comments selecting dropdown

I enter in a key (not that there is any indication to me that this would have any impact - it isn't very discoverable) and I get a summary of results. It would be nice if it were able to read that shortened list of results.
Screenshot of VoiceOver's comments after hitting the letter b

When one option has been selected that isn't english and you go back to edit the dropdown:
Screenshot of VoiceOver's comments when french has previously been selected.

When you've selected one result.
Screenshot of VoiceOver's comments when one result available

mgifford’s picture

I added some elements to my taxonomy, then went http://sb8acaa3c676552c.s3.simplytest.me/node/add/article

I've attached the screenshots below, but not fleshed out the descriptions. The file names kinda illustrate the problems.

It works but also needs work.

Bojhan’s picture

Oeeh, nice. Looking forward to the A11y review

mgifford’s picture

I've uploaded so many images I can't find the patch anymore.

I am going to have to write up what it should be and then see what we can do to make it that way. We do need to have some action points.

Accessibility is probably going to be the major hurdle for this patch (and I'm not sure whether it's for Select2 or the implementation). I do hope we can git it in though as it's a nice feature.

mgifford’s picture

I'm going to write out what should happen for accessibility:

A) On Choose a language
1) Rather than saying "English pop up button" it should say "Language selection pop up. English selected."
2) On entering the pop up, the user should be told "94 results are available, use up and down arrow keys to navigate" it should say "To choose a language, enter the first few characters. 94 results are currently available."
3) When a key is pressed the user should be told that the list changed. Rather than "6 results are available, use up and down arrow keys to navigate." -- it would be nice if it was more consistent with autocomplete and would read the list.
4) If there is only one result, it should read the result. "One result is available, press enter to select it." is a pretty useless description. In my example it should read something like "Bosanski selected, press enter to save and continue."

I can't see the source code to see how viable that actually is.

mgifford’s picture

B) With the taxonomy term, it is important to provide more context as this will be very confusing.

1) When you first tab to the form you're told "Tags edit text list 1 item" but really should be told that this is an empty form and that they should start typing to either get a list of previously selected tags or to enter a new tag.
Screenshot of an initial screen when entering a tag

2) On hitting f, I'm told that "4 results are available, use up and down arrow keys to navigate" it would be nice if it were consistent with autocomplete right now and list the selection.
Screenshot of dropdown with selection

3) If there's already a tag selected, the count is off. "4 results are available" seems wrong given there are 3 in the list:
Screenshot of dropdown with 3 items selected

4) Frog is pronounced when selected:
Screenshot with frog selected from a list of f words.

5) The tags have a nice description field which is available but it isn't read to the screen reader as it's done as a title to the input form. It says "Please enter 1 or more character"
No description is available for screen reader users.

oushen’s picture

Hi. When D8 go to beta release, I will port Select2 module to D8 and we can use it for tags (and other taxonomy ref) fields, autocomplete fields and other.

nod_’s picture

Thanks oushen, any chance you can help out this patch? I'd rather have that in core in 8.1.0 if we can instead of contrib. That way we'd make sure the integration is accessible and that many more other contrib modules can use it (like rules maybe).

droplet’s picture

get the patch back.

mgifford’s picture

I had to search for a cached version of the page to get the patch:
https://www.drupal.org/files/issues/core-js-select2.patch

attiks’s picture

The summary says to use it for taxonomy, why don't we use it for multiple selects as well?

mgifford’s picture

I think @nod_ was primarily developing this as a use case to see what problems we'd run into.

There are a few accessibility problems with it at this point. I've tried to articulate how they should be improved.

oushen’s picture

attiks, at this week I will publish dev release of Select2 module for D8, with this module you can use it for all select form elements, autocomplete fields and define select2 options for custom elements by Forms API.

attiks’s picture

#13 Cool

Bojhan’s picture

Issue tags: +D8MI, +#amsterdam2014

Alright, so this greatly impacts i18n - who made a major follow up.

tkoleary’s picture

Issue tags: -D8MI, -#amsterdam2014

Thanks oushen, any chance you can help out this patch? I'd rather have that in core in 8.1.0 if we can instead of contrib. That way we'd make sure the integration is accessible and that many more other contrib modules can use it (like rules maybe).

+1 to that!

tkoleary’s picture

@mgifford @nod:

If "choose language" is not being read it's because the "aria labeledby" attribute is missing I think.

tkoleary’s picture

The summary says to use it for taxonomy, why don't we use it for multiple selects as well?

Amen to that

tkoleary’s picture

@mgifford

The "please enter one character" issue also looks like aria labeledby is missing

mgifford’s picture

Issue tags: +Accessibility

We can add aria-labelledby to the 'Choose language' title in core/lib/Drupal/Core/Installer/Form/SelectLanguageForm.php

I think the "please enter one character" is a vendor issue though that's part of Select2. Not that we can't change that, but it is a change for stuff up-stream.

With any dynamic tool like Select2 WAI-ARIA is going to need to be added to add the required semantics.

Drupal.announce() is also worth looking at https://www.drupal.org/node/2014521

tkoleary’s picture

With any dynamic tool like Select2 WAI-ARIA is going to need to be added to add the required semantics.

Yes, but having said that, from my research the library already has more aria roles natively than any other and if we make that more robust it would be more responsible for us to add them upstream submitting pull requests to Select2 on github. That way others can benefit as well.

mgifford’s picture

I'm totally onboard with providing patches to Select2 and pushing them upstream. I think they'd be open and everyone would benefit.

I'm just not a JS person so won't be leading the way in developing the patch.

Xano’s picture

Can you please update the issue summary so it includes the reasons for adding this, which problems it solves, etc?

Also, this looks like Chosen. Do they really do similar things and if so, how do they differ?

mgifford’s picture

Issue summary: View changes
Issue tags: +Needs issue summary update

Took a quick look for comparisons of Select2 vs Chosen.

They do pretty similar things from what I can tell.

Bojhan’s picture

It is worthwhile to look at Kevin his evaluation at https://docs.google.com/spreadsheets/d/1vifOGL_4wgOl6sy2Os59k24saIHvwFFQ...

andypost’s picture

This would be really useful for new UI for related help topics #2351991-55: Add a config entity for a configurable, topic-based help system

andypost’s picture

andypost’s picture

droplet’s picture

Comment #6: 3,

I sent a patch to upstream and it's merged now. https://github.com/ivaynberg/select2/pull/2726

Wim Leers’s picture

This would also finally solve the many huge problems (UX-wise and otherwise) with jQuery UI Autocomplete explained at #675446-271: Use jQuery UI Autocomplete. Great work here :)

tkoleary’s picture

@Nod

Given the upstream changes to Select2 for a11y are we unblocked on rolling a patch?

mgifford’s picture

Is this going to have to get bumped to 8.1.x.?

Is there any chance that a patch will get into 8.0.x for this?

Bojhan’s picture

Version: 8.0.x-dev » 8.1.x-dev
mgifford’s picture

Status: Needs review » Postponed
YesCT’s picture

Issue summary: View changes

I put the templates in the summary, but there are details I'm not sure of.

What is the motivation here?
Why is this a feature request?
Could this qualify for beta under "prioritized change"?

YesCT’s picture

Issue summary: View changes
amateescu’s picture

Version: 8.1.x-dev » 8.0.x-dev
Category: Feature request » Task
Priority: Normal » Major
Status: Postponed » Needs review
FileSize
13.89 KB
333.79 KB
7.34 KB

I think it's very important to get this into 8.0.0 for multiple reasons:

Also note that Entity reference is very likely to replace the taxonomy term reference field in D8 so the last point outlined above is going to get in everyone's face soon enough.

I started with @nod_'s patch referenced in #10 but I'm not sure that creating one-off libraries for every select element that wants to use Select2 is a good long term strategy, and we should rather aim for a much better DX by integrating it right into Form API's select element via an optional #select2 property.

Haven't touched the autocomplete bits yet but this patch shows how I envision the Form API integration. I also added the #select2 option in two more places, the timezone selectors, just to demonstrate how easy it should be for everyone to use it.

jibran’s picture

+++ b/core/misc/drupal.js
@@ -86,12 +86,12 @@ if (window.jQuery) {
+        //try {
...
+        //}
+        //catch (e) {
+          //errors.push({ behavior: i, error: e });
+        //}

Comment out code.

Wim Leers’s picture

+++ b/core/lib/Drupal/Core/Render/Element/FormElement.php
@@ -128,4 +129,43 @@ public static function processAutocomplete(&$element, FormStateInterface $form_s
+  public static function processSelect2(&$element, FormStateInterface $form_state, &$complete_form) {

Why on \Drupal\Core\Render\Element\FormElement and not on \Drupal\Core\Render\Element\Select?

AFAIK there is no other element that could use it?

amateescu’s picture

Why on \Drupal\Core\Render\Element\FormElement and not on \Drupal\Core\Render\Element\Select?

AFAIK there is no other element that could use it?

Text elements that might have a different purpose than autocomplete can use it too, so why not give them the possibility? :)

amateescu’s picture

Title: Use select2 » Replace jQuery UI autocomplete with Select2
FileSize
30.87 KB
350.77 KB
22.99 KB

Here's the complete integration with Drupal's autocomplete requirements, with proper markup escaping and all that.

The only thing left that still needs work is to provide support for our "term with, comma" syntax, which is not supported by Select2 at all. Every time this question comes up on github or other support forums, people just say to use "|" as a delimiter, but I don't think we have that luxury of choice in Drupal so we'll need to provide our own tokenizer function. I looked a bit at that code but I hope @nod_ can help out here since he's, well.. more familiar with JS :)

Status: Needs review » Needs work

The last submitted patch, 41: 2346973-41.patch, failed testing.

amateescu’s picture

Assigned: Unassigned » nod_
Status: Needs work » Needs review
FileSize
352.04 KB
1.27 KB

Fixed that last test. Let's see what @nod_ thinks about #41.

jibran’s picture

Can we have a core only patch *pretty please*?

amateescu’s picture

It's in #41?

jibran’s picture

pardon my ignorance patch looks good to me.

xjm’s picture

Let's get the beta evaluation updated to be more than boilerplate? :) It would be really valuable to summarize in that table why this is major, what the improvements for accessibility and such are, and what the disruption would be within core, for contrib, etc. :)

The diffstat for the core-only patch in #41 is nice.

xjm’s picture

+++ b/core/modules/views/src/Tests/ViewsTaxonomyAutocompleteTest.php
@@ -75,8 +75,8 @@ public function testTaxonomyAutocomplete() {
-      'value' => $label,
-      'label' => String::checkPlain($label),
+      'id' => $label,
+      'text' => String::checkPlain($label),

E.g. this change in the array structure is a (reasonably small) disruption for contrib. Etc.

amateescu’s picture

Issue summary: View changes

Improved the entire IS a bit, I hope it's more clear now :)

attiks’s picture

#48 does this mean that the keys need to be changed depending on the fact that you use select2?

Ex: if I remove the "'#select2' => TRUE" from a select, will this break the code?

amateescu’s picture

@attiks, the keys have to be changed everywhere. But that's only about the autocomplete API, not about using Select2 in regular select elements.

nod_’s picture

I don't think we need to change the keys, the naming makes more sense as it is now and it's trivial to map that on the JS side.

amateescu’s picture

I changed them because we also did it when we switched to jQuery UI autocomplete in #675446: Use jQuery UI Autocomplete, so I thought we want to follow the Select2 defaults. I don't have any strong opinion about it though :)

amateescu’s picture

I thought about it some more and I agree that the value => label combination makes more sense than id => text, so let's drop the slight API change and just keep the huge UX improvement :)

aspilicious’s picture

FileSize
6.71 KB
5.11 KB
7.19 KB
5.59 KB

I WANT this patch so I tested it but found some problems.

screen
- tags with spaces don't get recognised

screen3
- When editing the same node nothing gets recognised

screen2
- Why is timezone a select 2 field and country not?

author
- Can there be multiple authors? That's confusing. After the first author the autocomplete doesn't work anyway.

amateescu’s picture

@aspilicious, thanks for the review!

- tags with spaces don't get recognised

That's already mentioned in #41 :)

- Why is timezone a select 2 field and country not?

Yeah, the country selector is long enough to need the Select2 widget. Added.

- Can there be multiple authors? That's confusing. After the first author the autocomplete doesn't work anyway.

Fixed.

nod_’s picture

Quick review, I'm looking at the tag splitting thing.

  1. +++ b/core/core.libraries.yml
    @@ -808,3 +808,19 @@ underscore:
    +  js:
    +    assets/vendor/select2/select2.js: {}
    +    misc/select2.js: {}
    +  css:
    +    theme:
    +      assets/vendor/select2/select2.css: {}
    +  dependencies:
    +    - core/jquery
    

    Dependencies are not right, the misc file should be in drupal.autocomplete. Not here since it'd make select2 depend on core/drupal and core/drupalSettings.

  2. +++ b/core/lib/Drupal/Core/Render/Element/FormElement.php
    @@ -123,6 +124,49 @@ public static function processAutocomplete(&$element, FormStateInterface $form_s
    +      $options = isset($element['#autocomplete_options']) ? $element['#autocomplete_options'] : array();
    

    Default should be an object, otherwise the JSON will end up as [], not {}.

  3. +++ b/core/misc/autocomplete.js
    @@ -41,132 +39,51 @@
    +  var select2Options = {
    

    We might want to expose that in drupalSettings for people to be able to change it globally, not just with data attributes.

  4. +++ b/core/misc/autocomplete.js
    @@ -174,45 +91,17 @@
    +      $(context).find('input.form-autocomplete').once('autocomplete')
    

    Set a data attribute instead of a class and use it to select elements please. data-drupal-autocomplete would work.

  5. +++ b/core/modules/node/src/Entity/Node.php
    @@ -378,6 +378,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    +//      ->setCardinality(1)
    

    ?

amateescu’s picture

FileSize
2.51 KB

@nod_, I was looking into the tokenizer thing as well and I got it mostly working, here's my WIP diff.

amateescu’s picture

Quick update for the review in #57:

  1. Dependencies are not right, the misc file should be in drupal.autocomplete. Not here since it'd make select2 depend on core/drupal and core/drupalSettings.

    Not sure that's correct, that code is just registering Select2 into our library system, and it's only dependency is on jQuery. Since we've now integrated Select2 into Form API, this is not tied to autocomplete anymore.

  2. Fixed.
  3. We might want to expose that in drupalSettings for people to be able to change it globally, not just with data attributes.

    I don't know what's the "right way" to do this. Do we usually expose stuff in drupalSettings from inside a js file?

  4. Fixed as discussed in IRC.
  5. Oops :)
nod_’s picture

This file is the problem: misc/select2.js: {} Look at all our other vendor libs, they don't have extra Drupal dependencies (this file will crash JS because Drupal isn't defined if you load only core/select2).

Here is the tokenizer thing with some improvments in splitValues. Based on #56.

amateescu’s picture

Finally understood what @nod_ meant with the separate library. Fixed that and incorporated the tokenizer from #60 into the main patch.

aspilicious’s picture

Status: Needs review » Needs work

Tag autocompletion still has issues. I made two tags:

"Some tag", "a new tag"

When editing the node you get 1 merged tag: "some tag, a new tag". The tag list in the backend looks ok, so it's a js thingie.

nod_’s picture

You can laugh at me:

diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js
index 3817c7d..f0fae1b 100644
--- a/core/misc/autocomplete.js
+++ b/core/misc/autocomplete.js
@@ -77,7 +77,7 @@
 
     // If there are no enclosing character splitting is easy.
     if (value.indexOf(enclosing) === -1) {
-      result = value.split(enclosing);
+      result = value.split(token);
     }
     // Handle enclosed token.
     else {

Then it works.

amateescu’s picture

/me giggles at @nod_ :D

The fix from #63 fixes the problem mentioned by @aspilicious, but there's still one small issue: you can never remove a tag which contains a comma :) It is removed visually from the input element but when you save the node, it's still there, sometimes even duplicated.

quicksketch’s picture

This looks like a great direction.

Looking at the library and the patch, what approach should be used to bring consistency to non-Select2 select lists and Select2-enabled select lists? @aspilicious's image in #55 shows the differences pretty clearly. I'm guessing the default styling for Select2 would be left in place (considering there are no "skins") and the theme would take on the responsibility of styling them individually (as Seven theme styles select lists already).

amateescu’s picture

Status: Needs work » Needs review
FileSize
350.65 KB
414 bytes

I'm not sure that the Seven theme styles select lists already. At least on FIrefox/Chrome on Kubuntu, the select lists look like the OS ones, and I don't see any select-specific code in firebug.

My proposal for styling is to use the Seven style guide, so even if Select2-enabled select elements won't look like the regular ones, at least they'll be consistent with the rest of the theme. We already have a dedicated issue for this: #2318665: Implement the dropdown menu component styling into the autocomplete widget, but I'm not opposed to doing that work here.

Here's a reroll for current HEAD + the small fix from #63 (Drupal only patch for review is in #61).

@nod_, do you have some time to look into that small (last) issue with the new tokenizer found in #64?

LewisNyman’s picture

I'm not sure that the Seven theme styles select lists already.

It does, but only on Webkit because cross browser support for styling the native
element is poor. #2207391: Style select elements in Webkit only

LewisNyman’s picture

I have to say this is looking very good. I recommend we stick with the default library styling, and work on the Seven styling in #2318665: Implement the dropdown menu component styling into the autocomplete widget

nod_’s picture

Assigned: nod_ » Unassigned

Umm looks like a new version of select2 got out (in beta still), the catch is that select 2 can't work with inputs anymore, it expect a select element (it makes sense given the lib name). See Select2 v4 beta. The consequence for us is that the current tag input field for taxonomy won't work with the new version of select2. That's a bummer.

We can transform tag input in a select with JS (progressive enhencement and all) but the data sent to the server will be different, unless we serialize the values from select2 in the input on submit.

amateescu’s picture

Yes, I saw the new version of the library and that it contains quite a few things that break our current integration, but that doesn't mean we should drop this issue, I hope?

the data sent to the server will be different, unless we serialize the values from select2 in the input on submit.

This doesn't look like an unsolvable problem :)

LewisNyman’s picture

hmm, I don't understand. How would you add a new value that doesn't exist as an option in the select dropdown? Or is that now outside of the use case of Select2?

amateescu’s picture

@LewisNyman, a select dropdown is needed just as the initial element, adding new values / tagging works just like before: https://select2.github.io/examples.html#tags

Wim Leers’s picture

Indeed, looks like we can work with Select2 version 4 just fine; we'll just have to change #type => input to #type => select.

LewisNyman’s picture

I think a select element feels like a much better JS fallback than a blank text input.

Wim Leers’s picture

#74: except that you can type in a blank input[type=text], but the <select> Select2 uses would be empty in our case, since free tagging in Drupal allows for thousands of terms to be created, not all of which can be listed. Disable JS and look at https://select2.github.io/examples.html#data-ajax for a more accurate fallback UX.
And that is actually a great point: the no-JS experience. Do we even still care about that? E.g. dropbuttons are also completely broken without JS.

quicksketch’s picture

I just spent a day trying to upgrade the D7 Select2 module to support the new 4.0.0 version of the library. It *really* doesn't like working with input fields. Dropping support for (hidden) inputs is actually listed as a feature of the new version: https://select2.github.io/announcements-4.0.html#hidden-input

In trying to use it on input textfields, Select2 simply has no support whatsoever now. It actually tries to embed <option> tags inside of the textfield <input> element. The only hope we'd have is doing as Wim suggested and replace the textfields with select elements.

I don't know if this is going to be a suitable replacement for autocomplete text fields. A select list isn't going to be the right element when dealing with large lists, which is pretty much any situation we have autocomplete currently: author name, term tags, the search on api.drupal.org, etc.

The whole situation is disappointing. The "best" library for autocomplete basically doesn't want to deal with autocomplete and wants to focus exclusively on replacing select list elements. I suppose it shouldn't be too surprising, considering their past claims that autocomplete/type-ahead is outside the scope of their goals: https://github.com/select2/select2/issues/17.

aspilicious’s picture

We have a site with more than 6000 tags and counting (since september 2014). We can't use select fields for those in combination with select2 because it's nearly impossible to render.
Making tags a select field would introduce severe performance issues.

As I do see the advantage for 95% of the use cases I would like to have a fallback to the current behaviour. But that would be hard because one widget is a textfield and the other a select widget :s

Damn...

Can't we fund a JS genius to make a drupalSelect fork of select2? XD

droplet’s picture

@#77,

You won't tagging 6k tags in ONE node ??

Technically, we can rendering select list in client side (converting from input).

see patch in #66, it still making a lot of changes to JS/PHP code. It's a sign that D8 still having bad Autocomplete API architecture in CORE. I think we need to shape it better API to adopt different JS libs for future developers (without CORE JS & PHP patching).

attiks’s picture

#78 We have similar (and bigger) vocabularies as @aspilicious mentioned in #77, outputting a select list is not going to be an option. Most of the entities are tagged with multiple terms.

Dream scenario:

Have a widget that renders the right HTML depending on the amount of data and attaches the right libraries.

For example (boundaries to be defined in config):
10 or less options and without tagging: output select, no select2
200 or less options and without tagging: output select, use select 2
200 or less options and with tagging: output text, use select 2
201 or more options and without tagging: output empty select, use select 2 + ajax
201 or more options and with tagging: output input, use select 2 + ajax

Really nice to have: Add support for hierarchical vocabularies as well, so site user can select parent term as well and they are rendered as nested.

amateescu’s picture

Whoa, hold on there.. isn't #72 clear enough in this regard? :)

#73 is wrong, there's no change needed on the PHP side (at least for the element declaration), we just need to convert the text input into a select before Select2 is initialized on that element.

attiks’s picture

#80 I'm probably missing something, but what is the policy for non js browsers, 'cos if we output a select for free tagging it will not work without javascript. Unless we are converting the input to a select using javascript?

amateescu’s picture

Unless we are converting the input to a select using javascript?

Bingo! :) Just as @nod_ said in #69 when the discussion about the new version of Select2 started.

attiks’s picture

Issue summary: View changes
attiks’s picture

#82 I've updated the IS, but by reading the comments the API change is no longer needed?

aspilicious’s picture

I'm a JS noob, so I can't say anything useful, but I think when it's done we need to manual test this with 1000+ tags to see if it has any effect. Just to be sure. I'm always ready for doing that when needed.

It will gain me lots of credits with the UX designers at work ;)

quicksketch’s picture

Sorry, yeah I kicked off the discussion in the wrong direction there. We can convert the textfield to a select *with JS*, then run Select2 on the new select list field we just created. However, that means we're going to have to adopt a lot of custom code to deal with converting a textfield to a select list. You'd need to account for single/multiple values, parsing the input field, converting it to a select list with the entered options selected. Then run Select2 on the resulting new select field and load the results via AJAX like we had been doing before. Before the values are submitted to the server, you have to convert these values *back* into a input so it would all come in as a single value in POST. A select list will send multiple values as an array.

Rather than attempt to revert the select back to input, we'd probably find it easier to maintain the original input on the page, and update it as the select list is updated.

So in summary, to use Select2:

- PHP outputs a textfield onto the page.
- Hide the original textfield and create a select list "copy" of the field with JS
- Apply Select2 to the select list, load results via AJAX
- On value change, update the original textfield.
- On POST, the server gets the value from the original field. The select element we could leave with no name attribute, so it would be nothing but a client-side widget for manipulating the hidden field.

So basically we'd re-implement the functionality that was removed from Select2 to support hidden fields.

I don't know... it's possible but doesn't seem right.

Wim Leers’s picture

#76/#77: did you look at how https://select2.github.io/examples.html#data-ajax (that specific linked example) works? It works with an empty <select>, for which <option>s are generated by Select2.

#86: that sounds very doable? But I agree that it's very unfortunate that the input[type=text]-based autocomplete use case is no longer directly supported by Select2. I really wonder why the author did that? After all, what Select2 presents UI-wise resembles a input[type=text] much more cosely than a <select>, so even in that regards it's a puzzling change. The removal of a input[type=hidden] dependency makes sense to me, the removal of input[type=text] not so much.
Does anybody of us know the Select2 author? Or has any of us followed its development closely? If so, then perhaps we can start a conversation with the author? One of us should reach out to the author IMO; Drupal 8 would be one of the most prominent users of Select2, I imagine, so perhaps he'd be willing to add this back for us. Or perhaps he'll manage to convince us of his reasoning :)

nod_’s picture

Reason was code simplification. it's easier to deal with options elements than splitting a string, also the return is cleaner for the backend, getting an array of split values is better than a string of values to split. It's in the github queue somewhere.

Not sure how messy it'd be to add back input support, but I guess we should reach out in any case.

kevin-brown’s picture

I'm the maintainer of Select2, and I'm interested in working together to fix the current lack-of-text-input issue.

I removed support for hidden inputs (<input type="hidden">) because there was no non-js fallback. Non-js users would be presented with absolutely nothing, and most likely any validation would be failing (pretty silently) because of that. All in all, it wouldn't be a great user experience, and it was something I wanted to avoid. Now, I didn't realize that people were using a text input as the fallback until about a week ago, and because of that much of the code is expecting a <select>, which is great because we don't have to special case that much.

The problem with the old implementation largely revolved around initSelection, a badly named function that handled the job of converting the value attribute to a set of data objects. I'm interested in working together to figure out what would need to be done to have Select2 function as an autocomplete for Drupal, but my knowledge of how the Drupal internals work is very limited.

We are tracking this issue at https://github.com/select2/select2/issues/3022 as well.

Wim Leers’s picture

That's awesome news! Thank you!

Basically, all there is to know is this:

  1. Drupal has supported "free tagging" (also known as folksonomies) for … 10 years or so. You can type any tag you want, and type a comma to indicate a next one.
  2. To help users find/select existing tags, there is an autocomplete, which takes the space-trimmed string after the last comma — if any — and asks the server for autocomplete matches. (It's never been quite as awesome as Select 2 though :)) i.e. foo, bar, baz -> "baz" is being autocompleted.
  3. To type tags containing commas, we wrap them in double quotes. i.e. Some Person, "Leers, Wim", Another Person has 3 tags: "Some Person", "Leers, Wim" and "Another Person".
    (This behavior would probably need to be implemented on the Drupal side, which is exactly what @amateescu did in #66, until @nod_ remarked in #69 that Select2 version 4 was about to be released, and this issue kind of got stuck on what to do now that Select2 no longer natively supports input[type=text]. In other words: you probably wouldn't even have to care, as long as we can still make it work just like we did for Select2 version 3.)
  4. Most importantly to you: what is described above, including the examples, are exactly what is sent to the server (commas, quotes, spaces and all). Basically, our UI has always been input[type=text] with some UI additions for autocompletion that helped the user get data in there in input[type=]text] faster and more easily — hence degrading "gracefully" to a very unhelpful, autocompleteless, mindblowingly simple UI: the plain input[type=text].
nod_’s picture

Thanks for the offer kevin-brown. Hopefully we can work this out :)

Bojhan’s picture

Issue tags: -Needs usability review
Dom.’s picture

Also maintainer of Search Autocomplete interested in helping if needed : #2442699: UX improvment on autocompletion

Dom.’s picture

njbarrett queued 66: 2346973-66.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 66: 2346973-66.patch, failed testing.

njbarrett’s picture

Now there's a release candidate for Select2 4.0, do you think now is a good time to create a new patch for this issue?

Wim Leers’s picture

Indeed, more than a month ago, the solution on the Select2 side was merged: https://github.com/select2/select2/issues/3022#event-243644862, https://github.com/select2/select2/pull/3051.

quicksketch’s picture

Component: base system » javascript

Select2 4.0.0 was released about 2 week ago. Looks like this issue back on. ;)

joelpittet’s picture

Issue tags: +frontend

Tagging frontend for sprint.

mgifford’s picture

Should we bump this to 8.1?

tkoleary’s picture

@mgifford

Given other priorities, perhaps. Although given the fact that it is unquestionably an a11y improvement, maybe not.

mgifford’s picture

@tkoleary I don't see the accessibility improvement. At least not when looking at the examples here:
https://select2.github.io/examples.html

It is a simple tool, but there are a lot of basic problems listed here:
http://wave.webaim.org/report#/https://select2.github.io/examples.html

I don't know how many are just part of the example code though.

I haven't had time to really look at it though. I do know that jQuery UI's autocomplete has had quite a lot of accessibility testing.

Can you point me to a comparison of the two for accessibility? Or even the documentation on the a11y work that's gone into Select2?

tkoleary’s picture

Last info I looked at was this issue https://github.com/select2/select2/issues/2499 that both you and I commented on which is now closed fixed. Since that time new a11y issues have been opened in 4.0, but (based on my own unscientific testing) 2499 puts Select2 well ahead of jquery autocomplete.

Here are the open a11y issues in select2 4.0

https://github.com/select2/select2/pull/2875 this one was opened after 2499 and was merged in on 12/09/2014
https://github.com/select2/select2/issues/3238 closed fixed
https://github.com/select2/select2/issues/3144 this one is still open as an enhancement but no longer marked a bug

I could not find other issues. We have an individual working with us here in Boston who may be able to test 4.0.

mgifford’s picture

I definitely think there has been progress with Select2 on accessibility, but I haven't had time to test it and it isn't clear to me that others have either. One of the last comments in #2499 is "Unfortunately I have no idea how to thoroughly test it as I only have limited knowledge of how Orca works, but perhaps someone else can help with testing."

That doesn't give me a lot of confidence.

I don't know how testing has been done or by whom. Select2 seems to have quite a few powerful options. I don't know if any of those have been tested.

There's some good addition of ARIA, but I still don't see how it's significantly better than jQuery UI for accessibility.

tkoleary’s picture

Some initial testing by Tyler Littlefield here in OCTO shows that in fact there is still a good bit of work to do. I plan on creating some new issues in the Select 2 queue on github.

mgifford’s picture

The WP folks did a nice review of Select2 because they were considering it for WP Core - https://make.wordpress.org/accessibility/2015/09/07/accessibility-userte...

It would be great if we could work with them a bit more on addressing these issues.

subhojit777’s picture

Issue tags: +Needs reroll
mgifford’s picture

Gaelan’s picture

Assigned: Unassigned » Gaelan

Rerolling.

catch’s picture

Version: 8.0.x-dev » 8.1.x-dev

subhojit777 queued 66: 2346973-66.patch for re-testing.

Wim Leers’s picture

Apparently there's a competitor to select2 that pays homage to select2, but tries to be better/simpler: https://github.com/arendjr/selectivity

mstrelan’s picture

Selectize.js also claims to be have a few advantages to Chosen, Select2 and Tags Input. and http://selectize.github.io/selectize.js/ and could be worth considering.

tkoleary’s picture

@wim leers

Apparently there's a competitor to select2 that pays homage to select2, but tries to be better/simpler: https://github.com/arendjr/selectivity

It does look simpler. Also bad on A11y but Select2 has not made much progress either, same for selectize. Just tested all three with screen reader.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vprocessor’s picture

Status: Needs work » Needs review
FileSize
397.23 KB

attempt to reroll

Status: Needs review » Needs work

The last submitted patch, 117: 2346973-117.patch, failed testing.

tkoleary’s picture

@vprocessor

Looks awesome! Despite failing tests it seems to work fine when I spin it up on simplytest.me.

One thing I noticed, the descriptive text would need to change (or just go away) in several places eg.

Enter a comma-separated list. For example: Amsterdam, Mexico City, "Cleveland, Ohio"

But that's a good problem to have.

joginderpc’s picture

Status: Needs work » Needs review
FileSize
20.91 KB

Updated all files with newer version of D8. Let's see if test passes.

Status: Needs review » Needs work

The last submitted patch, 120: jQuery_autocomplete_ui_replace-2346973-120.patch, failed testing.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Manuel Garcia’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
20.91 KB

Rerolled, was just a simple conflict on core/misc/autocomplete.js

Status: Needs review » Needs work

The last submitted patch, 123: replace_jquery_ui-2346973-123.patch, failed testing.

Bojhan’s picture

Assigned: Gaelan » Unassigned
phenaproxima’s picture

Status: Needs work » Needs review
FileSize
610.51 KB

It looks like the re-roll was botched at some point, and a missing file (or several!) was causing the test failures. Here's a new re-roll against 8.3.x, using Select2 4.0.3.

I apologize for the colossal patch size; the overwhelming majority of it is the Select2 library.

EDIT: Now that core has functional JavaScript testing, it seems like we might want a functional test of this widget against, say, a taxonomy term reference field. Do folks agree?

Status: Needs review » Needs work

The last submitted patch, 126: 2346973-126.patch, failed testing.

amateescu’s picture

Note that #2788209: Entity reference field "Autocomplete matching: Starts with" option does not work added a (small) javascript test for the autocomplete widget, so we could expand it here if needed.

But IIRC, this issue was blocked on the fact that Select2 is not as accessible as we need for core, see comments from #103 to #107.

phenaproxima’s picture

Looks like the WordPress people were interested in perhaps devoting some brainpower to fixing these issues; I can't tell if anything came of that, but maybe we could do the same? I really like this library and would quite like to see it in core.

tkoleary’s picture

+++ b/core/assets/vendor/select2/css/select2.css
@@ -0,0 +1,484 @@
+    .select2-container .select2-selection--single .select2-selection__rendered {

Guessing this was copied from select 2 css and altered and that's where the indented rules come from. We should follow drupal CSS coding style here with no indents.

At first glance I thought it was Sass. :)

droplet’s picture

All good work here.

I think we need some final calls:
A1. [Frontend] Final analysis of the Performance. Select2 isn't a small kid thought.

If we can't pass A1. It's time focus on contributed and pick another one instead of dead loop :)

A2. [Accessibility] Final analysis of select2 itself (without Drupal)

A3. Basic usage. Testing in cross browsers (Checking the supports table in Select2 is not enough. In Drupal, we have very diff requirements.)

B. [JavaScript] Possible way to improve the Accessibility problem in Select2 Upstream & Drupal ourselves.

With my last patch to Select2 upstream ( https://www.drupal.org/node/2346973#comment-9255223 ), I think there's limitation to patch everything in Select2 upstream. Select2 also has itself design principal.

chr.fritsch’s picture

Status: Needs work » Needs review
FileSize
610.46 KB
1.76 KB

I could resolve some dependency issues. Looks like there is no Select2 object in version 4.

Status: Needs review » Needs work

The last submitted patch, 132: replace_jquery_ui-2346973-132.patch, failed testing.

Rajab Natshah’s picture

+1 This will be very very nice if we do have it in Drupal core and out of the box.

Bojhan’s picture

Assigned: Unassigned » nod_

I think this needs escalation to product, with a clear answer on 1.

Assigning to nod_ to provide some guidance.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pdenooijer’s picture

I am looking forward to start using this feature, is there any update on the status of this issue?

Manuel Garcia’s picture

Issue tags: +Needs reroll

Most conflicts are easy enough to fix, however core/misc/autocomplete.js has been changed by #2823589: Improve IME handling on Autocomplete so I'm stepping away from this reroll in fear of messing things up :)

droplet’s picture

jonathanshaw’s picture

I suspect a lot of conflicts are not showing up because the patch hasn't been updated to allow for the fact that a lot of Entity Reference code has moved out of that module.

More generally:
Everyone wants this. But it's not showing any signs of going anywhere.
There's 4 tough hurdles to climb:

  1. Get Select2 working as a Drupal element and entity reference widget
  2. Get it meeting Drupal accessibility etc. standards
  3. Switch it in place of jquery autocomplete in the default entity reference widgets
  4. Deal with the consequences of adopting it in Drupal's admin UIs

What chance of us achieving all this in one 15k-lines patch in 8.x?
How about we split this into 3 steps:

  1. Get select2 working in contrib, getting it feature-complete as an optional element and widget
  2. Move it into core as an experimental module, working on accessibility etc.
  3. Create an issue to deprecate the current jquery autocomplete entity reference widgets in favour of the select 2 ones
  4. Create an issue to enable it globally in the admin UI replacing jquery autocomplete and deal with whatever unforeseen consequences that has
geek-merlin’s picture

#140:
> How about we split this into 3 steps: ... (4 steps)

YES sounds very reasonable.

pk188’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
470.35 KB

Re rolled. Not find all the changes. Not able to form interdiff.

Status: Needs review » Needs work

The last submitted patch, 142: replace_jquery_ui-2346973-142.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jfs.csantos’s picture

I've just come across this while looking for a D8 version of the Select2 module.
I'm working on and already created a basic version of the module which creates a Select2 widget and a FAPI element ( which is what I needed initially.)

Anyone else working on this? Can we combine efforts and get at least a dev release ready asap?

jonathanshaw’s picture

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mgifford’s picture

Has anyone checked out selectwoo?
https://github.com/woocommerce/selectwoo

There's also someone from waggl.com willing to fund some accessibility work on select2:
https://github.com/select2/select2/issues/3744#issuecomment-314813909

droplet’s picture

@mgifford,

Good news! that is a @automattic supported project. and other supports from waggl.com

@drewB I'd do it with PRs if I thought they would get merged in, but I doubt they will.

I have same concern as @claudiulodro in #131. I believe we need a smiliar fork or custom extension as woocommerce/selectwoo in druapl also.

1. and recently, when I worked on a custom project, I found the responsive doesn't work very well in select2 in many cases. e.g. rendered as a close Modal markup, Tabs. When it's shown, `width` didn't set correctly. ( https://github.com/select2/select2/issues/3278 )

2. down arrow on focus doesn't work. ( https://github.com/select2/select2/issues/4514 )

mgifford’s picture

Thanks @droplet I do hope we can get this addressed in the 8.x cycle. Seems like there are a lot of folks who want a solution but there hasn't been someone yet to organize it. Maybe folks will rally behind selectwoo.

Thanks for posting those other accessibility bugs in select2.

droplet’s picture

jonathanshaw’s picture

jfc.csantos seems to have created https://github.com/Bynder/d8-select2

jfs.csantos’s picture

Hi all!

I asked to contribute my version to the official select2 project but the maintainer didn't wan't to do it, so I'll just go ahead and create this one...it's holding my company back on releasing a few necessary features.

As soon as we can get my changes to the select2 project I'm more than happy to remove this one.

Cheers

droplet’s picture

Assigned: nod_ » Unassigned

@jfs.csantos,

AFAIK, after some point of 2016 Mid ~ 2017, you able to create "Yet another Select 2" in d.org freely.

With current movement, I think it's a bit hard to get Select2 into CORE.

Anybody’s picture

@jfs.csantos (https://github.com/Bynder/d8-select2) & @webflo (https://github.com/ueberbit/drupal-select2)

I think it would make a lot of sense to release one of your module on drupal.org as project to
- make it easier to find it
- provide it via drupal.org composer
- combine into one project and use benefits from both, because drupal-select2 supports views filters for example while d8-select2 supports remote data?

The best would be to release it as D8 version of one of these projects:
https://www.drupal.org/project/select2
or
https://www.drupal.org/project/select2widget
or
http://hemantnegi.github.io/jquery.sumoselect/sumoselect_demo.html
or
https://www.drupal.org/project/selectize
instead of creating a further one??

At the end a Drupal core integration and replacement of the current solution would be perfect, but I think that will take some time...

jfs.csantos’s picture

Hi there @Anybody! Thanks for the input, but I already tried to move in that direction...asked the maintainer of Select2 to upload an initial version of the D8 module, he said he didn't want to because in would be "releasing an official version in a few months".

Also considered releasing the module in Packagist or in drupal.org as a new project, but in the end they were temporary and not very good solutions.

So, in the end, because of my company's need for this to be released, we ended up just adding it as a submodule of the Bynder module. When/if we can actually get some cooperation from the Select2 project maintainer I will gladly contribute with this code.

If you guys still find the module useful, I can still put it up on Packagist.

Cheers

geek-merlin’s picture

@all: This info and discussion belongs here: #2695535: [select2] Select 2

This is also the community place to discuss and decide the release policy.

Anybody’s picture

Related issues: +#2695535: [select2] Select 2
nithinkolekar’s picture

FileSize
67.86 KB

OffTopic: following this issue and got alert for new comment at dashboard as "1 new" but how come #154 changed it's comment time? Its not a big issue but would get messy afterwards.

attaching screenshot for ref..
comment-time

alphawebgroup’s picture

@Anybody
I'm really sorry... but I've just checked SumoSelect on github - https://github.com/HemantNegi/jquery.sumoselect
it contains pretty strange code inside (bad maintainability by my opinion), not sure if it will be acceptable by community
please check - https://github.com/HemantNegi/jquery.sumoselect/blob/master/jquery.sumos...

alphawebgroup’s picture

Anybody’s picture

Thank you @alphawebgroup https://github.com/Mobius1/Selectr should also be considered. I also just had a look at sumoselect and share your oppinon. Did you have a a look at Selectrs code already?

The problem we see with Selectr is that it changes its height (1 line becomes multiline if many items are selected). This man be a problem for views filter layouts or on mobile devices and other cases. jquery.sumoselect offers the possibility to use "x selected".

See my quote here: https://www.drupal.org/project/contrib_tracker/issues/2695535#comment-12...

Perhaps https://github.com/Mobius1/Selectr (discussion for responsive / touch UI: https://github.com/Mobius1/Selectr/issues/14) might be a better alternative for Drupal (Core) but it also doesn't behave well in responsiveness. The box simply grows line by line... best would be a selective combination from Select2 / selectr and jquery_ui_multiselect_widget by usecase... Chosen is even older...

I created a feature request in Selectr for that but I don't think that will happen: https://github.com/Mobius1/Selectr/issues/56

thomas.frobieter’s picture

The problem we see with Selectr is that it changes its height (1 line becomes multiline if many items are selected). This man be a problem for views filter layouts or on mobile devices and other cases. jquery.sumoselect offers the possibility to use "x selected".

I agree. This will make consistant (inline-)form styling nearly impossible. Those "Pill Style"-selects are just usefull for simple vertical forms.

matsbla’s picture

I needed this so contributed the module here if anyone else need it for D8: Select2 Boxes.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Pancho’s picture

Version: 8.6.x-dev » 9.x-dev

If there’s still no viable, actively maintained jQuery widget, it seems we should really team up with WordPress and other consumers to maintain our own fork either of Select2/SelectWoo or another alternative.

I might be wrong, but I guess it’s not going to be more workload than putting more and more efforts into our own, outdated and limited autocomplete widget, especially taking into account all the effort site builders put into introducing their own custom implementations.

Either way it doesn’t seem realistic this would ever be implemented into Core within the D8 life cycle. May I push it to D9, while different routes are weighed in contrib? I’d love to see a major improvement, but fail to see it materializing... :/

jonathanshaw’s picture

Version: 9.x-dev » 8.6.x-dev

I think this could easily be made available in core in D8, even if the default implementation didn't change.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jonathanshaw’s picture

Status: Needs work » Closed (outdated)

In #140 I proposed a 4 stage plan:

  1. Get select2 working in contrib, getting it feature-complete as an optional element and widget
  2. Move it into core as an experimental module, working on accessibility etc.
  3. Create an issue to deprecate the current jquery autocomplete entity reference widgets in favour of the select 2 ones
  4. Create an issue to enable it globally in the admin UI replacing jquery autocomplete and deal with whatever unforeseen consequences that has

Now point 1 has been done, thanks to @chr.fritsch.

Therefore I've opened #2987622: Move Select2 to core as an experimental module in the ideas queue. I'm also suggesting we close this issue despite the heroic work here, because it's no longer Drupal practice to make large changes in core using single monolithic issues. If this going to happen, I imagine it will likely be via the experimental modules route.

andypost’s picture

Status: Closed (outdated) » Needs work

This is not outdated, there are patches & valuable discussions.
I see no reason in experimental module while contrib has only first release & that is just a frontend library

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anybody’s picture

Title: Replace jQuery UI autocomplete with Select2 » Replace jQuery UI autocomplete with better multiselect library
Anybody’s picture

Anybody’s picture

Choices.js is a new candidate which is now used by Webform: https://www.drupal.org/node/3046239

As the other libraries didn't match the requirements yet, this could be interesting.

thomas.frobieter’s picture

The problem we see with Selectr is that it changes its height (1 line becomes multiline if many items are selected). This man be a problem for views filter layouts or on mobile devices and other cases. jquery.sumoselect offers the possibility to use "x selected".

I agree. This will make consistant (inline-)form styling nearly impossible. Those "Pill Style"-selects are just usefull for simple vertical forms.

The markup of choices.js is pretty good, should be easy to alter the style for horizontal forms by removing the pill style and do something like:

.choices__list--multiple{
white-space:nowrap;
overflow:hidden;
text-overflow: ellipse;
}

Maybe the author of Choices.js is willing to add this as a clean option.

So +1

lauriii’s picture

Based on some quick research, this library seems like a pretty accessible option: https://github.com/alphagov/accessible-autocomplete. It's a React library, but we could use it as a comparison.

Anybody’s picture

Issue summary: View changes
Anybody’s picture

Issue summary: View changes
Anybody’s picture

Issue summary: View changes
Anybody’s picture

Issue summary: View changes

Thank you @lauriii for pointing out this very important reference. I've updated the issue summary to list some of the acceptance criteria and the mentioned libraries to evaluate. I'm unsure if we should remove the initial text from the issue summary, which only concerned select2 as option, but isn't really a good choice in several points. Or should we close this as duplicate and create a cleaned up issue based on this discussion?

bnjmnm’s picture

I went ahead and prototyped how this might work with choicesjs to see what kind of unexpected surprises might show up.

The biggest of the surprises is that the best way to implement asynchronous autocomplete is to use choicesjs's 'search' event, and that event is only triggered on select elements. To get a feel for choicesjs, I added JS that converts all of the autocomplete <input> elements to <select>. This got things far enough along to make it possible to evaluate the use of choicesjs on entity reference fields. However, since the form element is different, it's not currently possible to save values (or populate existing ones).

I think this can be worked around if choices still seems like the best solution, whether they be in Drupal or the js library. This patch at makes it possible to evaluate how it may work in Drupal, which can help us gather evidence to determine if it's worth the implementation hurdles.

bnjmnm’s picture

Two patches here, the first is an improvement to the choicesjs prototype from #181, the assets are now added as part of drupal.autocomplete instead of jquery.ui.autocomplete.

The other patch is a prototype of using the Accessible Autocomplete library. This probably isn't a good candidate, unfortunately. Among other things, it does not support multiple values, and it only works with string arrays (no ability to have discrete values and labels).

I think the prototype is still very useful to have as reference when evaluating other libraries for accessibility support. There's also a good writeup on some of the research and testing that went into developing the library, which can help inform the evaluation process for this issue.

bnjmnm’s picture

I had a look at Selectr, wondering if the concerns in #161 were surmountable. I didn't get too far in the evaluation after discovering that (similar to choices in #181), it requires a select element, and would not be able to work on existing autocomplete <input> elements.

If its decided that changing the form elements is an acceptable refactoring, it may still be worth looking into Selectr and submitting a PR for the concerns in #161

bnjmnm’s picture

Issue summary: View changes

Currently working on a prototype for a custom lib based on React Select. Based on preliminary testing done with @lauriii, React Select does not have any of the major accessibility/functionality limitations we've run into with other libraries. So far, any issues we've run into are ones that can be addressed via implementation and not a limitation of the library itself.

Wim Leers’s picture

#171: nice, your comment is exactly 1 year and 1 day since the last one 😆

Based on the prototyping work done by @bnjmnm this seems to be the current state:

Library Evaluation
Choices Still in the running, see #181 + #182
Accessible Autocomplete ❌ does not support multiple values, see #182
Selectr ❌requires <select>, see #183
React Select Still in the running, see #184

@bnjmnm I think it'd be handy if you expand this initial table (I can give you the source HTML so you don't need to recreate it) and add it to the issue summary, that would make it very clear why which JS libraries are eliminated or still being considered.


My gut reaction here is that I am surprised we're not continuing to look at Select2 first, because as this issue's older comments show, we have successfully worked with the author of that library (a long time ago!) to get accessibility improvements committed. Accessibility is notoriously hard to achieve for user experiences like this, and having years of testing and feedback is a huge advantage.

Select2 still seems to be actively maintained: the last commit 11 hours ago, and it happens to be an accessibility improvement: https://github.com/select2/select2/commit/e5131d0cc8dffd98ba36a68f3d027b...! Look at the complexity of that commit message! 🤯

React-select had its last commit >1.5 month ago and it was just updating a dependency: https://github.com/JedWatson/react-select/commit/c22a4b20aef2161ebaa3a03....
https://github.com/JedWatson/react-select has 1160 open issues and 1250 closed ones. https://github.com/select2/select2 has 40 open issues and 4230 closed ones. Notably, https://github.com/JedWatson/react-select/issues/1084 has been open for over three years. https://github.com/JedWatson/react-select/issues/3353 means not even the label for the form input is being read by screen readers.

That's a lot of signals indicating that Select2 is more mature, which is important for an accessibility-critical UI component.

bnjmnm’s picture

@WimLeers very good point about Select2 and that's definitely next on the list. The thought was to start with standalone libraries, or at the very least see what can be done without jQuery. Full (not at all surprising) disclosure: react-select definitely does not achieve the "standalone" part of that approach at all, and has the hearty node_modules directly to prove it 🙂

Also worth noting: One of the steps required to get the react-select prototype working made it apparent that Choices and Selectr may still be viable options even though they require a <select> element - the library doesn't have to directly manipulate the entity reference text input - the input can be made hidden and updated via the library-provided select input (similar to how Media Library keeps track of selections)

chr.fritsch’s picture

For select2 we have a stable D8 module in contrib. See https://drupal.org/project/select2. Currently, around 2000 sites are using it.

There were also some discussions around this in #2987622: Move Select2 to core as an experimental module

bnjmnm’s picture

Here are patches for three prototypes

  • Select2
  • Choices (there was a very simple way to get around the <select> only limitation, the same approach was used for Select2) (also want to point out the lib isn't minified in this prototype)
  • React-select (working with the prototype has made me less enthusiastic about this one)(also want to point out the lib IS
  • minified and it's still pretty huge.

Will follow up with another comment with some of my findings for each one, but as that may not happen immediately I wanted to make the prototype patches available to others so they can evaluate.

In each case, i just worked with taxonomy fields in the Article content type, so that's going to be the best place to evaluate these patches.

bnjmnm’s picture

Findings for Choices JS

(some of the evaluation criteria is not included/complete as the review stopped after identifying numerous difficult-to-address accessibility problems - this can always be revisited if our other options have a similar extent of accessibility issues)

Accessibility
  • No focus ring for items in multiselect
  • Multiselect item focus change is only indicated by color change of the tiny “x” svg for removing an item. Default state is a hard coded #FFF. During focus/hover the color doesn’t actually change - the svg changes from opacity:1 to opacity: .75. This means that it fails standards due to color being the only means of distinguishing, and the difference has insufficient contrast. (and would require creating custom SVGs to override)
  • Multiselect label/text contrast is only 2.29 (this could be addressed fairly easily with CSS, but strongly suggests that accessibility hasn’t been considered much)
  • On single select, default focus style is overridden, and only distinguishable by color. The color change is from #DDD to #B7B7B7 offering a low contrast ratio of 1.47:1
  • The actual interactive elements in multiselect can’t receive focus as they have a tabindex of -1. Instead, their containers are assigned a tabindex, and when focused receive an .is-focused class that styles the interactive element inside.
  • Labels are not associated with their inputs - the choice online demo relies on placeholder text to identify the field to screenreaders.
  • Its also not immediately clear how to associate the form element with a label via custom JS. I did some trial and error changing the “for” attribute of the existing label to reference the ID of elements generated by choicesjs, both with the select element and the additional input element it generates but screenreaders would not acknowledge either. There are still other things to try but it certainly does not work out of the box.
  • Using keyboard only: If a user begins a search and arrows down to any option other than the first (for the sake of example lets say third), then changes their mind and searches for something different, focus continues to be on the third result even though a different search was conducted.
AJAX support Works well, but only on<select> elements, does not work on text inputs (which means we can't work directly with the inputs provided by the Form API.)
Filter search There are easily implemented events/callbacks for this
Single / multi select Both
Dependencies No jQuery dependency but not 100% standalone: uses
Classnames, deepmerge, fuse.js, redux
Other
  • AJAX does not work on text inputs, only <select> elements. The prototype demonstrates that things can be made to work by hiding the text input and syncing it with the values of the <select>. One known issue with this is mentioned below, but there may be other unexpected problems too. Something important to note: this is one of the few libraries that can function at all with text inputs most features work fine with text inputs, it's just updating options via AJAX that doesn't. If it turns out that working on text inputs is critical, this library may require the least amount of customization in order to do that.
  • A concern mentioned about selectr in #161 is also present here - if a certain number of options are added it becomes multiline which per that comment “may be a problem for views filter layouts or on mobile devices and other cases”. While it’s possible to set this to white-space:none and allow horizontal scrolling, I was not able to find a way to horizontally scroll within the element using keyboard navigation. This would not be an issue if it were possible to use <input> elements
  • Current prototype does not support terms that include commas (this is fairly easy to address however).
  • Base.css breaks several core styles, but it is not clear if this stylesheet is necessary (yet to find evidence that it is). The second css file - choices.css seems to do everything needed to use it in Drupal.

Will also add these findings to the issue summary after allowing a bit of time for feedback/corrections.

catch’s picture

I think we should at least consider switching to a select element if that improves everything else. At the very worst this could be added as new elements/widgets deprecating the current one but even that might not be necessary depending on how we do it. i.e. if our options include both updating our existing widget and a complete visual update we should look at both. We might decide it's not desirable in the end, but doesn't seem worth ruling out up front. The big thing though is retaining AJAX autocomplete for scalability.

Wim Leers’s picture

#188: exciting to have 3 prototypes!

#189: Wow, love the deep analysis! Clearly you have a lot of accessibility knowledge 🤩👏 It sounds like some of those would be pretty easy to fix upstream, but others seem to perhaps be deeply embedded in the architecture.

Looking forward to an analysis similar to that of Choices in #189, but then for Select2.

#190: I was gonna say "but wouldn't that be too disruptive?" — then I realized that it's not #type => textfield with #autocomplete_route_name => …, but we're talking about #type => entity_autocomplete. So it seems we're fine there. Except … aren't we trying to remove the jQuery UI autocomplete altogether, which would require this to work for both cases?

aspilicious’s picture

"The big thing though is retaining AJAX autocomplete for scalability."
This is very important for a lot of projects.
I know that select2 implementations of a normal select can go wrong with +1000 elements.

bnjmnm’s picture

Findings for Select2/SelectWoo

Selectwoo describes itself as "a fork of select2 with improved accessibility", which was started when Select2 didn't have much activity on github. Select2 activity has since resumed, so any accessibility issues I identified on one I tried with the other. Assume the problems happen on both unless stated otherwise.

Similar to the ChoicesJS review, theres probably more to learn but I stopped after once the accessibility problem list had several potential dealbreakers. Note that the maintainers of Select2 seem quite open to addressing accessibility issues so it shouldn't be ruled out based on these findings alone several accessibility issues have been addressed within the past few weeks and several more are in progress.

Maturity Select2 has been around a long time. They've explicitly stated a commitment to making it more accessible, and the recent commits/issues/PRs reflect that. Overall there is a nice amount of recent activity from very capable contributors. The activity on their Github suggests that were we to report the accessibility issues discovered here, they may get addressed (particularly if we assist)
Accessibility
  • It's not possible to access individual items in a multiselect via keyboard navigation - they are not focusable. One of the biggest problem this presents is it's not possible to remove an item in the middle of a multiselect without a mouse. This was noticed very recently in an unrelated issue by a contributor that has exhibited some very strong accessibility skills, so a fix may be on the way.
  • This one I'm not sure is a problem - but its different. With jQuery autocomplete, the contents of a multiselect are automatically read by screenreaders when the input is focused. With Select2, when the input is focused the user is informed they are on a list - additional list-specific navigation is required to get the contents of the list.
  • (NOT AN ISSUE IN SELECTWOO) - When a screenreader reads multiselect selections, the remove button for each element is identified by the screenreader as "X", and it is interpreted as text, not an interactable element.
  • (ONLY AN ISSUE IN SELECTWOO) - When a screenreader reads multiselect selections, there are two instances of each item - the first states the item value, the second states the value and its position within the group of items.
  • When screenreaders read a populated single-select element, it says the value of the input twice.
  • When autocomplete provides suggestions, the screenreader will announce the number of suggestions, which can be navigated with arrow keys. However, when arrows are used to highlight a suggestion, the screenreader does nothing. Contrast this with Accessible Autocomplete which announces each suggestion as it is highlighted.
  • There is a known bug with labelling Multiselect inputs - screenreaders will refer to it as "blank". This was reported recently, and the discussion in this issue is promising both in its pace and quality of comments. That said, if they go with the approach for single-select inputs (which I mention in the next bullet), it still won't be ideal but may be possible to mitigate on the Drupal end.
  • For single select, they do make use of aria-labelledby, but the corresponding label element contains the default or current select value, not a label describing the field. I'm guessing this can be addressed with JS by adding an ID to the field label and changing the aria-labelledby value.
  • Clearing inputs can be done with a "clear all options" button (seen as an "X") at the far right of the input. This is an interactable element but cant be accessed via tab navigation.
    • To remove items from multiselect via keyboard, it can only be done by backspacing/delete-keying from the last selection and removing one at a time
    • To empty a single-select via keyboard the user must backspace/delete-key when the input is in focus, but unlike multiselect there is no cursor present to even indicate backspacing is an option. Once the item is removed via backspace, the autocomplete form appears, and needs to be closed with the escape key. TLDR emptying a single-select field via keyboard is very confusing.
  • The "X" button that removes an item from multiselect is #999999 on an #E4E4E4 providing a contrast of only 2.24:1, not passing any WCAG standards
  • Multiselect does not receive a focus ring as the input cant actually receive focus - so it instead passes focus styling via a class change. The only indication of focus is a change to the inputs border color (which fails WCAG 1.41 - color can't be the only means of conveying change)
  • There are other assorted known issues, which appear to be getting attention as of the past month.
  • The WordPress team conducted an accessibility audit in 2015. I'm not sure which of these findings have since been addressed in either Select2 or SelectWoo. This can be investigated further if the above findings don't take Select2/SelectWoo out of consideration.
AJAX support Easy to implement. However, comment #192 mentions "I know that select2 implementations of a normal select can go wrong with +1000 elements." - if Select2 is a contender it would be good to know more about that issue and if it applies to current versions.
Filter search There are easily implemented events/callbacks for this
Single / multi select Both
Dependencies jQuery, jquery-mousewheel
Other
  • Like ChoiceJS, AJAX does not work on text inputs, only <select> elements. The prototype demonstrates that things can be made to work by hiding the text input and syncing it with the values of the <select>. There are likely hidden downsides -- but the next point identifies one that was discovered
  • A concern mentioned about selectr in #161 and found with ChoicesJS is also present here - if a certain number of options are added it becomes multiline which per that comment “may be a problem for views filter layouts or on mobile devices and other cases”. While it’s possible to set this to white-space:none and allow horizontal scrolling, I was not able to find a way to horizontally scroll within the element using keyboard navigation. This would not be an issue if it were possible to use <input> elements

Will also add these findings to the issue summary after allowing a bit of time for feedback/corrections.

Attached patch is an updated prototype that works with items that have spaces and/or commas.

bnjmnm’s picture

Findings for Chosen

This one did not get the Drupal prototype treatment, based on reviewing the repo and online demos I feel pretty comfortable ruling this one out

Code Style src is in CoffeeScript
Maturity NPM reports 28,959 downloads this past week so it's clearly well-loved. Github activity is pretty scarce, however. There's a few recent minor commits after a year of no activity, and there are 209 open issues and 53 open pull requests - many with no responses/activity at all.
Accessibility
  • Did a grep for 'aria' and the only results were part of the word "Bulgaria"
  • Like select2, removing a multiselect option that is not the last in the list cannot be done without a mouse
  • Based on this demo page elements aren't focusable and can't be reached by keyboard navigation.
AJAX support Not really - any docs/examples I saw used jQueryUI autocomplete.
bnjmnm’s picture

Findings for Selectr

This one did not get a Drupal prototype treatment, I reviewed the repo and online demos. If it's still in the running after these initial findings we can dig further.

Code Style Doesn't make heavy use of comments, but is more readable (to me at least) than some of the other libs I've reviewed
Maturity Can't really tell (happy to get input). It's one of the newer libs out there, but has a good sized user base (~25k weekly downloads on NPM, which is high, but much lower than Select2's ~200k) There are things like this issue which is still tagged as open but has been fixed in a different issue (as seen in the comment), and I found some duplicate issues suggesting that grooming may be infrequent.
Accessibility
  • So far one of the better libraries for keyboard navigation, but not very good with screenreaders
  • Like many of the other libraries reviewed, the inputs will not associate with a label. Also like the other libraries, this is because the actual form input is hidden, and the interactable markup is divs and spans, not an input element that can align with a label's "for" attribute. It may be possible to get around this with aria-labelledby shenanigans, but there's no straightforward solution.
  • Select options are not read by screenreader, even when highlighted. The best I could get was when a select was open, ctrl-option-L would read the first option
  • In multiselect, screenreader does not read currently selected options when they are focused - instead it just says "Button".
  • A screenreader identifies these inputs as "textfield", there is no indication of it being an autocomplete field.
  • The only aria attributes in the source are aria-hidden and aria-expanded
  • Return key will not open selects - must be done with spacebar. This was reported early 2019 and another issue shortly thereafter. Looks like spacebar is less common but acceptable
  • Not immediately sure if this is actually a problem, but it deviates enough from the pattern found in other libs that it should be mentioned: In multiselect, the autoocomplete input is independent from the form input containing the selections. In all other libraries reviewed, the autocomplete query is entered in the same input the selections are in. In these other libraries, once a selection is made, the options close and focus goes to the input element. With Selectr, the options remain open even after an option is selected -- this provides the ability to add multiple options without having to initiate another search, but also means that the search options will be present for keyboard users until they hit escape.
AJAX support Was not clear from the doc, which shows the ability to load options from ajax on init but not clear if this can be used in an autocomplete scenario. There dont appear to be dedicated events that fire on input, but its possible a standard JS event would work. Can investigate further if accessibility or other issues are not deal breakers.
Dependencies None, real vanilla.
Other A concern initially mentioned in #161 a certain number of options are added it becomes multiline which per that comment “may be a problem for views filter layouts or on mobile devices and other cases”. This could be worked around if it worked with text inputs, but (like most of the libs reviewed) it only works with <select>
catch’s picture

#91

We are trying to remove it altogether, but we could for example do #type => select with #autocomplete_route_name and deprecate #type => textfield with #autocomplete_route_name (but have #type => entity_autocomplete just update to the new system). Maybe?

geek-merlin’s picture

Kudos for the thorough analysis!

Let me add another criterion that was relevant in some projects:
* Can choices optionally be ordered? (In field storage we have this, often we don't want it and are happy that the widget ignores it, but sometimes we do!)
* Can we optionally have duplicate choices? (Same as above, sometimes we do need it)

It would be gold standard if we can settle on a widget that has (or can be extended to have) both options.

Maybe my research on this helps. (For the there favored selectize also see @kevinquillen*s Selectize.js)

Wim Leers’s picture

  • @bnjmnm in #193 + #194 + #196: I am really impressed with your detailed analyses. Thank you so much! 🙏👏❤️

    What are the next steps here?

  • #196: I see. Maybe, yes. That sounds like we'd still cause BC breaks though. At least I think it's very likely that we have both #type => select and #type => textfield with autocompletion in contrib modules. A quick search already surfaces several: http://grep.xnddx.ru/search?text=%23autocomplete_route_name&filename=
  • #197: those are excellent additions.
bnjmnm’s picture

More!

Findings for Selectize

No prototype as I was able to gather enough information from online demos to provide an initial review. Something I'd like to highlight is that this is the first (multiselect-supporting) library I've tested that provides proper labeling for screenreaders . If we wind up preferring a different library that has this common input labelling problem, this library may help us identify the best way to fix it (unlike most of the libraries I've reviewed, the input is not hidden. It's placed inside the looks-like-an-input div that pretty much all these libraries use)

Code Style While it isn't as thoroughly commented as Drupal core (core lays em on thick), the comments that are there seemed to be placed well and it should be easy to follow for anyone with a modest understanding of jQuery plugins. The functions and variables are named well, and the overall structure makes it easier to understand than many jQuery plugins.
Maturity NPM reports 52,842 downloads this past week so it is one of the more widely used options. The Github activity may be concerning: very little has been done in over a year other than security or Github-compliance related updates. There are 551 open issues and 130 open pull requests. Some are over a year old and for bugs that should be addressed with more urgency (or conclusively ruled out as an issue unique to the reporter). While the validity of each PR/issue hasn't been investigated thoroughly, it doesn't look like the library is getting much attention, even to just clean up the backlog.
Accessibility
  • Pillbox background of #1B9DEC and text color of #FFFFFF provides an insufficient 2.96:1 contrast
  • Closed selects can't be opened with enter or space key, it won't open until search text is typed in. This goes beyond a navigation problem for instances where it's necessary for all options to be visible. A keyboard nav user will only be able to see options that match the autocomplete string.
  • A grep for "aria" in src returns zero results. This likely explains the screenreader issues that will be mentioned next. (and there are likely even more than what gets listed)
  • Screenreaders do not read currently-selected multiselect options as expected. If a populated field receives focus, the values should be read automatically. For multiselect, the only way to get these values read is: 1. focus the field, 2. move cursor moved to the beginning of the field using the left arrow 3. Instruct the screenreader to start reading (ctrl-option-A with voiceover). While it's technically possible to get these values, there's no indication to a screenreader user that these steps are necessary.
  • Screenreader does not announce the availability of autocomplete results/suggestions)
  • Screenreaders do not read suggestions as they are focused
  • Screenreaders only indicate that user is on a text field, nothing indicates that it will behave like a select or autocomplete.
AJAX support Did not build my own to validate, but based on the docs and online demos this works fine
Single/Multi select Both are supported
Other
  • It is possible to attach this functionality to text inputs, but the not-a-text-input concers as mentioned in #161 apply here as well generated markup displays the values in a div. There should be several ways to get around this issue, so I would not consider it a blocker for this or any of the other options.
  • Based on the feature list on the Github page, it looks like this (and available plugins for it) might have some nice functionality not available in many of the other candidates. We can look into this further if the accessibility issues don't take it out of the running.
bnjmnm’s picture

Findings for React-select

Demo
Prototype patch *(only tested with taxonomy autocomplete fields) *(terms with commas will not work properly, but that is easy to fix - this was just written before realizing that needed addressing )

Code Style It's completely written in React
Maturity NPM reports 1,212,971 downloads in the past week so it's among the more popular of the ones being reviewed (even after taking into account that CI and other processes for React Apps install dependencies constantly). It's not immediately clear to me if the library is being well taken care of or not, but I think it could be gauged by someone more experienced contributing to these types of projects. I noticed there are more issues and PRs than any of the libraries reviewed so far (100, 1,168 respectively), but many React libraries with million+ weekly downloads have similar numbers, and there's enough recent activity to indicate it isn't abandoned.
Accessibility
  • This has the same no-input-label problem faced by every library that isn't Selectize. As with the other libraries, this issue can probably be addressed with a little bit of extra JS. Addressing this with a React component will probably require significantly more lines of code than addressing this with something based on jQuery or vanilla (can't be sure until I try it, though).
  • GOOD: grep for 'aria' has the healthiest results of any library.
  • Good/BadThis easily has the best screenreader support of any of the libraries reviewed, but there are still issues. The type of issues are much more promising than other libraries. Issues with what the screenreader is saying are much better problems to have than the screenreader not speaking up at all
    • On multiselect with creatable enabled, the number of results reported by the screenreader is often incorrect. The incorrect number is usually the maximum number of results that can be displayed + 1 (the + 1 likely being the "create" option)
    • After entering text on multiselect with creatable enabled, voiceover will say "press down to open the menu", but it was already opened in response to the entered text.
  • To reproduce: Use keyboard navigation to focus a multiselect option (which means its remove button is focused). Start typing a word -- the input receives the text but does not receive focus - focus remains on the item's remove button.
  • Clearing all multiselect options can be done with a "clear all options" button (seen as an "X") at the far right of the input. This is an interactable element but cant be accessed via keyboard navigation.
  • Similar to the "clear all options" issue above, the disclosure arrow is an interactable element that can't be accessed via keyboard navigation
AJAX support Yes
Single/Multi select Both are supported
Other
  • Like every library reviewed so far, the concerns in #161 are present, as multiselect options are not displayed in a text input. This means that when selectons exceed the width of the field, there must be a line break or horizontal scrolling.
  • True to the name of the library, this is built in React. This introduces some unique concerns.
    • React and several other dependencies are bundled into the js file that would be included, which results in a minified file ~250k, much larger than our other options. (this is based on a prototype - it's possible that this can be made smaller)
    • Using react-select inside a non-React application requires creating a wrapper that acts as an intermediary between the standard JS and the React component. This wrapper is not particularly complex, but would likely be confusing without React experience.
    • React libraries tend to have more dependencies than jQuery/vanilla. There are 10 direct dependencies (3 are sublibraries of the same parent) that must be kept track of for security issues, over twice that of any other option we've reviewed.
bnjmnm’s picture

Findings for Sumoselect

Going to rule this one out without a full table as it can be done pretty quickly:

  • No activity in almost two years
  • No support for creating items
  • Screenreader use is very unclear - has many of the problems found in other screenreader-unfriendly options, plus announces the inputs as buttons.
  • No ajax autocomplete
bnjmnm’s picture

At this point, all the options listed in the issue summary have been evaluated. Accessibility looks to be a significant problem with each. The issues discovered came from just manual testing, so it's likely that more would be discovered as testing got more granular and rigorously checked against w3 specs.

These are some of the possible next steps that come to mind:

  • Find the library that has a good combination of surmountable issues and likelihood of having PRs merged. Create issues and provide patches.
  • Fork accessible-autocomplete and add support for multiple options similar to how it's done currently (comma/quotes). Note that this approach would satisfy autocomplete on text fields, but would not address making select inputs filterable. This would also provide no UX improvements for autocomplete entity reference fields - just accessibility ones.
  • Track down a really good library that was somehow overlooked in our list of candidates.

And there are likely other ways to approach this issue that I'm overlooking due to cognition-compromising effects of disappointing a11y testing.

webchick’s picture

AMAZING work! :O :O

I think the next logical step here might be to overhaul the issue summary with a clear summary of results, and then try and get a wider audience (JS, a11y folks) to look at our findings and provide feedback. (Happy to tweet something out.)

Wim Leers’s picture

#200: lol, >1 M downloads per week. It's painfully obvious that we're once again letting us be misled by something that is easily measured but the meaning of which is unclear. >1 M downloads/week does not mean >50 M sites/year are adopting this. It means people using that particular library tend to make many tiny commits that each trigger a test run that triggers a package download. Anyway … I digress.

#200:

  • Wow, best of all candidates so far, that's impressive!
  • 250K!!!! 🤯 That's about half the size of our minified CKEditor build, which offers orders of magnitude more complexity. I was hoping it would not be this bad, because it'd be great to have a first React-based component in core, especially if it was leading the pack like it sounds it is.

due to cognition-compromising effects of disappointing a11y testing.

😂😭

+1 to what @webchick recommended as next steps. I think that the two strongest contenders are react-select and select2. Is that correct?

bnjmnm’s picture

Re #204

#200: lol, >1 M downloads per week. It's painfully obvious that we're once again letting us be misled by something that is easily measured but the meaning of which is unclear. >1 M downloads/week does not mean >50 M sites/year are adopting this. It means people using that particular library tend to make many tiny commits that each trigger a test run that triggers a package download. Anyway … I digress.

Partially to save face 😊, but also important to clarify since I didn't effectively communicate it in the initial assessment - the conclusion that react-select is among the more popular options did take into account that React libraries get re-installed constantly. It's definitely not accurate to do a 1:1 comparison of NPM download counts. Most of the libraries evaluated had such comparatively low stats that I felt pretty comfortable classifying react-select as more popular. The library I couldn't conclude this with is Select2. It's likely the most popular based on ~200K weekly installs, many for sites that likely do not use the NPM-buffet approach.

And the the highest states happen to belong to what seem to be the best candidates: select2 and react-select .

Updated issue summary is on the way...

Wim Leers’s picture

#205: I'm very very sorry 😞I should've been more clear. That small rant about ">1M/week" was not criticism towards you! Obviously you can compare npm download numbers across different npm projects. I'm just saying it is a silly metric to track in general. Just like it's ridiculous to pretend having 10K Drupal modules is a good thing (which we tend to do 🙃).

Anybody’s picture

And the the highest states happen to belong to what seem to be the best candidates: select2 and react-select .

#199 Selectize sounded equally good to me based on your findings? Or did I get you wrong?

But let's wait for the comparison... I was just wondering about that sentence, following the mails from this issue.

droplet’s picture

https://www.drupal.org/project/drupal/issues/1329742

data consistency would be a priority problem it should be reviewed. Also, a lib returned ARRAY better than CSV-alike STRING.

ARRAY > ALWAYS COMMAS ONLY > CSV-alike (Drupal)

jonathanshaw’s picture

I'm reminded of what was learnt recently on #2113931: File Field design update: Upload field. where hundreds of hours of work had to be discarded:
it's very very hard to retrofit accessibility to a complex component that was not designed for it from the ground up.

What I've not yet seen much discussion of is what Drupal core gate accessibility would look like for an autocomplete? We badly need a spec of some kind. Then we could assess how hard it would be to make any particular library acheive that spec.

The problem is that it is not possible to make an inference from A to B to C where
A) this library has made some/much apparent effort to deliver accessibility by using lots of aria syntax etc
B) this library has even 95% of the accessibility we need
C) it will be easy to bring it up to 100%

As I understand it core gates for accessibility are not very flexible by nature: close to compliant is still not acceptable.

What @bnjmnm has brilliantly demonstrated is that are significant concerns with every library and no standout winner.

What spec to use? A knowledgeable user in this comment:
https://github.com/select2/select2/pull/5571#issuecomment-514923004
suggests:

the UI pattern fo follow is the combobox one described in the ARIA Authoring Practices:
https://www.w3.org/TR/wai-aria-practices-1.1/#combobox

Do our accessibility maintainers agree?

If we do, then I suggest the question we would need to answer is:
for any given library, what would be the hardest aspect of getting it to match that spec?
It's the hardest aspect that is ultimately the critical one when success is a binary pass/fail as it is here.

I appreciate that this is a hard question; but the experience of #2113931: File Field design update: Upload field. suggests it's risky to work on developing accessible components by starting with low hanging fruit.

bnjmnm’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

@jonathanshaw from #209: +1 on defining the a11y spec this should adhere to so we can factor that into the evaluation process. I've updated the issue summary and included that in the remaining tasks.

bnjmnm’s picture

Issue summary: View changes
bnjmnm’s picture

Issue summary: View changes
webchick’s picture

Thanks for the issue summary updates! Ok, posted this to Twitter to hopefully get it in front of a wider set of eyes. https://twitter.com/webchick/status/1159727661897273344

webchick’s picture

One that was brought up in that thread that doesn't seem to be here yet is http://leaverou.github.io/awesomplete/ (apparently one of the ones under consideration for Joomla! 4, according to https://twitter.com/brianteeman/status/1159733875377135622)

webchick’s picture

Also cross-posted to the #accessibility channel in Slack.

@andrewmacpherson there noted (verbatim apart from fixing a few typos for clarity):

FWIW, my favourite keast-shitty one us still the jquery.ui autocomplete. Sad to see it go :-(
The earlier issues around Select2 and whatever-the-other-was-called fizzled out because it wasn't ckear what we wanted.
To me, these kind of libs suffer from nany features, one-stop swiss army knife. Same as sludeshow libs.
The a11y problems are difficult, because the libs expose lots of independent config options, which deserve different semantics.
Plus, even in the a11y community there is no reliable consensus on what the semantics/behaviours should be for those "buttons inside a textbox" widgets
I think it could help if we know what (accessible) widgets we need for Drupal, rather than looking at the huge list of configurations these libs advertise.
It's about satisfying users, not the W3C... because WCAG doesn't actually cover this at all.
ARIA has semantics which can describe a dynamically changing list of options. jquery.ui autocomplete didn't use them though. Probably because it was written when ARIA implementations were at ab earlier stage. instead it uses an aria live region like our drupal.announce. Every time you press a key it adds a new entry in an invisible live region, which can grow forever! Crude but it works.
The "buttons inside a text box" pattern is pretty problematic. They favour pointrr users at the expense of making it more laborious for other methods .
Say there are 4 tags there already. Pointer users can directly remove any tag. But on implementations I'e seen, if a keyboard user wants to remove the first tag, the have to use backspace to delete them all, then re-add the ones they want to keep.
That means a greater risk of unintended data loss too.
The GREAT thing about a nirmal text box, is that once you're inside it, everyone is on a very even footing.
[The pill/chip pattern is] something that is being explored in the ARIA Authoring Practices guide. It's still controversial in the a11y community though.
Basically the thing that looks like a text box with pill buttons inside us actually a fieldset with a nested ARIA grid widget for the pill buttons...
... followed by an autocomplete combobox + list, without visible borders.
Examplec2 here. https://www.w3.org/TR/wai-aria-practices-1.1/examples/grid/LayoutGrids.htm
I've not seen this implemented in an off-the-shelf library yet.
It's also a but controversial among the a11y community. Some concerns are that "grid" doesn't reflect what it looks like, and keyboard discoverability, and users just aren't familiar with it yet.
Or, it's a cowpath that is unpaved as yet :-)
I just checked the Van11y widget collection [https://van11y.net/]. It follows the ARIA Authoring Practices closely, for better or worse. It doesn't include the pills + autocomplete yet.

andrewmacpherson’s picture

@bnjmnm - thanks for the big survey!

droplet’s picture

I appreciate the hard-working on the WCAG reviews but there are many basic problems we have to address them.
(It helps us to save our time for difficult WCAG reviews.)

#214

Generally, unstyled tagging lib can kick it out.

For unstyled tagging, we need to provide a way to edit the middle tag. For example, we expected to change "JavaScript" below will popup another new list to select. (This is a Code bug, UX problem, also WCAG I think)

"CSS, JavaScript, HTML"

droplet’s picture

If we think out of the box, we can change the tagging and multiple selection design. So call it Drupal Pattern.

For instance, we can use the WordPress way to add a tag. Then, we only need a lightweight SINGLE-selection lib (dropdown + filter)

webchick’s picture

Another library raised in the Twitter thread that's not here yet. https://github.com/github/auto-complete-element (via https://twitter.com/dgrammatiko/status/1159820163547566081)

mgifford’s picture

My comments are more about the replacement for jQuery UI autocomplete. The better multiselect library is a bigger challenge, and I still haven't found anything that does it for me. It also hasn't been a priority lately.

The GDS in the UK did this piece last year talking about their solution. They also published these examples.

Dennis Lembree (@webaxe on Twitter) pointed me to the GDS blog post as well as one of his own autocomplete demos.

I don't know if the downshift WAI-ARIA compliant enhanced input React components are an option at this stage. Here's the downshift example page. I was pointed to this on Twitter by @devisscher.

If what we ant to do though is replace it with something like Select2, not sure there is an accessible one that has come up and is well supported since this issue was created almost 5 years ago. I wonder what solutions communities like WordPress & GatsbyJS are using.

bnjmnm’s picture

I did a quick accessibility review of the Wordpress tags field and it's one of the better ones so far. :The issues I found are all things that could be addressed without much difficulty (were I to evaluate more strictly against W3 specs, it's possible I'd discover trickier issues).

The Javascript that does this is React-based and seemslike it is very threaded into Wordpress' overall architecture. Does not look like something that could be easily ported to another CMS. but I think these findings are still valuable.

  • Screenreader users have no way of knowing there is autocomplete functionality until they begin typing.
  • Field provides an aria role of combobox - this results in screenreader instructions to "Display a list of options, press Control-option-space". Following these instructions results in nothing because options aren't available until text is entered in the field to trigger autocomplete.
  • While arrowing through the options, it reads the option followed by "clickable". It does not provide "option (X) of (total)" information. Note that the total available options are read when the options list first appears.
  • Gutenberg onlyHaving a screenreader read the existing values of a multiselect field is possible, but odd. Once a value is in the field the field itself is focusable until the user has tabbed through all existing items. The tabbbale part of the existing items is their delete buttons. Tabbing to each items delete button will first read "remove tab(button)" followed by the button name and its position in the list. After tabbing past the last item, the screenreader will state it's on the "add new tag" input. I can see the benefits of this as it forces the user to hear the existing values before adding a new one, but that could also become an unwieldy number of tab stops.
  • Pre-gutenberg The text input for a tags field never has a value. When a tag is added via this input, the values are added below the field in a separate container. Each item's delete button can be tabbed to. This is a nice way to get around the UX hassles of
    having multiple values in a single text input, but really bad for screenreaders since there's nothing to indicate the field has any values until it's been navigated past.

Should also point out the Wordpress approach - like most of the options reviewed - has the same concerns first mentioned in #161, where the field height may increase with multiple values. The only way for this to not happen (without horizontal scroll on overflow) is to use a text field.

bnjmnm’s picture

https://github.com/github/auto-complete-element findings

This is a pretty quick one to rule out so not bothering with the table-treatment unless made aware of an obvious benefit.

  • Does not support multiselect
  • Does not support create
  • Screenreader does not announce options when they appear or provide instructions how to access them.
bnjmnm’s picture

Awesomplete findings

https://leaverou.github.io/awesomplete/
The attached prototype was tested with taxonomy autocomplete on the article content type.

Code Style Vanilla JS, Easy to read and even with a good amount of comments it's only 552 lines pre-minification
Maturity Github issues have a pretty good rate/speed of response from the maintainer. There are 145 open issues, but it was difficult to find ones worthy of concern. Many were user error, would-be-nice-ifs, or questions. Although it would be nice if many of these were closed, important issues seem to get addressed.
Expanding on something mentioned in #214 it looks like this was added to Joomla ~summer 2018 (possibly earlier). I hoped to find a lengthy issue like this one where Joomla vetted the heck out of it , but the closest I could find was https://github.com/joomla/joomla-cms/pull/20888 -- which at the very least seemed like success with using the library.
The NPM stats are on the lower end compared to other libraries, but its use in Joomla probably evens that out a bit -- it seems like its used widely enough that there's been many pre-existing users around to identify major problems so Drupal users don't have to
Accessibility Some of this can be credited to the library not using the pillbox approach, but the only accessibility issues I found were ones I was able to easily address in the attached prototype. There may well be things that aren't quite there that can be found by very skilled a11y people like @andrewmacpherson or @mgifford, but is currently the only candidate that did not have accessibility problems when I put it through my pretty-good-but-not-expert a11y tests. (with the quick fixes I added to the prototype).

The biggest issue I found only happened with the online demo, where sometimes an option would be highlighted that was not focused/active. Did not encounter this issue when used in Drupal.

AJAX support Not built in, but Awesoplete is built in a manner that made implementing this pretty easy, and it's part of the prototype
Single/Multi select Both are supported
Filter search Easy to implement
Create (tag) Yes - this is also working in prototype.
Other
  • This does not support optgroups, so it unfortunately cant be used to improve the UX of select elements. Even though select is not supported, I recommend this option remain considered. Improving select was the original impetus for opening this issue, which was a very-desirable but not critical change. In the ~5 years that have passed, we're now faced with the critical need to deprecate the use of jQuery UI libraries. Awesomplete is currently among the candidates with the highest likelihood of getting through the core gates. Improving select can get a followup issue or perhaps we can submit a PR. An issue that hoped this would be added was opened in 2015
  • While this cant currently be used to improve select because optgroups aren't supported, this is among the few libraries that would not experience the concern in #161 (the input height increasing when filled with many items), because it uses a textfield. This sidesteps the design/ux challenges that would accompany pretty much all the other libraries. While some may prefer the UX of pillboxes, it introduces some legit accessibility concerns as pointed out by @andrewmacpherson (via @webchick) in #215.
  • To summarize the above, this strikes me as the least-disruptive, most-accessible option I've evaluated so far. Naysayers are welcome and encouraged - who knows how much of this enthusiasm can be attributed to the excitement that comes from adequate screenreader support?
Ghost of Drupal Past’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Let me add awesomplete to the IS. This is , well, awesom(pl)e ;)

bnjmnm’s picture

Title: Replace jQuery UI autocomplete with better multiselect library » [policy, no patch] replace jQueryUI autocomplete with awesomplete
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +Needs followup

Updated issue summary to bring in the policy people. Also tagging with "needs followup" to create an issue that represents the original intent of this issue when it was created in 2014 - to improve the UX of select elements.

Berdir’s picture

What about terms with commas in them? That's very confusing to deal with in our current autocomplete. At least the demo doesn't seem to support that, with those simple data lists, but I guess the custom matching that I saw in one example should allow to reimplement the existing hacks we have with quotes and stuff?

Another use case is identical labels, our workaround there is the "Label (ID)", which I think is another thing that's pretty confusing to inexperienced users, especially for the private message module, where a lot of regular users came into contact with that and I got lots of issues about that.

In other words, looks like the focus of this issue shifted to basically doing a drop-in replacement of jquery UI autocomplete with a library that does the same thing, with the same advantages and disavantages? I guess that does make sense considering that we need to get rid of the jQuery UI components and it seems to be pretty much impossible to have UI improvements without a11y drawbacks?

Maybe that would better be done as a separate, new issue though, rather than changing the goal of this one at 200+ comments? :)

Status: Needs review » Needs work

The last submitted patch, 223: awesomplete-prototype.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Wim Leers’s picture

It's impressive that the solution that is being proposed after extensive research is one consisting of only 552 lines of code. The difference in size with several others is striking mind-boggling. 2KB versus at least 68 KB for select2 (and at most 77 KB) versus 250 KB for react-select.

Given that you've done such a deep analysis, I'm wondering if @bnjmnm could share his perspective on why there is this a multiple-order-of-magnitude difference. The two obvious questions: A) Do the others do so much more? B) Are they needlessly complex? I'm sure the answer is somewhere in the middle.

amateescu’s picture

@Berdir:

Another use case is identical labels, our workaround there is the "Label (ID)", which I think is another thing that's pretty confusing to inexperienced users, especially for the private message module, where a lot of regular users came into contact with that and I got lots of issues about that.

I was also interested in this and, by looking the documentation, it seems that Awesomeplete will be able to fix this long-standing problem for us:

Suggestions with different label and value are supported too. The label will be shown in autocompleter and the value will be inserted into the input.

bnjmnm’s picture

Status: Needs work » Needs review

#226

What about terms with commas in them? That's very confusing to deal with in our current autocomplete. At least the demo doesn't seem to support that, with those simple data lists, but I guess the custom matching that I saw in one example should allow to reimplement the existing hacks we have with quotes and stuff?

The implementation of the prototype patch includes being able to add/create terms with commas and/or spaces the same way it currently works in core.

#228

I'm wondering if @bnjmnm could share his perspective on why there is this a multiple-order-of-magnitude difference. The two obvious questions: A) Do the others do so much more? B) Are they needlessly complex?
  • Awesomplete has fewer features than the other candidates, which makes sense as most of them are designed to enhance select elements, not just be autocomplete. A quick scan of Select2 shows all sorts of nice features that simply aren't needed for autocomplete.
  • There's no built-in AJAX support (but it was pretty easy to implement)
  • Fewer options than many of the libraries - things that might be defined in most libraries with an options object are accomplished with callbacks instead.
  • A big part of the size difference can be attributed to Awesomcomplete enhancing the functionality of an existing input, while the other candidates created entirely new UI elements. I saw many lines of code defining the interactive properties of divs and spans added by the library - something that isn't necessary when the element is already interactive.

The difference is substantial enough that it's probably worth reviewing the code of some of the other candidates to see if they address use cases that Awesomplete does not.

joegl’s picture

Suggestions with different label and value are supported too. The label will be shown in autocompleter and the value will be inserted into the input.

Is this actually a problem with the current JQuery UI Autocomplete or it's core implementation? As far as I know, drupal core inserts the label into the input instead of the value, and this wasn't a constraint or design decision forced by JQuery UI Autocomplete. I'm not in anyway stating we shouldn't move on from JQuery UI Autocomplete, but just wanted an answer on this. The reason for this I believe is the need to store the value while still showing the label to the user (by appending the ID's with the labels in parentheses to regex them out later). It appears Awesomplete does solve this, but I'm not entirely clear on how.

EDIT: Apologize for all the edits and if this is redundant, I'm just excited about this!

Wim Leers’s picture

#230: Thanks, that's a very helpful overview!

There's no built-in AJAX support (but it was pretty easy to implement)

http://leaverou.github.io/awesomplete/, search for "AJAX" — AFAICT it's intentional that awesomeplete does not itself do the AJAX request :)

Awesomplete has fewer features than the other candidates, which makes sense as most of them are designed to enhance select elements, not just be autocomplete. A quick scan of Select2 shows all sorts of nice features that simply aren't needed for autocomplete.

So this gets to the very essence of my original question: the other libraries have more features, but do we need them? It sounds like the answer is "no"?

Berdir’s picture

@Wim: See #226. Depends on your definition of "need". We don't need them to replace jQuery UI Autcomplete as it's very similar to jQuery UI Autcomplete in how it works based on what I understand *but* the original purpose of this issue was to have something *better* than the current UI.

And in regards to the key/value stuff in #229, I don't think that actually helps because in the end, it's still a simple textfield that's submitted to the server and needs to be parsed. As discussed in Slack.

Unlike select2 and similar libraries, where a selection is a thing that has an internal, non-visible ID and a label, just like a select option that we can submit and reliably process. But all those implementations have all these a11y problems.

So as I said in #226, I think it would make sense to create a new issue for our new goal (which now is to get rid of jQuery UI asap, not improve what we have), and keep all the investigation/research here open.

catch’s picture

Just catching up on this, but from an issue management perspective I agree with #233. It sounds like we can do a near-drop-in replacement of jQuery UI with awesomplete, and we should open a new issue for implementing that.

Then this issue can stay open for its original purpose with all the new research, which has been really useful in its own right and can continue independently of replacing jQuery UI.

lauriii’s picture

+1 to #233 and #234. Let's open another issue to discuss replacing jQuery UI autocomplete with awesomplete and keep this open to continue discussion around libraries that could be used to achieve the UX improvements.

bnjmnm’s picture

Title: [policy, no patch] replace jQueryUI autocomplete with awesomplete » Improve usability and accessibility of long select lists
Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs followup

New issue has been created for the jQueryUI autocomplete replacement #3076171: Provide a new library to replace jQuery UI autocomplete, and the issue summary here has been brought back to it's original intent.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

andrewmacpherson’s picture

Issue tags: -JavaScript +JavaScript

There's something in the evaluation approach which should be avoided in future...

#200 says:

GOOD: grep for 'aria' has the healthiest results of any library.

I was puzzled by what this meant. Elsewhere I see grepping for mentions of "aria" was part of the evaluation. But what does healthy mean here - a lot of matches, or few matches?

Never give any weight to this count. It's highly misleading because:

  • The first rule of ARIA use, is that you don't use ARIA when the host language already provides the semantics and behaviour you need. If you find a lot of instances of "aria", the first reaction should be: "Why so much ARIA? Hasn't the developer heard of HTML?"
  • The number of times that ARIA roles, states, properties, and relationships are used says nothing at all about whether they have been chosen well, or applied to appropriate elements. Developers just make stuff up, a lot.
  • ARIA only provides semantics. Even if roles, states, and properties have been chosen well, the actual behaviour still needs to be implemented. Developers sometimes omit a lot of that.
  • At best, the number of times "aria" appears can tell you which library has made the most elaborate attempt to address accessibility.

I appreciate the level of detail in the evaluation comments - so much to digest. The ARIA grep count shouldn't be given any credence though.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

catch’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Anybody’s picture

@bnjmnm: With a lot of awesome work in #3076171: Provide a new library to replace jQuery UI autocomplete done, is A11y_autocomplete (npm package from that issue) also a candidate to solve the other UI / UX improvement requirements mentioned in this thread?

Like X-Device (multi)-selection with filtering for large lists, ...

If yes: What's the strategy?
Extending the library itself? Adding a dependent package?

If no: How can we proceed here and how can decide that?

In the meantime, the analyzed libraries also received relevant updates (e.g. https://github.com/select2/select2/pull/5571) so that the best candidates from above:

  1. https://github.com/select2/select2 (25.2 k stars)
  2. https://github.com/selectize/selectize.js (12.8k stars)
  3. https://github.com/LeaVerou/awesomplete (6.8k stars)
  4. https://github.com/Choices-js/Choices (4.5k stars)
  5. Any other still relevant ones?

should be re-evaluated. Together with that re-evaluation I think it would make sense to add a table to the IS which shows in one sentence if a library is still an option at all with links to the details, like for

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)

?

bnjmnm’s picture

@Anybody Glad there's still interest in this!

While A11y_Autocomplete certainly isn't capable of this out of the box, it should be able to support this kind of customization. It definitely did when I initially built it, I assume it still does after recent changes (but I can't say 100% since I haven't evaluated it since those changes).
I believe most of it could be accomplished by adding event listeners that only fire if the autocomplete input has an attribute indicating it should be multiselect. It may also require instance method or two being overridden, but this should be possible
I'm not sure how long it will take for A11y_Autocomplete to get into core - there are many moving parts to consider. An A11y_Autocomplete solution could be provided as contrib, though. A great contrib solution may be the most convincing way to get it into core.

As for the other solutions:

  • Select 2 is a jQuery plugin - core is no longer adding new jQuery usage unless absolutely necessary. This probably isn't necessary.
  • Selective is also a jQuery plugin
  • Awesomplete is a great autocomplete, but the level of customization required to provide the functionality requested here would require very extensive enough overrides that it is effectively custom solution
  • I did a quick check of the current version of Choices and it's still not ideal with screenreaders. I think it could get there, but I don't know how much would require changes to the library itself vs. modifying it's behavior in core.

All of those options include the approach of the selected items being inside the input. The multiselects I've seen that provide better accessibility (in my opinion at least) display the selected items outside of the input, and use the input only for adding new items. I'm unsure if there's a semantically correct way to have interactive "pill" items within an already-interactive input .

Anybody’s picture

@bnjmnm: Thank you for your super quick and informative reply!

So if I get you right and based on that list, you'd vote for extending A11y_Autocomplete to provide the other relevant options. I agree that this makes sense and Drupal would benefit a lot to have such a complete, out-of-the-box solution.

Using a A11y_Autocomplete module until it's in core is also a good idea once A11y_Autocomplete library has these options.
I found this one: https://www.drupal.org/project/a11y_autocomplete is that what you mean?

As the other relevant libraries don't seem to be a good option anymore and this issue is very long, would it then perhaps make sense to create an issue based on / referencing this issue and #3076171: Provide a new library to replace jQuery UI autocomplete to define and discuss the additional features needed additionally to the jQuery UI autocomplete replacement?

We could compare the relevant features from the listed libraries and based on your great analysis in this issue and create a list of required features. For example the select-list, filtering, etc.

Alternatively, we could do it outside of Core's issues here: https://www.drupal.org/project/issues/a11y_autocomplete
or is there any GitHub Repo I didn't find yet?

Or would you like to proceed in this issue?

It would be nice if you could lead the way, as you're deeply involved!

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

One module that's helped our projects is https://www.drupal.org/project/cshs which has a submodule for menus.

xjm’s picture

Title: Improve usability and accessibility of long select lists » Improve usability, accessibility, and performance of long select lists

 

xjm’s picture

Title: Improve usability, accessibility, and performance of long select lists » Improve usability, accessibility, and scalability of long select lists
Issue tags: +Performance
joseph.olstad’s picture

@xjm, how does this close out #3110371: When adding a new menu link, restrict the available parents to the current menu ?

I'd like to test you on this performance issue. Is there some sort of ajax call being proposed to load children as needed? so select a parent and then the children are ajax loaded? Without patching, core currently loads an entire tree for ALL menus is loaded when we use a menu link in a node edit form. 3110371 fixes that by loading the expected menu rather than ALL menus.

#3110371: When adding a new menu link, restrict the available parents to the current menu
is not only a performance fix, it's a huge usability improvement. To elaborate on a fix for this would be to solve the edge case of situations were one might want to use the node edit page to move menu links around however I argu that the menu system admin ui should do that, not the node edit form.

Have you ever used menu links with the node edit form?

joseph.olstad’s picture

this patch
#3110371-27: When adding a new menu link, restrict the available parents to the current menu

This patch is Passing 100% success, this proves that the edge case that the patch removes and mentioned by @catch wasn't important enough to write an automated test for. If the edge case was important enough there would have been an edge case test and the patch would have caused a test failure.

IMHO, this patch provides a significant usability improvement and it also is a performance improvement from default core behavior.

Simply tossing a working solution aside without providing an improved equally or better solution we can use immediately is a bit disappointing. At least an explanation and some sort of rationale would be appreciated.

With all this said, I'd be curious to try perhaps another approach to perhaps instead of use menu links to see if taxonomy terms would work better. AFAIK when loading a taxonomy term UI core doesn't load all taxonomy terms trees for all vocabularies like the menu tree is doing so it might be a better approach to rely more on taxonomy.
https://www.drupal.org/project/taxonomy_breadcrumb
instead of
https://www.drupal.org/project/menu_breadcrumb

With that said, the default core behavior of menu links has always since Drupal 6 been a pet peeve of mine, it's a rats nest to navigate assigning a menu link to a parent without the patch.

As for the edge case brought up by @catch, I suggest deleting the menu link from the wrong menu and manually creating a new one in the intended menu would match exactly how taxonomy works where terms are not saved to other vocabularies without the convert_bundles contrib module being involved.

IMHO, core behavior of menus should be patched as proposed several years ago in #3110371: When adding a new menu link, restrict the available parents to the current menu

xjm’s picture

@joseph.olstad, you're welcome to explore alternatives in contrib. The fact is, though, that core has many non-performant long select fields that can whitescreen or even take down sites, fields that need to be replaced with reference or hierarchical widgets. Adding HTML number widgets to core fixed some of them, but not the ones that have hierarchy. It's the same problem in multiple places, so we should fix it at the Field API level. This is the issue with the most recent holistic approach to that, so I'm folding menu selection into the scope. Thanks!

joseph.olstad’s picture

@xjm,
yes contrib, I'm curious if there's an inventory of options for contrib here?

So for menu links I've created sansdesordre (without a mess), a very simple module.

It doesn't have the performance benefits of the mentioned core patch.

Related usability improvements offered by contrib

modules that improve the UX but not necessarily deal with scalability from a performance perspective:

libraries mentioned by @Anybody
#2346973-246: Improve usability, accessibility, and scalability of long select lists

Related core issue:

#3076171: Provide a new library to replace jQuery UI autocomplete

What about core performance/scalability?

If you have anymore insight into the related core roadmap and high level decisions on the direction for this please share.
If there's other possible contrib solutions or perhaps a way to enable a performance improvement to enable a UX/performance/scalability solution in contrib then please share plans/ideas/references or discuss.

Thanks

xjm’s picture

@joseph.olstad, whatever solution we pick has to pass the performance gate, so scalability will definitely be taken into account. And anything that doesn't load an entire giant database table into a single field on page load is going to be an improvement, or at least, it'd be difficult to make it worse.

andypost’s picture

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mgifford’s picture

Issue tags: +awesomplete

This is definitely a long issue. Thanks for all the work everyone.

On accessibility, always good to look upstream to awesomplete https://github.com/LeaVerou/awesomplete/issues?q=is%3Aissue+is%3Aopen+ac...

Also, I'm encouraged it is code by Lea Verou.

Chi’s picture

[Deleted] (wrong issue)

donquixote’s picture

A strategy could be like this:

  • A widget type that dynamically switches between select list and autocomplete, depending on the number of available options.
  • Optimized code to build a huge options list without loading all entities into memory at once.
    Part of this can be an entity iterator, another part can be caching of entity labels, and caching of complete option lists. #2846426: Options Select Widget: High Memory usage,
    #2577417: Add an entity iterator to load entities in chunks, #1199866: Add an in-memory LRU cache.
    This can be useful if we have something like < 500 options.
    We could even load the list as a separate request, so it can be cached separately _and_ does not impact initial load time.
  • Client-side libraries that enhance the UX for autocomplete (tags style) widgets.
    (Chosen or slim_select already do this for select lists, but not yet for autocomplete, afaik)

I see discussion around point 3 (client-side libraries) in this issue, but it is not really 100% focused on that.
Perhaps we should open individual issues for the different aspects?

donquixote’s picture

Client-side libraries that enhance the UX for autocomplete (tags style) widgets.
(Chosen or slim_select already do this for select lists, but not yet for autocomplete, afaik)

https://www.drupal.org/project/autocomplete_deluxe
This module does it.
It acts like an equivalent to chosen or slim_select for autocomplete.