Skip to content

Commit

Permalink
fix forwardRef
Browse files Browse the repository at this point in the history
  • Loading branch information
secretlifeof committed Aug 20, 2020
1 parent 3ad6944 commit 537d62e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/base/attachAttrs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import render from '../system/render';
import { forwardRef } from '../system/setup';
import getFilteredProps from './getFilteredProps';

function as(this: any, a: any) {
Expand All @@ -14,7 +15,7 @@ function withComponent(this: any, attrsIn: any, val: any, filter: string[]) {

const { mergedProps } = this;
const WrappedComponent = (props?: any, ref = { current: null }) => {
const refOut = ref && ref.current ? { ref } : {};
const refOut = ref && forwardRef ? { ref } : {};
const styles = typeof val === 'function' ? val(props) : val;
const attrs = typeof attrsIn === 'function' ? attrsIn(props) : attrsIn;
const initValues = this.getInitialValues(props);
Expand All @@ -35,10 +36,18 @@ function withComponent(this: any, attrsIn: any, val: any, filter: string[]) {
});
};

// if used without forwardRef
attachAttrsBound(WrappedComponent, { ...attrsIn, ...mergedProps, ...val });

const Forwarded = forwardRef
? forwardRef(WrappedComponent)
: WrappedComponent;
// if used with forwardRef
attachAttrsBound(Forwarded, { ...mergedProps, ...val });

this.mergedProps = {};

return WrappedComponent;
return forwardRef ? Forwarded : WrappedComponent;
}

function merge(this: any, components: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Base {

const { mergedProps } = this;
const WrappedComponent = (props?: any, ref = { current: null }) => {
const refOut = ref && ref.current ? { ref } : {};
const refOut = ref && forwardRef ? { ref } : {};
const styles = typeof val === 'function' ? val(props) : val;
const initValues = this.getInitialValues(props);
const variantStyles = this.getVariantStyles(props);
Expand Down

1 comment on commit 537d62e

@vercel
Copy link

@vercel vercel bot commented on 537d62e Aug 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.