uiwjs / react-codemirror

CodeMirror 6 component for React. @codemirror https://uiwjs.github.io/react-codemirror/
https://uiwjs.github.io/react-codemirror/
MIT License
1.65k stars 132 forks source link

onFocusChange is there a replacement? #555

Closed marabesi closed 1 year ago

marabesi commented 1 year ago

reac-codemirror has the event onFocusChange that I used to use in my project like so:

<div className={`editor ${className} `}>
  <CodeMirror
    value={this.props.value}
    options={codeMirrorOptions}
    className="editor"
    onChange={this.props.codeChanged}
    onFocusChange={this.onFocus}
  />
</div>

This is what it does: onFocusChange Function (focused) called when the editor is focused or loses focus.

But I couldn't find a equivalent to use for @uiw/react-codemirror, is there a workaround for this one?

jaywcjlove commented 1 year ago

@marabesi https://uiwjs.github.io/react-codemirror/#/extensions/events

import * as events from '@uiw/codemirror-extensions-events';

const extension = events.content({
  focus: (evn) => {
    console.log('focus');
  },
  blur: (evn) => {
    console.log('blur');
  },
});

<CodeMirror value="console.log('hello world!');" height="200px" extensions={[extension]} />
marabesi commented 1 year ago

checked with extensions and it worked!

Thanks!