StaticMania / keep-react

Keep React is an open-source component library built on Tailwind CSS and React.js. It provides a versatile set of pre-designed UI components to build modern web applications.
https://react.keepdesign.io
MIT License
1.32k stars 115 forks source link

Use with Formik #40

Closed rymkapro closed 6 months ago

rymkapro commented 10 months ago

Can't use with Formik "from the box"

rymkapro commented 10 months ago

I've created a wrapper component, something like this

const FormikInput = (props: IFormikInput) => {
  const { label, form, field, keepreact } = props
  const is_error = form.touched[field.name] && form.errors[field.name]

  return (
    <>
      {label && <Label value={label} color={is_error ? 'error' : keepreact.color} />}

      <TextInput
        {...field}
        {...keepreact}
        handleOnChange={field.onChange}
        color={is_error ? 'error' : keepreact.color}
      />

      {is_error && (
        <div className={classNames('text-rose-600 text-xs mt-0.5')}>
          <ErrorMessage name={field.name} />
        </div>
      )}
    </>
  )
}

And I can't use {...field} props because they are not fully passed, as i understood (may be i'm wrong)


Also reseting input value is not working (even without formik) Can be reproduced

const App = () => {
  const [value, setValue] = useState<string>('')

  return (
    <div className="wrapper relative">
      <TextInput value={value} handleOnChange={(e) => setValue(e.target.value)} />
      <Button size="sm" onClick={() => setValue('')}>
        Reset value
      </Button>
    </div>
  )
}

export default App

Pressing "Reset value" button will not reset field value

darkweb19 commented 10 months ago

On which dir is this code written or which branch ?

rymkapro commented 10 months ago

That's just an example of my code, how i tried to use keep-react input with formik Field