Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select's activeItem prop does not work if items are not 'strings' #2998

Closed
jonavila opened this issue Oct 5, 2018 · 1 comment
Closed

Select's activeItem prop does not work if items are not 'strings' #2998

jonavila opened this issue Oct 5, 2018 · 1 comment

Comments

@jonavila
Copy link

jonavila commented Oct 5, 2018

Environment

  • Package version(s): 3.6.1
  • Browser and OS versions: Chrome 69

Steps to reproduce

  1. Use the Select component '@blueprintjs/select' and use an array of objects for the items prop.
  2. Specify the activeItem prop as one of the objects in the items prop
  3. Provide a value prop.

Actual behavior

The activeItem is not highlighted when the select's popover opens showing the list of items

Expected behavior

activeItem should be highlighter

Possible solution

The activeItem prop works as expected when the list of items are of type 'string'. I believe this part of the source code is what's setting the itemRenderer modifiers:

https://github.com/palantir/blueprint/blob/develop/packages/select/src/components/query-list/queryList.tsx#L211

My guess is the equality of activeItem === item is failing for objects

@giladgray
Copy link
Contributor

giladgray commented Oct 5, 2018

@jonavila the === check will definitely fail if the two objects are not exactly the same object. not objects that look the same but actually the same. this is a known limitation of the API. to fix it we'll have to introduce an itemComparator prop a la itemDisabled to allow customizing the equality check. see #1340.

example:

// actually the same instance
const obj = { prop: "yes" };
const obj2 = obj;
obj === obj2 // true

// look the same, separate instances
const a = { a: 5 };
const b = { a: 5 };
a === b // false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@giladgray @jonavila and others