Skip to content

Commit

Permalink
[core] Fix innerRef being considered injected with certain HOCs (#14333)
Browse files Browse the repository at this point in the history
Closes #14095

* [core] Add failing ts test

innerRef is not injected but intercepted

* [core] Fix innerRef being considered injected instead of intercepted
  • Loading branch information
eps1lon authored Jan 30, 2019
1 parent 138aef1 commit 4507944
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
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

0 comments on commit 4507944

Please sign in to comment.