I am trying to build custom rich text editor in react. I have few questions regarding how to handle child html element inside contentEditable div element -
- How to get current focused element (which has cursor currently) inside contentEditable element
- get
previous siblingto that element.
below is html, something which I want to get inside editable section_content :
<div className={css.section_content} contentEditable={true} onChange={handleChange} onKeyDown={handleKeyDown} ref={contentRef}>
<h3 className={`${css['h4']} ${css['h3--leading']}`}> Title </h3>
<p className={`${css['p']} ${css['after--h4']} ${css['is-selected']}`}>
paragraph1
</p>
<p className={`${css['p']} ${css['after--p']} ${css['p-trailing']}`}>
paragraph2
</p>
</div>