Skip to content

Make control state available outside Field.Root #3078

@KenanYusuf

Description

@KenanYusuf

Feature request

Summary

I would like to access the state object from the render prop of components like Input and Select without needing to wrap the control in Field.Root.

Currently, state is available in the render function:

<Input
  render={(props, state) => {
    <>
      <SearchIcon fill={state.focused || state.filled ? 'gray' : 'black'} />
      <input {...props} />
      {state.filled && <ClearButton />}
    </>
  )}
/>

…but the values of state (dirty, touched, filled, focused) do not update unless the control is wrapped in Field.Root, as mentioned in the docs for the relevant data attributes. Since these properties describe the control itself, not just the field, it would be convenient if the state were accurate at the control level.

Motivation

I want to implement UI behaviour based on the control's state without introducing a Field.Root wrapper for every individual control.

Example: https://codesandbox.io/p/sandbox/control-state-llh87m

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: enhancementIt’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions