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

[FormControl] Integrate FormControl with input components #17

Open
7 tasks
mj12albert opened this issue Mar 23, 2023 · 1 comment
Open
7 tasks

[FormControl] Integrate FormControl with input components #17

mj12albert opened this issue Mar 23, 2023 · 1 comment
Assignees
Labels
component: form This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature

Comments

@mj12albert
Copy link
Member

mj12albert commented Mar 23, 2023

Motivation

To be able to easily compose different kinds of (higher level) form fields with consistent interaction states using Base components/hooks,

Currently, only the Input component is supported (doc).

<FormControlUnstyled defaultValue="" required>
  <Label>Name</Label>
  <Input />
  <HelperText />
</FormControlUnstyled>

But that <Input /> could just as well be an Autocomplete or a Switch.

Requirements

1. Consistent interface for getting a value from any form component

  • Currently FormControl accepts an onChange prop that gets an event as the sole argument
  • This works for getting the value from a basic Input using event.target.value, but doesn't work for cases like multi-select or Autocomplete with multiple options
  • It could updated to provide the latest value as a second argument like: onChange: (event: React.SyntheticEvent, newValue: any) => void

Some components already have this second argument:

  • useAutocomplete: onChange?: (event: React.SyntheticEvent, value: AutocompleteValue<T, Multiple, DisableClearable, FreeSolo>, reason: AutocompleteChangeReason, details?: AutocompleteChangeDetails<T>) => void
  • useSlider: onChange?: (event: Event, value: number | number[], activeThumb: number) => void
  • useSelect: onChange?: ( event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, value: SelectValue<OptionValue, Multiple>, ) => void
  • useNumberInput

2. Additional metadata

Some components call onChange with "metadata" arguments:

  • Autocomplete: reason, details
  • Slider: activeThumb

Perhaps a general metadata object can be used as the third argument, e.g. onChange: (event, newValue, metadata).

Components

@mj12albert mj12albert self-assigned this Mar 23, 2023
@mj12albert mj12albert changed the title [base] Integrate FormControlUnstyled / useFormControlUnstyledContext with all “input” type components [base] Integrate FormControl with input components Apr 28, 2023
@mj12albert
Copy link
Member Author

mj12albert commented May 24, 2023

I made a sandbox that integrates a react-hook-form based form with all of Base's form components as a reference: https://codesandbox.io/s/baseui-react-hook-form-8s6ptc?file=/src/App.tsx

@mj12albert mj12albert changed the title [base] Integrate FormControl with input components [base-ui][Formcontrol] Integrate FormControl with input components Aug 16, 2023
@mj12albert mj12albert changed the title [base-ui][Formcontrol] Integrate FormControl with input components [base-ui][FormControl] Integrate FormControl with input components Aug 16, 2023
@michaldudak michaldudak transferred this issue from mui/material-ui Feb 27, 2024
@michaldudak michaldudak changed the title [base-ui][FormControl] Integrate FormControl with input components [FormControl] Integrate FormControl with input components Feb 27, 2024
@michaldudak michaldudak added enhancement This is not a bug, nor a new feature component: form This is the name of the generic UI component, not the React module! labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: form This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature
Projects
Status: Backlog
Development

No branches or pull requests

2 participants