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

TypeScript error prevents assigning a ref to MarkdownEditor #228

Open
phil-coris opened this issue Sep 13, 2024 · 1 comment
Open

TypeScript error prevents assigning a ref to MarkdownEditor #228

phil-coris opened this issue Sep 13, 2024 · 1 comment

Comments

@phil-coris
Copy link

I'm trying to solve an issue where tabbing from a vanilla text input to MarkdownEditor does not focus the MarkdownEditor. I was going to attempt getting around this by listening for a tab button press on the first input and then manually focusing the MarkdownEditor. However, I can't assign a ref.

const $ref = useRef(null);

...

	<MarkdownEditor
		ref={$ref}
		value={noteContent}
		height="400px"
		onFocus={() => {
			console.log('focus');
		}}
		toolbarsFilter={(tool) => {
			// @ts-ignore
			const toolName = tool?.name as string;
			return !['code', 'codeBlock'].includes(toolName);
		}}
		onChange={(value, viewUpdate) => {
			console.log(value);
			setNoteContent(value);
		}}
	/>

This causes the following error:

TS2322: Type '{ ref: MutableRefObject<any>; value: string; height: string; onFocus: () => void; toolbarsFilter: (tool: Commands) => boolean; onChange: (value: string, viewUpdate: ViewUpdate) => void; }' is not assignable to type 'IntrinsicAttributes & IMarkdownEditor'.
  Property 'ref' does not exist on type 'IntrinsicAttributes & IMarkdownEditor'.
    213 |                                                       {/* @ts-ignore */}
    214 |                                                       <MarkdownEditor
  > 215 |                                                               ref={$ref}
        |                                                               ^^^
    216 |                                                               value={noteContent}
    217 |                                                               height="400px"
    218 |                                                               onFocus={() => {
@jaywcjlove
Copy link
Member

@phil-coris

import { MarkdownEditorRef } from '@uiw/react-markdown-editor';
const $ref = useRef<MarkdownEditorRef>(null);

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