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

feat(conform-react)!: allow customizing shadow input with props #19

Merged
merged 1 commit into from
Aug 21, 2022

Conversation

edmundhung
Copy link
Owner

@edmundhung edmundhung commented Aug 21, 2022

Context

This PR includes breaking changes

This makes useControlledInput returning the props to be applied on the input element instead of giving you an element directly, which gives users control over the shadow input in case of customization

Example:

import { useFieldset, useControlledInput } from '@conform-to/react';
import { Select, MenuItem } from '@mui/material';

function MuiForm() {
  const [fieldsetProps, { category }] = useFieldset(schema);
  const [inputProps, control] = useControlledInput(category);

  return (
    <fieldset {...fieldsetProps}>
      {/* Render a shadow input somewhere */}
      <input {...inputProps} />

      {/* MUI Select is a controlled component */}
      <Select
        label="Category"
        value={control.value}
        onChange={control.onChange}
        onBlur={control.onBlur}
        inputProps={{
          onInvalid: control.onInvalid
        }}
      >
        <MenuItem value="">Please select</MenuItem>
        <MenuItem value="a">Category A</MenuItem>
        <MenuItem value="b">Category B</MenuItem>
        <MenuItem value="c">Category C</MenuItem>
      </TextField>
    </fieldset>
  )
}

@edmundhung edmundhung merged commit d5712f0 into main Aug 21, 2022
@edmundhung edmundhung deleted the refine-use-controlled-input branch August 21, 2022 09:10
@edmundhung edmundhung mentioned this pull request Aug 26, 2022
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant