Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support react ref for certain inputs #261

Open
liywjl opened this issue Dec 14, 2020 · 3 comments
Open

Support react ref for certain inputs #261

liywjl opened this issue Dec 14, 2020 · 3 comments

Comments

@liywjl
Copy link

liywjl commented Dec 14, 2020

Is your feature request related to a problem? Please describe.
When implementing certain accessiblity features, we sometimes need to refer to a specific DOM element (example an input in a form).

The common way to do this in React is to use ref (ex: <div ref={someRef} />). Currently in Source we do not have a way to support refs, as they cannot be spread like other props.

Instead other UI libs have used forwardRef as a way of passing down refs.

Describe the solution you'd like
Support refs for certain input elements by using forwardRef

Describe alternatives you've considered
I currenly have a workaround using query selectors and custom HTML attributes: https://github.com/guardian/dotcom-rendering/blob/main/src/web/components/elements/CalloutBlockComponent.tsx#L195

@SiAdcock
Copy link
Contributor

Thanks @liywjl . I originally raised this as guardian/source#294 after we discussed this back in March. I got bogged down in TypeScript problems trying to support this and since you found a workaround, I put it down. Happy to look into it again if it would still be useful. It will be a breaking change so we can add it to the v4.0.0 roadmap.

When you say "support ref for certain inputs", do you think it would be better for some components to support ref but for others not to support it?

@ob6160
Copy link
Contributor

ob6160 commented Oct 26, 2021

This just came up in guardian/source#1106, turns out I can use Synthetic Events here, but I definitely missed the ability to forward refs. Discussion resulted in @SiAdcock suggesting we look into whether this would be a breaking change.

In terms of planning this, should we make a list of components where we think a ref forward would be useful?
....
Or I'm wondering if it's even worth trying to pre-empt usage and add them all at once / on demand

@tjmw
Copy link
Member

tjmw commented Mar 7, 2022

Hi @SiAdcock 👋 I was just wondering what the current state/thinking around supporting forward refs in source components was? We've got a use case where we'd like to programatically focus an instance of source's Button component (to support one of the recommendations we've been given around banner accessibility).

@sndrs sndrs transferred this issue from guardian/source Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants