Skip to content

[Autocomplete] Provide more details in the details param of onChange prop #44603

Open
@dragos-rosca

Description

@dragos-rosca

Steps to reproduce

Steps:

  1. Add an Autocomplete component with multiple={true} and disableClearable={false}.
  2. Add values
  3. Press the clear button

Current behavior

When onChange is called you get:
event = {...}
value = []
reason = 'clear'
details = undefined

Expected behavior

When onChange is called you get:
event = {...}
value = []
reason = 'clear'
details = { option: [...clearedValues] }

Context

When you have an Autocomplete with multiple and not disableClearable and you:

  1. Select an option (op5) you get:
    event = {...}
    value = [op1, op2, op5]
    reason = 'selectOption'
    details = { option: op5 }
  2. Remove an option (op5) you get:
    event = {...}
    value = [op1, op2]
    reason = 'removeOption'
    details = { option: op5 }

Your environment

npx @mui/envinfo
  System:
    OS: Windows 10 10.0.19045
  Binaries:
    Node: 18.20.3 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.0 - C:\Program Files\nodejs\npm.CMD   
    pnpm: 8.14.0 - C:\Program Files\nodejs\pnpm.CMD 
  Browsers:
    Chrome: Not Found
    Edge: Chromium (131.0.2903.51)
  npmPackages:
    @emotion/react: ^11.13.3 => 11.13.3
    @emotion/styled: ^11.13.0 => 11.13.0
    @mui/base:  5.0.0-beta.40
    @mui/core-downloads-tracker:  6.1.7
    @mui/icons-material: ^6.1.7 => 6.1.7
    @mui/lab:  5.0.0-alpha.173
    @mui/material: ^6.1.7 => 6.1.7
    @mui/private-theming:  5.16.6
    @mui/styled-engine:  5.16.6
    @mui/system:  5.16.7
    @mui/types:  7.2.19
    @mui/utils:  5.16.6
    @types/react:  18.3.12
    react: ^18.3.1 => 18.3.1
    react-dom: ^18.3.1 => 18.3.1
    typescript:  4.9.5

I use Chrome: Version 131.0.6778.86 (Official Build) (64-bit)

Search keywords: multiple onChange reason clear details disableClearable

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: autocompleteThis is the name of the generic UI component, not the React module!enhancementThis is not a bug, nor a new featurepackage: material-uiSpecific to @mui/materialwaiting for 👍Waiting for upvotes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions