-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Typography] Improve custom component types support #18868
Merged
oliviertassinari
merged 1 commit into
mui:master
from
fyodore82:typings-for-component-prop
Dec 17, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { FC } from 'react'; | ||
import { Typography } from '@material-ui/core'; | ||
|
||
const TypographyTest = () => { | ||
const CustomComponent: React.FC<{ prop1: string; prop2: number }> = () => <div />; | ||
return ( | ||
<div> | ||
<Typography /> | ||
<Typography align="inherit" color="inherit" display="block" /> | ||
<Typography align="left" color="initial" display="inline" /> | ||
<Typography align="right" color="primary" display="initial" /> | ||
<Typography align="justify" color="secondary" display="initial" /> | ||
<Typography align="inherit" color="textPrimary" /> | ||
<Typography align="inherit" color="textSecondary" /> | ||
<Typography align="inherit" color="error" /> | ||
// $ExpectError | ||
<Typography display="incorrectValue" /> | ||
<Typography component="a" href="url" display="block" /> | ||
<Typography component="label" htmlFor="html" display="block" /> | ||
// $ExpectError | ||
<Typography component="a" href="url" display="incorrectValue" /> | ||
// $ExpectError | ||
<Typography component="a" incorrectAttribute="url" /> | ||
// $ExpectError | ||
<Typography component="incorrectComponent" href="url" /> | ||
// $ExpectError | ||
<Typography component="div" href="url" /> | ||
// $ExpectError | ||
<Typography href="url" /> | ||
<Typography component={CustomComponent} prop1="1" prop2={12} /> | ||
// $ExpectError | ||
<Typography component={CustomComponent} prop1="1" prop2={12} id="1" /> | ||
// $ExpectError | ||
<Typography component={CustomComponent} prop1="1" /> | ||
// $ExpectError | ||
<Typography component={CustomComponent} prop1="1" prop2="12" /> | ||
</div> | ||
); | ||
}; |
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.
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.
This change makes the export of
TypographyProps
unused, does it not @fyodore82? So code that used to reference andPick
fromTypographyProps
I see is now broken and a mismatch for theTypography
component itself.For example:
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 see this is an updated pattern elsewhere in the code (e.g. Chip, Grid, Link etc), but unsure how the
*Props
exports relate.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.
Pattern I've employed for Typography is used in several other components in Material-UI as you already mentioned. So I've decided not to invent different solution but follow already established mainline.
The
TypographyProps
andTypography
itself are related. Both inherit fromOverrideProps
interface.Typography
does it indirectly, rhruOverridableComponent
andTypographyProps
does it directly.forwardRef
will also work fine if specializeTypographyProps
with correct componentI have also checked how it was before
Typography
change. This code<Typo component="a" href="url" display="block" />
was not valid due to presence ofhref
attribute. And we had no means to make it valid.I may suggest to extend Typography documentation and include samples of how to use component prop in different scenarios
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.
@fyodore82 So was the documentation ever updated? Because now I can't use
FC<TypographyProps>
anymore, which was a bit of a low blow to sneak into a minor release.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.
Did it