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.

pass index of value to Value

See original GitHub issue

Feature Request

Use Case: I needed to add a comma to multi select values (Value component) to give the appearance of a comma-separated list for values. The comma is needed in all Value items except for the last value. While I can add the comma with css it’s overly difficult to target the last .Select-value (Since .Select-value’s have the input as a sibling :last-child is out and :last-of-type didn’t work. Oddly:first-of-type did work).

The only way I found to add a class which notes the Value’s index was to extract the index from the id prop which is passed to values but this is not ideal.

// Value.js
render() {
    // extract the index of the item and label value with css class so the last item's comma can be hidden
    const id = this.props.id,
      index = id && id.indexOf('-value-'),
      valueIndex = id && id.substring(index + 7, id.length),
      valueClass = id ? `Select-value-${valueIndex}` : '';
      ...
}

Solution I propose would add optional valueIndex prop to Value.js ~(and add Select-value-${this.props.valueIndex} class if valueIndex is present)~, and pass this valueIndex prop to the ValueComponent in Select.js. Can provide pr if you agree.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
hakunincommented, Jul 4, 2019

Is there any way to work this around in the meantime?

0reactions
deanbotcommented, Feb 7, 2020

Hey @wzup, I forked react-select and made the various edits I noted at the top of the thread. Then I built the project and included the lib folder directly in my project source (a little messy but it worked).

  1. In src/Value.js, add valueIndex: PropTypes.number // index of value in selected values to the Value.propTypes object at the end of the file.
  2. In src/Select.js, add valueIndex={i} to each instance of <ValueComponent>. I.e. search for “<ValueComponent” and put the new prop after value={…}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass index value in <%= - CodeProject
I tried to pass the [int] index value between <%= %>. JavaScript. <pre> $("#<%= JobMatrixGrid.ClientID%>").find("tr").each(function (index) ...
Read more >
How to pass index value and get name from array response ...
Try this below : onRowClick($event) { const indexid= $event; this.tagPolicesArray['records'].map(function(item, index){ if(index ...
Read more >
pass index of for:index value to js - Salesforce Stack Exchange
I want to get the value of each tile href value using a function getHref is there a way wherein I can pass...
Read more >
Array.prototype.every() - JavaScript - MDN Web Docs
The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value....
Read more >
Excel INDEX function with formula examples - Ablebits
The INDEX array form returns the value of a certain element in a range or ... Likewise, to get the entire row, you...
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