Skip to content
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

[core] Fix innerRef being considered injected with certain HOCs #14333

Merged
merged 2 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/material-ui/src/styles/withStyles.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export type WithStyles<
? K
: never
>;
innerRef?: React.Ref<any> | React.RefObject<any>;
};

export interface StyledComponentProps<ClassKey extends string = string> {
Expand Down
5 changes: 4 additions & 1 deletion packages/material-ui/src/styles/withTheme.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { PropInjector } from '..';

export interface WithTheme {
theme: Theme;
}

export interface ThemedComponentProps extends Partial<WithTheme> {
innerRef?: React.Ref<any> | React.RefObject<any>;
}

export default function withTheme(): PropInjector<WithTheme, Partial<WithTheme>>;
export default function withTheme(): PropInjector<WithTheme, ThemedComponentProps>;
5 changes: 4 additions & 1 deletion packages/material-ui/src/withWidth/withWidth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export interface WithWidthOptions {

export interface WithWidth {
width: Breakpoint;
}

export interface WithWidthProps extends Partial<WithWidth> {
innerRef?: React.Ref<any> | React.RefObject<any>;
}

Expand All @@ -27,4 +30,4 @@ export function isWidthUp(

export default function withWidth(
options?: WithWidthOptions,
): PropInjector<WithWidth, Partial<WithWidth>>;
): PropInjector<WithWidth, WithWidthProps>;
5 changes: 5 additions & 0 deletions packages/material-ui/test/typescript/styles.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ declare const themed: boolean;
// Test that withTheme: true guarantees the presence of the theme
const Foo = withStyles({}, { withTheme: true })(
class extends React.Component<WithTheme> {
hasRef() {
// innerRef does not exists, originally caused https://github.com/mui-org/material-ui/issues/14095
return Boolean(this.props.innerRef); // $ExpectError
}

render() {
return <div style={{ margin: this.props.theme.spacing.unit }} />;
}
Expand Down