material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[RFC][Joy UI] Remove `TextField` in favor of composition

Open siriwatknp opened this issue 3 years ago • 9 comments

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:

  • https://github.com/mui/material-ui/issues/31421
  • https://github.com/mui/material-ui/issues/29525
  • https://github.com/mui/material-ui/issues/11377

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 avatar Sep 02 '22 09:09 siriwatknp

Hi, can I try this one?!

kabernardes avatar Sep 21 '22 12:09 kabernardes

Hi, can I try this one?!

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

siriwatknp avatar Sep 23 '22 03:09 siriwatknp

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 😁.

oliviertassinari avatar Oct 29 '22 17:10 oliviertassinari

[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.

WilliamKelley avatar Nov 01 '22 14:11 WilliamKelley

[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.

siriwatknp avatar Nov 02 '22 08:11 siriwatknp

[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.

WilliamKelley avatar Nov 02 '22 14:11 WilliamKelley

From https://github.com/mui/material-ui/pull/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

siriwatknp avatar Nov 03 '22 08:11 siriwatknp

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

oliviertassinari avatar Nov 11 '22 17:11 oliviertassinari

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?

hbjORbj avatar Dec 13 '22 22:12 hbjORbj

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

Dooblr avatar Aug 25 '23 23:08 Dooblr