Skip to content

Commit

Permalink
fix: always forward ref
Browse files Browse the repository at this point in the history
  • Loading branch information
nafees nazik committed Apr 3, 2022
1 parent f02aba6 commit 830874e
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,13 @@ export { VariantProps, ClassProp, VariantsSchema, VariantsConfig, ClassValue }

export type IntrinsicElementsKeys = keyof JSX.IntrinsicElements

type ForwardRefFunction = {
(props: any, ref?: any): any
}

export type VariantOBJ<Variants> =
type VariantOBJ<Variants> =
| (Variants extends VariantsSchema
? VariantsConfig<Variants> & ClassProp
: ClassProp)
| undefined

export function styled<T extends IntrinsicElementsKeys>(
Tag: T,
forwardRef?: ForwardRefFunction,
) {
export function styled<T extends IntrinsicElementsKeys>(Tag: T) {
return function wrapper<Variants extends VariantsSchema>(
base?: ClassValue,
config?:
Expand Down Expand Up @@ -70,7 +63,7 @@ export function styled<T extends IntrinsicElementsKeys>(
_props.className = cx(classes(), props.className)
}

if (forwardRef) {
if (ref) {
_props.ref = ref
}

Expand All @@ -79,6 +72,6 @@ export function styled<T extends IntrinsicElementsKeys>(
return React.createElement(_as, _props)
}

return forwardRef ? forwardRef(StyledWrapper) : StyledWrapper
return React.forwardRef(StyledWrapper)
}
}

0 comments on commit 830874e

Please sign in to comment.