Reference to input
See original GitHub issueThis is not a feature request per se, but I cannot seem to find this in the documentation. I have also asked a question about this on SO.
How do I get a reference to the input element so I can .select()
the text inside of it?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (1 by maintainers)
Top Results From Across the Web
<input>: The Input (Form Input) element - HTML
The <input> HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide...
Read more >reference | input() - P5.js
The .input() function is called when any user input is detected with an element. The input event is often used to detect keystrokes...
Read more >CIP 31 - Reference inputs - Cardano Improvement Proposals
A reference input is a transaction input, which is linked to a particular transaction output as normal, except that it references the output...
Read more >Input Output Reference — EnergyPlus 8.8 - Big Ladder Software
This single input object is used to produce two important reports that are used to identify the specific output variables and meters available...
Read more >HTML input tag - W3Schools
Attribute Value Description
disabled disabled Specifies that an element should be disabled
form form_id Specifies the form the element belongs to
max number date Specifies the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@artooras Here is your solution.
@manualva7 100% incorrect. Here is the working “solution” that you said isn’t possible: https://codesandbox.io/s/react-select-editable-and-selectable-6nfdv
Please consider reading before refuting so assuredly what’s possible and not possible in the future.
To set the record straight, the fact is that React-Select DOES render an Input (when the searchable prop is true). What also does happen is that the opacity is set to 0 based on whether or not it thinks it should display based on a
isHidden
prop sent to the Input component (see here for the implementation) What we need to do is keep it visible and do away with the SingleValue/MultiValues with thecontrolShouldRenderValue
prop.If you care to learn, here are some of the other “suggested” approaches that could/should have resolved this with hopes that either someone can point out where proposed solution #1 went wrong or to push for making this a much easier internal solution (autoHideInput to override default behavior, editableInput which could manage these state changes internally, easier to override styling, etc…)
Custom Component: (Does not work today for me on my computer)
Creating a Custom Component for Input should work, but when testing today, the controlled component seems to be re-rendering the input on every keypress which results in losing focus and winds up setting the document.activeElement to body instead of the input. I am not sure what changed between testing locally on some existing React-Selects and today’s Sandbox, but I had to remove it.
Custom Styling: (Does not work)
Theoretically, this should also work, but the way the Input component was written, overwrites the opacity style based on the prop isHidden which is sent to the Input.
CSS: (Works)
I understand specificity and the stigma around
!important
but it exists for reasons like this; that being a 3rd party library with no apparent alternatives to overwriting inline styles which affect the desired behavior.That said, I appreciate having a community so we can help solve similar problems. It’s why we are all here. It’s just not helpful when so much free time is taken to help others only to blindly discredit the methodology and approach without any thought for what you might be missing.
I’ve built some cool stuff with this tool there’s still a lot that I’ve learned just this past weekend. Looking forward to building more tools and community together.
Thanks @ebonow . Is the following
documented anywhere? Because I think it should be 😃
In my case, I ended up using a workaround which, though may not be entirely correct, works for me quite reliably. This is based on the assumption that when I call
focus()
on thereact-select
, the input that is in focus indocument
is that ofreact-select
: