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

[RFC][Joy UI] Remove TextField in favor of composition #34176

Closed
siriwatknp opened this issue Sep 2, 2022 · 10 comments · Fixed by #35462
Closed

[RFC][Joy UI] Remove TextField in favor of composition #34176

siriwatknp opened this issue Sep 2, 2022 · 10 comments · Fixed by #35462
Labels
component: text field This is the name of the generic UI component, not the React module! package: joy-ui Specific to @mui/joy RFC Request For Comments waiting for 👍 Waiting for upvotes

Comments

@siriwatknp
Copy link
Member

siriwatknp commented Sep 2, 2022

Problems

The TextField is a wrapper of FormLabel, Input, and FormHelperText. It binds the id with ARIA to those components which reduce a lot of effort for developers.

However, it becomes a pain when you need to pass props to the inner HTML input:

Hard to customize

To pass a prop to the HTML input, you have to do this:

<TextField
  componentsProps={{
    input: {
      componentsProps: {
        data-attributes: '',
      }
    }
  }}
/>

Confusion

Take Material UI as an example, Joy UI would follow the same regardless of the final APIs for the TextField.

here is some confusion from the community about the API of the TextField:

Proposal

Remove the TextField component and lean toward composition similar to Chakra UI.

<FormControl>
  <FormLabel>...</FormLabel>
  <Input /> {/* This could be Textarea, Select, Autocomplete */}
  <FormHelperText>...</FormHelperText>
</FormControl>

I think the removal of the TextField will clean up the confusion and hand over the customization to developers which sounds like a good strategy for us (as a maintainer).

Advantages

  • I believe that it will reduce the issues related to the props injection for Joy UI.
  • Low learning curve because it is one-to-one DOM mapping.
  • It is easier to customize both styling and passing props.
  • Don't need to spend time thinking about the API that the TextField should have (currently, the componentsProps does not work)
  • The pattern can be used with Textarea, Select, and Autocomplete without creating new field components.

Disadvantages

  • More character to type (I don't think this is a big deal because Chakra UI has positive feedback)
  • Different experience compare to Material UI (does it matter that much? Material UI also provide FormControl for composition as well)
@siriwatknp siriwatknp added component: text field This is the name of the generic UI component, not the React module! package: joy-ui Specific to @mui/joy RFC Request For Comments labels Sep 2, 2022
@siriwatknp siriwatknp changed the title [RFC][Joy UI] Replace TextField with composition [RFC][Joy UI] Remove TextField in favor of composition Sep 2, 2022
@kabernardes
Copy link
Contributor

Hi, can I try this one?!

@siriwatknp
Copy link
Member Author

Hi, can I try this one?!

Thanks for asking but I think we will have to wait for the decision first.

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 29, 2022

I think that this could work as long as the abstractions terminology/structure is compatible with Material UI's one.

At a high level, I would be amazed if we don't get a lot of people asking us to create a Text Field abstraction on top of the lower-level primitives once we remove it, but who knows? It might actually be interesting to experiment.

In v1, I tried to promote the composable API https://v1.mui.com/demos/text-fields/#components but move the h2 lower in the page in the following major versions when I saw the Google Analytics demos use stats on this page 😁.

@WilliamKelley
Copy link

[TextField] binds the id with ARIA to those components which reduce a lot of effort for developers.

This is the most important aspect of the solution for me. If the alternative can do this by default, then I'd be satisfied.

@siriwatknp
Copy link
Member Author

[TextField] binds the id with ARIA to those components which reduce a lot of effort for developers.

This is the most important aspect of the solution for me. If the alternative can do this by default, then I'd be satisfied.

Yes, it works the same.

The only downside is that you have to write more code (3 components) instead of 1, the TextField.

@WilliamKelley
Copy link

[TextField] binds the id with ARIA to those components which reduce a lot of effort for developers.

This is the most important aspect of the solution for me. If the alternative can do this by default, then I'd be satisfied.

Yes, it works the same.

Great! I can add that I think this would be received well by my company engineering team. Those who are very comfortable would grunt at the loss of a succinct component, but I've fielded so many questions and misunderstandings about TextField and TextField vs FormLabel, Input, etc. that it would have been well worth it to everyone to never have dealt with the abstraction in the first place.

One more thing I'd like to suggest is making Form*** components warn in the console if they can't find a FormControl context. My aim is to have a safety net to avoid using them in an inaccessible manner. I can't think of a good reason to use outside of a FormControl.

@siriwatknp
Copy link
Member Author

From #34994, using Input directly instead of the TextField let me focus on the composition to create a horizontal text field without banging my head with the TextField customization.

Screen Shot 2565-11-03 at 15 31 53

@oliviertassinari
Copy link
Member

Related to this discussion https://twitter.com/BrettThurs10/status/1591118613318369281

@hbjORbj
Copy link
Member

hbjORbj commented Dec 13, 2022

Jun, as we discussed, I made a draft PR for this issue. Feel free to skim through.

Since Joy doesn't have API docs yet, should we at least have a documentation for Joy FormControl so that developers can figure out how to create a user input?

@Dooblr
Copy link

Dooblr commented Aug 25, 2023

Is TextField still being removed? It remains in the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! package: joy-ui Specific to @mui/joy RFC Request For Comments waiting for 👍 Waiting for upvotes
Projects
None yet
6 participants