withspectrum/draft-js-markdown-plugin

Documentation for renderLanguageSelect is inaccurate

dino115 opened this issue · 0 comments

Hi,
the documentation for a custom renderLanguageSelect describes the onChange method with a parameter for selectedValue.

onChange: (selectedValue: string) => void,

But as you can see in the code component, the onChange method requires an event handler. It calls preventDefault, stopPropagation and access the value through ev.currentTarget.value (line 44).

I have worked around this by calling onChange with a fake event with noops for the two methods and the newly selectedValue nested in currentTarget.value. So for now it is not a big problem, and maybe it helps other people to implement an own language selector which doesn't depends on a select input.

createChangeLanguageHandler: ({ onChange }) => newValue => {
  // call onChange with a fake event
  onChange({
    preventDefault: () => {},
    stopPropagation: () => {},
    currentTarget: { value: newValue },
  });
}

Please update the documentation or improve the onChange handler to work as described.

Keep up your good work! Cheers 🍻️