react-md-editor icon indicating copy to clipboard operation
react-md-editor copied to clipboard

How can i set textarea(.w-md-editor-text-input)'s parent <div> height style?

Open imkdw opened this issue 1 year ago • 7 comments

import t\MDEditor from '@uiw/react-md-editor';

interface Props {
  content: string;
  changeHandler: (content: string) => void;
}

export default function ArticleContentEditor({ content, changeHandler }: Props) {
  const changeContentHandler = (value: string | undefined) => {
    if (value) {
      changeHandler(value);
    }
  };

  return (
    <MDEditor
      value={content}
      height="500px"
      onChange={(changedContent) => changeContentHandler(changedContent)}
      highlightEnable={false}
    />
  );
}

This is my code, when i set height="500px" on MDEditor Component But not working on textarea, textarea is so small

image image

Need to set more properties of MDEditor?

imkdw avatar Mar 20 '24 15:03 imkdw

@imkdw I can't reproduce your issue. Can you provide an example to help me investigate?

jaywcjlove avatar Mar 23 '24 09:03 jaywcjlove

@jaywcjlove

Thank you for your response But I can't find what's wrong.. so I set css height: 100% on class of w-md-editor-text It doesn't feel right, but it's resolved, so I think I should use it like this

.w-md-editor-text {
  height: 100%;
}

image

imkdw avatar Mar 23 '24 14:03 imkdw

I have the same issue exactly.

image

jongyoul avatar May 03 '24 15:05 jongyoul

It looks related to https://github.com/uiwjs/react-md-editor/commit/a7d9a2c266200579e083f70b63effafd08c328d3

jongyoul avatar May 03 '24 16:05 jongyoul

Hi found a temp fix referencing comments form @imkdw and @jongyoul, we can use: .w-md-editor-text { min-height: 100% !important; }

you can try height: 100% as well but for me it breaks cursor placement

jazztester avatar Jul 10 '24 06:07 jazztester

Not working for me

                      <MDEditor
                          height='100%'
                          value={values.code}
                          onChange={(value) => setFieldValue('code', value)}
                          onBlur={handleBlur}
                          preview='edit'
                          className={classNames(
                            'ui-min-h-40 ui-w-full ui-overflow-auto ui-rounded-xl ui-leading-6 ui-text-justify ui-px-2 ui-text-base placeholder:ui-text-gray-700 ui-items-stretch',
                            {
                              'ui-border-gray-300 ': !hasError(errors.code),
                              'ui-border-red-300 ': hasError(errors.code),
                            }
                          )}
                          hideToolbar
                          textareaProps={{
                            name: 'code',
                          }}
                        />

image

buzzracharyeah avatar Aug 31 '24 21:08 buzzracharyeah

import MDEditor from '@uiw/react-md-editor';
import { useState, useRef, useEffect } from 'react';

import styles from './index.module.scss';

interface MarkDownEditorProps {
  height?: string;
  placeholder?: string;
}

const MarkDownEditor: React.FC<MarkDownEditorProps> = ({
  height,
  placeholder,
}) => {
  const [value, setValue] = useState<string>('');
  const editorRef = useRef<HTMLDivElement | null>(null); 

  useEffect(() => {
    if (editorRef.current) {
      const editorElement =
        editorRef.current.querySelector('.w-md-editor-text');
      if (editorElement) {
        editorElement.setAttribute(
          'style',
          'background-color:rgb(255, 255, 255);'
        );
      }
    }
  }, []);

  return (
    <div className={styles.container} data-color-mode="light" ref={editorRef}>
      <MDEditor
        height={height}
        value={value}
        preview="edit"
        previewOptions={{
          className: styles.customPreview,
        }}
        visibleDragbar={false}
        textareaProps={{
          placeholder: placeholder,
        }}
      />
    </div>
  );
};

export default MarkDownEditor;

@buzzracharyeah This solved the problem without css. Please refer to it

SeungJin051 avatar Jan 25 '25 13:01 SeungJin051