Skip to content

Commit

Permalink
add forwardRef
Browse files Browse the repository at this point in the history
  • Loading branch information
hennessyevan committed Jul 9, 2019
1 parent 5c7e368 commit c53e620
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/box.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ClassNames, CSSObject } from "@emotion/core";
import facepaint from "facepaint";
import * as CSS from "csstype";
import React, { ReactNode, useContext } from "react";
import React, { ReactNode, useContext, forwardRef, Ref } from "react";
import expandAliases from "./expandAliases";
import splitCSSProps from "./splitCSSProps";
import { MediaQueryContext } from "./mqcontext";
Expand All @@ -16,7 +16,7 @@ export interface BoxProps extends CSS.StandardPropertiesFallback<number | string
[key: string]: any;
}

const Box = ({ is = "div", className, innerRef, css, props = {}, style, children, ...rest }: BoxProps) => {
const Box = forwardRef(({ is = "div", className, innerRef, css, props = {}, style, children, ...rest }: BoxProps, ref: Ref<any>) => {
const mqContext = useContext(MediaQueryContext);
const mq = facepaint(mqContext);

Expand All @@ -35,6 +35,7 @@ const Box = ({ is = "div", className, innerRef, css, props = {}, style, children
{
className: cx([ecss(mq([css, matched])), className]),
style,
ref,
...remaining,
...props
},
Expand All @@ -43,7 +44,7 @@ const Box = ({ is = "div", className, innerRef, css, props = {}, style, children
}
</ClassNames>
);
};
});

Box.defaultProps = {
boxSizing: "border-box"
Expand Down
2 changes: 1 addition & 1 deletion src/expandAliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function expandAliases(props: BoxProps, css: any = {}): [BoxProps
css["::before, ::after"] = {
display: "table",
clear: "both",
content: ""
content: "''"
};
delete props.clearfix;
}
Expand Down

0 comments on commit c53e620

Please sign in to comment.