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

[joy-ui] How to access the ref of the <input>? #39187

Closed
Eytan3000 opened this issue Sep 27, 2023 · 14 comments · Fixed by #39615
Closed

[joy-ui] How to access the ref of the <input>? #39187

Eytan3000 opened this issue Sep 27, 2023 · 14 comments · Fixed by #39615
Assignees
Labels
component: input This is the name of the generic UI component, not the React module! component: TextareaAutosize The React component. docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process. package: joy-ui Specific to @mui/joy support: question Community support but can be turned into an improvement

Comments

@Eytan3000
Copy link

Eytan3000 commented Sep 27, 2023

I was wondering how to use useRef with Joy UI Input or Textarea components.
I know that in Material UI it’s inputRef but I can’t make this work in Joy UI.

I’m currently using onChange with useState, but I’d like to avoid re-rendering for each type. Thanks, Eytan

@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 27, 2023
@danilo-leal danilo-leal changed the title How to use useRef in Joy UI? [joy-ui] How to use useRef? Sep 27, 2023
@danilo-leal danilo-leal added support: question Community support but can be turned into an improvement package: joy-ui Specific to @mui/joy labels Sep 27, 2023
@n0ir1

This comment was marked as resolved.

@Eytan3000

This comment was marked as resolved.

@siriwatknp siriwatknp added docs Improvements or additions to the documentation and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 28, 2023
@siriwatknp
Copy link
Member

siriwatknp commented Sep 28, 2023

Input:

<Input slotProps={{ input: { ref } }} />

Textarea:

<Textarea slotProps={{ input: { ref } }} />

We can add a section in the docs that is specifically about input ref:

diff --git a/docs/data/joy/components/textarea/textarea.md b/docs/data/joy/components/textarea/textarea.md
index 06a8652a80..2c80a6d3a6 100644
--- a/docs/data/joy/components/textarea/textarea.md
+++ b/docs/data/joy/components/textarea/textarea.md
@@ -115,6 +115,8 @@ It's usually more common to see textarea components using decorators at the top
 
 {{"demo": "TextareaDecorators.js"}}
 
+### Textarea ref
+
 ## Accessibility
 
 In order for the textarea to be accessible, **it should be linked to a label**.

@siriwatknp siriwatknp added component: TextareaAutosize The React component. component: input This is the name of the generic UI component, not the React module! labels Sep 28, 2023
@Eytan3000
Copy link
Author

Thank you!

@siriwatknp
Copy link
Member

Thank you!

Would you like to submit a PR?

@Eytan3000

This comment was marked as resolved.

@siriwatknp

This comment was marked as resolved.

@siriwatknp siriwatknp added the good first issue Great for first contributions. Enable to learn the contribution process. label Oct 2, 2023
@Gurjit11
Copy link

Gurjit11 commented Oct 2, 2023

I would like to contribute to this issue can you assign it to me ? also i am new to open source here i think i need to add demo to the docs how to use Ref right ?

@luv2027

This comment was marked as off-topic.

@Piyush07p

This comment was marked as outdated.

@oliviertassinari oliviertassinari changed the title [joy-ui] How to use useRef? [joy-ui] How to access the ref of the <input>? Oct 8, 2023
@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 8, 2023

I know that in Material UI it’s […]

If we take Material UI, even if we have slot props: https://mui.com/material-ui/api/input/#prop-inputProps inputProps an inputRef prop is https://mui.com/material-ui/api/input/#prop-inputRef provided as well.

I think it opens the question of:

  • What's the pros & cons?
  • Is there a need for Joy UI and Material UI using a different tradeoff?
  • If not, which one is best?

We can add a section in the docs that is specifically about input ref:

@siriwatknp I wonder a bit about the frequency of the need to access the input ref. Is this frequent enough to be worth a dedicated docs? I guess if it was in Material UI for a dedicated prop, it's likely the case, but I wonder if: 1. maybe inputRef was a mistake, it's not frequent enough: 2. if we can't teach this for all components.

@siriwatknp
Copy link
Member

@siriwatknp I wonder a bit about the frequency of the need to access the input ref. Is this frequent enough to be worth a dedicated docs? I guess if it was in Material UI for a dedicated prop, it's likely the case, but I wonder if: 1. maybe inputRef was a mistake, it's not frequent enough: 2. if we can't teach this for all components.

We have the doc about the inner HTML input but we could make it more obvious to inner HTML input and ref?

@vortex73
Copy link

Is this issue still open?

@kavyantic
Copy link

It is a very common use case where we want to use ref with html inputs. That's why it should be given as a singleton root prop in the Input component for better developer experience and avoid deep merge for input props.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: input This is the name of the generic UI component, not the React module! component: TextareaAutosize The React component. docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process. package: joy-ui Specific to @mui/joy support: question Community support but can be turned into an improvement
Projects
None yet
10 participants