Description
I'm not sure it's the right place but it's not a bug so I'm not sure where is the right place. (Maybe a new API)
In project I work on, there is a TextField
component which is more than a wrapper for <input>
. It wraps the <input>
element with a <div>
to overcome some limitation that needed by a requested design.
TL;DR
The forwardRef API as is seems to not be usable for this use case, because:
-
The actual wrapper is a
<div>
which is not what you expect when you manually want the textfield element. Because you would expect the<input>
for using commands such as#focus()
or#checkValidity()
and so -
But sometimes you do need the
<div>
container because you need to measure the element which the inner<input>
is useless for.ReactDOM.findDOMNode
from what I've search isn't recommended. But it also blocks the ability to use the code in React Native or other renderers
Today, I add functions to the component class such as TextField#focus()
(that calls focus on the <input>
) and I'll probably need to add one for TextField#getClientRects()
(for measure the <div>
). But, it seams redundant and not very stable as more native DOM functionality is needed to warped by the component class for imperative needs use cases (as the project grows and more needs are added).
What do you think I should do?
Maybe forwardRef need some tweaks?
Maybe a new API is needed?
Or maybe the current scenario of what I do is the least worst option?