This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
inputAs
prop toTextField
to customize how the underlyinginput
is rendered #72Add
inputAs
prop toTextField
to customize how the underlyinginput
is rendered #72Changes from all commits
f6d5d77
8e92e9b
e4de344
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why this PR touches
onBlur
and whatotherProps
used to do?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to sneak this in because I thought it would go through fast. I'm going to pull it into another patch PR. I explicitly don't want to acceptotherProps
because, this being a layout component, it's not obvious where those props will be spread to.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I remember why I did it this way; these two work together because there are formatting changes that will cause merge conflicts and I wanted to avoid that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read the api documentation for cloneElement and createElement to understand what is happening here. From what I understand,
cloneElement
does a shallow copy of the props by default, so we need to merge the classNames explicitly. Will this have unintended consequences or semantics around class precedence that would require documentation?The other case uses
createElement
without merging class names, since there are no props forinputAs
when it is a string, such asdiv
orinput
. It took me about 10 minutes to read through the React docs and understand it. I suggest you add a comment describing the cases here and why the prop merging is different, so hopefully that we don't need to context switch out of the source to understand the behaviorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question. No, the order of the class names in
class="a b c"
has no effect on precedence. Precedence is determined solely by specificity, which has clearly defined rules in the css spec.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I very much value the suggestion and am happy that you read through the docs before bringing up the talking point.
First, understanding the difference between an element and component is critical. A component is the definition of something you will render, either a
React.FC
(functional component) or a class that extendsReact.Component
. An element is the result of a render by either of two methods (note these two are identical; the first will be transpiled into the second by our build tools):jsx
React.createElement
Note:
jsx
is transpiled intoReact.createElement
for use in browsers.As you know,
createElement
andcloneElement
are very different things.cloneElement
takes an element, meaning something you've already rendered, and augments it with additional props; hence theclassNames
merging.createElement
takes either an intrinsic jsx element (like "div") or a component and renders it into a react element.While this not trivial, I think it's more valuable to look at the React docs if someone wants to know how it works rather than explaining it in a comment. In my opinion, I value that you spent the time to read about
createElement
andcloneElement
and I think you got far more out of that than any comment I could leave here. I also think it's better to read the docs because then in the next component where we do the same thing (Buttons, for example), you already know how they all work.