Skip to content

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

@siriwatknp

Description

@siriwatknp

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRequest For Comments.package: joy-uiSpecific to Joy UI.scope: text fieldChanges related to the text field.waiting for 👍Waiting for upvotes. Open for community feedback and needs more interest to be worked on.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions