[Feature Request] Align how _inputNode is checked in Input and Textarea #579
-
While I was reviewing the differences between the implementation of property changing in input and textarea components, I noticed there's a slightly different approach to how const native = this._inputNode;
if (native) {
native.readOnly = this.readOnly;
} Is the check necessary? In which scenario native would be updated(changedProps) {
super.updated(changedProps);
if (changedProps.has('type')) {
this._inputNode.type = this.type;
}
if (changedProps.has('placeholder')) {
this._inputNode.placeholder = this.placeholder;
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
the difference is that const native = this._inputNode;
if (native) {
native.readOnly = this.readOnly;
} get's executed lion/packages/input/src/LionInput.js Line 60 in 54f5853 so this can get executed before the dom node is available (maybe it gets rendered?) In comparison does my explanation makes sense? 😅 |
Beta Was this translation helpful? Give feedback.
-
Thanks for the clarification. This raises additional question though. If there is no need for the check in lion/packages/textarea/src/LionTextarea.js Lines 68 to 73 in 60284d7 knowing that it's inside if (changedProperties.has('rows')) {
this._inputNode.rows = this.rows;
} If it's the case, I could follow up with another PR after the addition of placeholders in Textarea. |
Beta Was this translation helpful? Give feedback.
-
Personally I wouldn't mind if we can get rid of redundant guards, so feel free to send a PR, if the tests pass I would be okay with merging, going by daKmoR's logic it should be fine. If it fails, it might be an indication something else is wrong. |
Beta Was this translation helpful? Give feedback.
-
@daKmoR I looked into this more and my proposal would be the following:
_delegatePropToInputNode(propName) {
this._inputNode[propName] = this[propName];
}
Then we make sure it's consistent everywhere, for rows, autocomplete, placeholder, type, readonly etc. etc. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
Closing as enhancement with votes needed. If someone wants to push for this, feel free! Or vote if you think it's important by 👍 'ing. |
Beta Was this translation helpful? Give feedback.
-
We have strict types now in Lion, and inputNode is now always strictly typed as not being undefined, so that kinda solves it and removes the need for the guard 👍 |
Beta Was this translation helpful? Give feedback.
We have strict types now in Lion, and inputNode is now always strictly typed as not being undefined, so that kinda solves it and removes the need for the guard 👍