Avoiding aria-autocomplete="list" when no autocompletion providers

Is it possible for codemirror/autocomplete or other party to detect whether there are any autocompletion sources loaded?

I am looking into an accessibility issue related to our use of CodeMirror where some file types may have language support with autocompletion and others may not.

The issue author suggests that aria-autocomplete="list" is confusing when autocomplete suggestions are not possible in a given editing configuration.

Is there a reasonable way to programmatically detect whether our selected LanguageSupport includes support for autocomplete? It looks like some FacetProviders under a LanguageSupport can contain values like { autocomplete: Function }, but I do not know whether that is a reliable way to detect support or merely a naming convention.

In addition, if such detection is possible, would detecting within codemirror/autocomplete be possible so that aria-autocomplete="list" could be added conditionally? If so, would you be open to a PR that did so?

This patch adds this behavior. But note that it can only see whether there are any completion sources registered for the editor, not whether any apply in the current context (i.e. if you have a JavaScript completion source that will act when the user types in a <script> tag of an HTML document, but no HTML completion, the attribute will still be present even with the cursor in HTML context.)

@marijn I applied your changes locally, and this works perfectly.

But note that it can only see whether there are any completion sources registered for the editor, not whether any apply in the current context

That makes sense. :slight_smile:

Thank you very much!

Hi @marijn, would you be up for making a new release of @codemirror/autocomplete that contains this fix?

Sure, tagged 6.16.3

Thank you!