Skip to content

ChoiceAutocomplete shows "No options" on focus before user has typed anything #2002

Description

@leoniedickson

When a choice item with itemControl=autocomplete is clicked for the first time, the MUI dropdown opens immediately and displays "No options" — because results are fetched from the terminology server on input, so the options array is empty on initial focus.

This is misleading: options do appear once the user starts typing. The open-choice equivalent avoids this because it uses MUI's freeSolo prop, which suppresses the popup when no options are loaded.

To reproduce: paste the following into the Playground:

{
  "resourceType": "Questionnaire",
  "status": "active",
  "item": [
    {
      "linkId": "gender",
      "text": "Gender (choice autocomplete)",
      "type": "choice",
      "extension": [
        {
          "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
          "valueCodeableConcept": {
            "coding": [
              {
                "system": "http://hl7.org/fhir/questionnaire-item-control",
                "code": "autocomplete"
              }
            ]
          }
        }
      ],
      "answerValueSet": "http://hl7.org/fhir/ValueSet/administrative-gender"
    },
    {
      "linkId": "gender-open",
      "text": "Gender (open-choice autocomplete)",
      "type": "open-choice",
      "extension": [
        {
          "url": "http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
          "valueCodeableConcept": {
            "coding": [
              {
                "system": "http://hl7.org/fhir/questionnaire-item-control",
                "code": "autocomplete"
              }
            ]
          }
        }
      ],
      "answerValueSet": "http://hl7.org/fhir/ValueSet/administrative-gender"
    }
  ]
}

Click into the choice field without typing — it shows "No options". Click into the open-choice field — no dropdown appears. The latter is less confusing.

Expected behaviour: Either show nothing on initial focus, or show a prompt like "Type to search..." instead of "No options".

Suggested fix: Set noOptionsText="Type to search..." on ChoiceAutocompleteField (or conditionally, only when the input is empty).

Affected component: ChoiceAutocompleteField.tsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions