question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[CR] Different API for `<Select>` component for Grommet 2

See original GitHub issue

Could we make the Select component work more like the native select and option combination in Grommet 2?

Today value on a <Select> can either be a string or object, and it will set the “selected” item to that string/object(even if it doesn’t exist in the options). Also, in the case of options being an array of objects, each of these objects look similar to this { label: 'label', value: 'value'} but in the onChange callback label is irrelevant. What you really care about is the value and/or the index of the element that was clicked.

In short something like this would(imho) be preferred:

const users = [{name: 'johndoe', id: 0}, {name: 'janedoe', id: 1}]

return (
  <Select onChange={(event, index, value) => console.log(users[index], value)}>
    {users.map(u => <SelectItem value={u.id}>{u.name}</SelectItem>)}
  </Select>
)

In this case it’s very similar to a native <select><option></select> and the onChange callback gets passed event, index, value (both index and value could be valuable). Arguably passing an array of objects to options vs mapping over an array to <SelectItem>'s could be seen as the same, but i think that having the <SelectItem>'s make it more similar to how it works natively, and therefore easier to understand.

Expected Behavior

As described above, open discussion

Actual Behavior

Today there are some catches(some mentioned above) to <Select> which can be unintuitive

URL, screen shot, or Codepen exhibiting the issue

Here the issue with how the value prop works today is shown: https://codepen.io/anon/pen/dzpjyx?editors=0010

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
karatechopscommented, Aug 4, 2017

This seems like a more declarative way of of composing the Select component, I dig it. Related to #1484

0reactions
L0ZZIcommented, Feb 6, 2018

It’s a question for @alansouzati and @ericsoderberghp. Above my pay grade.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Select - Grommet
A control to select a value, with optional search. ... Custom label to be used by screen readers. When provided, an aria-label will...
Read more >
Grommet - How to use a Select component with search?
Here is my basic implementation of a Select component with server-side ... based on user's search. const res = await API().categories.
Read more >
Electronic components. Distributor, online shop ... - TME.eu.
Over 30 years we have been co-creating the electronic components market. We combine our global range of business with family way of management....
Read more >
Wire Rope End Termination User's Manual
The purpose of this manual is to provide a resource for preparing wire rope terminations when using Crosby products. The publication contains the....
Read more >
Rubber Grommets Style C
Insulation rubber grommets are used in situations where a cable, pipe, or various other objects have to go through glass, metal sheet, plastic,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found