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

How to get a reference of a specific input when render multiple InputRange #172

Open
jaugustodafranca opened this issue Jun 19, 2020 · 1 comment

Comments

@jaugustodafranca
Copy link

I'm using multiples Inputs on the same component to change an object like this:

const currentDays = [ 
	{ day: 'SEG', hours: 2 }  
	{ day: 'TER', hours: 2 } 
	{ day: 'QUA', hours: 2 } 
]

And I'm rendering the multiples like this:

currentDays.map(current => (
      <div key={current.day}>
        <p className={styles.text}>{daysOptions[current.day]?.name}</p>
        <InputRageStyled
          minValue={1}
          maxValue={10}
          value={current.hours}
          name={current.day}
          onFormat={onFormatInputRange}
          onChange={onChangeRange}
        />
      </div>
    ))

How can I get the reference of which input I'm changing to update a specific object inside of currentDays?

Maybe the event to get the name of the input?

This is my onChange function:

const onChangeRange = useCallback((currentValue, event) => {
	console.log(currentValue) // return the correct value
	console.log(event)        // return undefined
  }, [])
@robba86
Copy link

robba86 commented Jun 27, 2020

I think an event is needed to. I miss onBlur & onFocus to handle keyboard events for better accessibility...
But adding event would make things more convenient to get the name, and more...

Or to let the developer get these values with ease and then make the choice to grab what ever the dev whants, not just the values.

Example of output:

{
   name: "name-of-input",
   label: "The label",
   type: "range-single",
   value: 200,
}
{
   name: "name-of-input",
   label: "The label",
   type: "range-multi",
   values: {
          max: 200,
          min: 10,
   },
}

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

No branches or pull requests

2 participants