prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
154 stars 40 forks source link

React.forwardRef on <PrismicLink> #128

Closed asyarb closed 2 years ago

asyarb commented 2 years ago

Is your feature request related to a problem? Please describe.

A ref that is assigned to a <PrismicLink> component never forwards it to the underlying <a /> or internal link component.

Describe the solution you'd like

The ref should be forwarded to the externalLinkComponent or internalLinkComponent respectively.

const Example = () => {
    // ref.current is always `null` currently, but should be a HTMLAnchorElement
    const ref = React.useRef<HTMLAnchorElement>(null)

    return <PrismicLink ref={ref} href="/" />
}

Describe alternatives you've considered

N/A

Additional context

N/A

If there is any additional information that I can provide to help with this, please let me know!

angeloashmore commented 2 years ago

Thanks! This is fixed in v2.1.1.

<PrismicLink> now forwards refs like other components. If a custom React component is provided to internalComponent or externalComponent, the component must also forward its ref.

More details can be found in the PR: #131