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

HTML Textbox input in preview #598

Closed
SundaramMaheshkumar opened this issue Nov 27, 2023 · 5 comments
Closed

HTML Textbox input in preview #598

SundaramMaheshkumar opened this issue Nov 27, 2023 · 5 comments

Comments

@SundaramMaheshkumar
Copy link

NOT a bug. Could I please get clarification on how to achieve the below in the markdown preview.

In the Checklist section -> For the column Comments & in the section Other Comments, I made a textbox using html which gets displayed in the preview with HTML input box (Not visible here due to sanitization I suppose).

But I can't input anything in that box. How to make those displayed textboxes to allow inputs in the preview, instead of editing the markdown itself. Is this achievable?

My Markdown:

Plan Checklist

Demographics

Key Value
Name Tom
ID 78147831

Automated Technical Check

Key Value Another column
Name Daniel
Operator Name Laura
Beam ID 234jtr2mtr42

Checklist

Item Planner Checker Comments
Distribution
Scorecard

Other Comments

Any help would be appreciated! Thanks.

@jaywcjlove
Copy link
Member

@SundaramMaheshkumar
Copy link
Author

SundaramMaheshkumar commented Nov 27, 2023

@jaywcjlove

Thank you. I tried to look into rehype plugins but couldn't figure out how to achieve my use case. Currently, I cannot type or change the value inside that HTML input box in preview. What I want is to allow free typing in those input boxes!

Sorry. Could you please guide me with an example? Thank you so much.

@jaywcjlove
Copy link
Member

@SundaramMaheshkumar
Copy link
Author

Thank you so much @jaywcjlove. That's exactly what I needed.

@jaywcjlove
Copy link
Member

https://codesandbox.io/p/sandbox/markdown-editor-for-react-598-q2mtp4?file=%2Findex.js%3A1%2C1-42%2C1

import React, { useEffect } from "react";
import ReactDOM from "react-dom";
import MDEditor, { selectWord } from "@uiw/react-md-editor";
// No import is required in the WebPack.
// import "@uiw/react-md-editor/dist/markdown-editor.css";

const mkdStr = `
# Markdown Editor

<input type="text" />

`;

function App() {
  const [value, setValue] = React.useState(mkdStr);
  return (
    <div className="container">
      <MDEditor
        height={200}
        value={value}
        previewOptions={{
          components: {
            input: (props) => {
              return (
                <input
                  {...props}
                  onChange={(ev) => {
                    console.log("xx", ev.target.value);
                  }}
                />
              );
            },
          },
        }}
        onChange={setValue}
      />
    </div>
  );
}

ReactDOM.render(<App />, document.getElementById("container"));

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

No branches or pull requests

2 participants