Skip to content

Feature request: allow option value to be set to an object #858

@michaelchihuyho

Description

@michaelchihuyho

Copy of #572 since there seemed to be a misunderstanding of the core issue there. The desire here is to be able to set options that look like this:

var options = [
  {label: 'item 1', value: {id: 123, foo: 'bar'},
  {label: 'item 2', value: {id: 456, foo: 'baz'}
]

The reason this doesn't work currently is because of how this.props.value is interpreted to display the selected option.

  1. Values that aren't strings or numbers aren't handled:
    if (typeof value !== 'string' && typeof value !== 'number') return value;
  2. Even if they were, === is not sufficient for comparing objects:
    if (options[i][valueKey] === value) return options[i];

Is setting values to objects a feature react-select is interested in supporting? If so, would it be okay to add a dependency on an object deep equality checker like node-deep-equal?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions