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

Input refs #144

Closed
chrisrolfe198 opened this issue Jul 7, 2021 · 7 comments
Closed

Input refs #144

chrisrolfe198 opened this issue Jul 7, 2021 · 7 comments
Labels
conversation needed Issues that may need to go to a broader conversation question Further information is requested

Comments

@chrisrolfe198
Copy link
Contributor

Support questions

I'm not sure if this is a bug or a feature so I'm asking this as a question.

If I pass a ref to an input component should this give me the input element itself OR another element within the component.

For reference I am trying to select the contents of an input when it's clicked so that it can be copied to the users' clipboard, see a code sandbox example here. In order to make this work I have to select the first child of the ref.

Is this behaviour correct and can I rely on the HTML structure not changing? Or is this a bug?

@snapsnapturtle
Copy link
Contributor

At the moment the ref goes on the outermost element of the input component. Currently this is a div, wrapping the input and the label. I don't have a definite answer how we want to continue (or handle) these kind of features. Probably something like an extra prop like an inputRef that targets the input and perhaps a labelRef targeting the label. Do you have any other proposals or ideas already?

Relates to #134

@snapsnapturtle snapsnapturtle added the question Further information is requested label Jul 7, 2021
@chrisrolfe198
Copy link
Contributor Author

Ah I hadn't spotted the other issue, so I guess for me what is the expectation of how this should work currently? I have a feature I need to deliver this week so whatever the final solution is probably won't arrive in time for me to have my code behave in that way?

If I depend on the html structure for now how likely is it that it'll break without warning?

@snapsnapturtle
Copy link
Contributor

That is correct, we should first figure out how we can enable more customisation for the components that fit all teams and projects. For now, we don't have specific plans to change the structure of the input component, but please keep in mind that I cannot guarantee that the current structure will not change without a breaking change.

@duranmla
Copy link
Contributor

duranmla commented Jul 8, 2021

I think you can rely on the HTML structure if you want to wrap this up as soon as possible due to the urgency of the feature. From what I see from the first proposal from @snapsnapturtle it seems that the change may be related to different props rather than a change on the HTML structure and even if we do such a thing we tend to be very cautious with breaking changes (which sometimes can play against us but favor you)

In that sense, I will solve your issue using the current ref div and traversing from there if possible into the input. Then we need to have a longer conversation on regards the input ref

@duranmla duranmla added the conversation needed Issues that may need to go to a broader conversation label Jul 9, 2021
@duranmla
Copy link
Contributor

duranmla commented Jul 9, 2021

I wonder if we should arrive at a consensus on where the ref should live. IMHO it feels all form controls should have a ref to the actual input, nonetheless, I also feel this needs to come as people need to do things with the value of the component which is also related to #149

@snapsnapturtle
Copy link
Contributor

I totally agree with you here that the ref on such basic components should reference the actual input. There's no point in having it reference a wrapper.

@nlopin
Copy link
Contributor

nlopin commented Aug 16, 2021

Closing this in favor of #169

@nlopin nlopin closed this as completed Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conversation needed Issues that may need to go to a broader conversation question Further information is requested
Development

No branches or pull requests

4 participants