Skip to content

[autocomplete] getOptionLabel callback is getting the value instead of option object #31192

@hasan-aa

Description

@hasan-aa

Current behavior 😯

When using different types for options and value properties, the getOptionLabel method is passed value instead of option object.

let's say I'm using following types:

type Option = { label: string; value: any; group?: string }
type Value = string;

I'm expecting getOptionLabel method always passed an Option type but that's not the case. That's why the picked option can not be displayed properly.

getOptionLabel={(option) => option.label || "!!!"} //here sometimes Value type is passes instead of Option type.
isOptionEqualToValue={(option, value) => return option.value === value}

Expected behavior 🤔

Always pass and option to getOptionLabel as a param to be consistent.

Steps to reproduce 🕹

Here's a demo:
https://codesandbox.io/s/controllablestates-material-demo-forked-0lekyg?file=/demo.js

Steps:

  1. Render a controlled Autocomplete component using different types for options and value props. (object and string)
  2. Utilize isOptionEqualToValue and getOptionLabel callback props

Context 🔦

I'm trying to render options that are objects like {label:"Label", value:"some value"}, but I want to use the value of the selected option instead of the whole option object.

Your environment 🌎

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements or additions to the documentation.scope: autocompleteChanges related to the autocomplete. This includes ComboBox.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions