Skip to content

DropdownMenu does not clear or update selection when user types text #176753

@nebkat

Description

@nebkat

Use case

Currently, the DropdownMenu widget allows the user to:

  1. Select an option from the dropdown list (triggering onSelected).
  2. Type arbitrary text into the input field to perform searching or filtering.
  3. Tap out of focus and leave the arbitrary text visible without selecting anything or triggering any callbacks.

This is confusing as the text field is the primary feedback for which item has been selected yet it no longer reflects that. See example.

Proposal

I believe the most comprehensive solution would be:

DropdownMenu(
    autoSelect: true,       // Automatically select highlighted menu item if focus lost
    incompleteTextBehavior: // If no highlighted menu item, or autoSelect: false
        DropdownIncompleteTextBehavior.ignore, // Leave text as-is,  don't emit (current behavior)
     or DropdownIncompleteTextBehavior.emit,   // Leave text as-is,  emit `onSelected(null)`
     or DropdownIncompleteTextBehavior.clear,  // Clear text,        emit `onSelected(null)`
     or DropdownIncompleteTextBehavior.reset,  // Reset to previous, emit `onSelected(previous)`
)

DropdownIncompleteTextBehavior.ignore could then be deprecated with a view to removing in future, forcing the user to do something more sensible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: qualityA truly polished experiencea: text inputEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions