mui / mui/material-ui

[autocomplete] Provide more details in the `details` param of `onChange` prop

Open
#44,603 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

scope: autocomplete type: enhancement waiting for 👍
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Autocomplete component's onChange entry point and trace the multiple-selection clear-button path described in the reproduction steps. Confirm the current clear behavior and verify that, when reason is 'clear', details.option contains the values that were cleared.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.