uiwjs / react-md-editor

A simple markdown editor with preview, implemented with React.js and TypeScript.
https://uiwjs.github.io/react-md-editor
MIT License
2.17k stars 156 forks source link

Support name property #286

Closed simoneb closed 2 years ago

simoneb commented 2 years ago

To make this component behave more like a native input element, it should support the name attribute. It would make it easier to integrate with form libraries like formik.

jaywcjlove commented 2 years ago
<MDEditor
  value={value}
  textareaProps={{
    name: 'field'
  }}
  onChange={setValue}
/>

@simoneb

<MDEditor
  value={value}
+  textareaProps={{
+    name: 'field'
+  }}
  onChange={setValue}
/>
allforabit commented 2 years ago

Having played around with this I think more changes would be needed to make it work directly with formik. The onChange callback would need to take a html form event and I'm not sure how feasible this is?

allforabit commented 2 years ago

Is there a reason that onChange is excluded from textareaProps? https://github.com/uiwjs/react-md-editor/blob/4b7cc43437585c3843c0cef0d2b4d2d7a39f17fc/src/components/TextArea/index.tsx#L27 There's no transformation of the text so it seems like it'd make sense to make it available?

jaywcjlove commented 2 years ago

@allforabit I don't know the rules of formik.

allforabit commented 2 years ago

Of course @jaywcjlove the request is really to see if the component can be made to act closer to a native component. For instance material ui allows you to use the name property and it passes the underlying text area event to onChange handler. It wouldn't just benefit Formik users and would just mean the component would be more standard. I can work on a PR for it if it's of interest?

jaywcjlove commented 2 years ago

We provide an onChange. Welcome to submit PR compatible Formik.

@allforabit

jaywcjlove commented 2 years ago

@allforabit Upgrade @uiw/react-md-editor@3.7.0

simoneb commented 2 years ago

Thanks @jaywcjlove @allforabit !