react div content editable render value with span
up vote
0
down vote
favorite
I've used div with contentEditable=true in my react component like this:
interface ContentEditableProps {
onChange: (evevt) => void;
onRef: (ref) => void;
html: any;
}
class ContentEditable extends React.Component<ContentEditableProps, {}>{
myRef: HTMLDivElement
lastHtml: string
constructor(props) {
super(props);
this.emitChange = this.emitChange.bind(this);
this.onRef = this.onRef.bind(this)
}
emitChange(event) {
this.props.onChange(event.target.innterText);
}
onRef(ref) {
this.myRef = ref;
this.props.onRef(ref);
}
render() {
return <div
onInput={this.emitChange}
contentEditable={true}
ref={this.onRef}
dangerouslySetInnerHTML={{ __html: this.props.html }}
>
</div >;
}
}
on emitChange I've used the innterText to show in my Parent Component.
interface IndicatorInputState {
html: any
}
class ParentComponent extends React.Component<{}, IndicatorInputState>{
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
this.onRef = this.onRef.bind(this);
this.state = {
html:''
}
}
onChange(value) {
this.setState({html: `<span>${value}</span>`});
}
render() {
return (
<React.Fragment>
<div className="indicator-input">
<ContentEditable onChange={this.onChange} html={this.state.html} onRef={this.onRef} >
</ContentEditable>
</div>
</React.Fragment>
)
}
}
export default ParentComponent
in My parent Component I have a sate(html) and set the html by this value
in this situation I don't have problem but if I use span instead of just using value then my cursor have a freaky behavior and it goes to left of my div
does anybody know how can i set the cursor to right? Provided that whenever the user write any things or delete text with backspace then the cursor must be at right(by the way:i used css for example direction but it isn't use full because backspace doesn't work in right position)
the sample of my code is here:
https://codepen.io/saeedafroozi/pen/WYweeO?editors=1010
please help me
html css reactjs
add a comment |
up vote
0
down vote
favorite
I've used div with contentEditable=true in my react component like this:
interface ContentEditableProps {
onChange: (evevt) => void;
onRef: (ref) => void;
html: any;
}
class ContentEditable extends React.Component<ContentEditableProps, {}>{
myRef: HTMLDivElement
lastHtml: string
constructor(props) {
super(props);
this.emitChange = this.emitChange.bind(this);
this.onRef = this.onRef.bind(this)
}
emitChange(event) {
this.props.onChange(event.target.innterText);
}
onRef(ref) {
this.myRef = ref;
this.props.onRef(ref);
}
render() {
return <div
onInput={this.emitChange}
contentEditable={true}
ref={this.onRef}
dangerouslySetInnerHTML={{ __html: this.props.html }}
>
</div >;
}
}
on emitChange I've used the innterText to show in my Parent Component.
interface IndicatorInputState {
html: any
}
class ParentComponent extends React.Component<{}, IndicatorInputState>{
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
this.onRef = this.onRef.bind(this);
this.state = {
html:''
}
}
onChange(value) {
this.setState({html: `<span>${value}</span>`});
}
render() {
return (
<React.Fragment>
<div className="indicator-input">
<ContentEditable onChange={this.onChange} html={this.state.html} onRef={this.onRef} >
</ContentEditable>
</div>
</React.Fragment>
)
}
}
export default ParentComponent
in My parent Component I have a sate(html) and set the html by this value
in this situation I don't have problem but if I use span instead of just using value then my cursor have a freaky behavior and it goes to left of my div
does anybody know how can i set the cursor to right? Provided that whenever the user write any things or delete text with backspace then the cursor must be at right(by the way:i used css for example direction but it isn't use full because backspace doesn't work in right position)
the sample of my code is here:
https://codepen.io/saeedafroozi/pen/WYweeO?editors=1010
please help me
html css reactjs
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've used div with contentEditable=true in my react component like this:
interface ContentEditableProps {
onChange: (evevt) => void;
onRef: (ref) => void;
html: any;
}
class ContentEditable extends React.Component<ContentEditableProps, {}>{
myRef: HTMLDivElement
lastHtml: string
constructor(props) {
super(props);
this.emitChange = this.emitChange.bind(this);
this.onRef = this.onRef.bind(this)
}
emitChange(event) {
this.props.onChange(event.target.innterText);
}
onRef(ref) {
this.myRef = ref;
this.props.onRef(ref);
}
render() {
return <div
onInput={this.emitChange}
contentEditable={true}
ref={this.onRef}
dangerouslySetInnerHTML={{ __html: this.props.html }}
>
</div >;
}
}
on emitChange I've used the innterText to show in my Parent Component.
interface IndicatorInputState {
html: any
}
class ParentComponent extends React.Component<{}, IndicatorInputState>{
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
this.onRef = this.onRef.bind(this);
this.state = {
html:''
}
}
onChange(value) {
this.setState({html: `<span>${value}</span>`});
}
render() {
return (
<React.Fragment>
<div className="indicator-input">
<ContentEditable onChange={this.onChange} html={this.state.html} onRef={this.onRef} >
</ContentEditable>
</div>
</React.Fragment>
)
}
}
export default ParentComponent
in My parent Component I have a sate(html) and set the html by this value
in this situation I don't have problem but if I use span instead of just using value then my cursor have a freaky behavior and it goes to left of my div
does anybody know how can i set the cursor to right? Provided that whenever the user write any things or delete text with backspace then the cursor must be at right(by the way:i used css for example direction but it isn't use full because backspace doesn't work in right position)
the sample of my code is here:
https://codepen.io/saeedafroozi/pen/WYweeO?editors=1010
please help me
html css reactjs
I've used div with contentEditable=true in my react component like this:
interface ContentEditableProps {
onChange: (evevt) => void;
onRef: (ref) => void;
html: any;
}
class ContentEditable extends React.Component<ContentEditableProps, {}>{
myRef: HTMLDivElement
lastHtml: string
constructor(props) {
super(props);
this.emitChange = this.emitChange.bind(this);
this.onRef = this.onRef.bind(this)
}
emitChange(event) {
this.props.onChange(event.target.innterText);
}
onRef(ref) {
this.myRef = ref;
this.props.onRef(ref);
}
render() {
return <div
onInput={this.emitChange}
contentEditable={true}
ref={this.onRef}
dangerouslySetInnerHTML={{ __html: this.props.html }}
>
</div >;
}
}
on emitChange I've used the innterText to show in my Parent Component.
interface IndicatorInputState {
html: any
}
class ParentComponent extends React.Component<{}, IndicatorInputState>{
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
this.onRef = this.onRef.bind(this);
this.state = {
html:''
}
}
onChange(value) {
this.setState({html: `<span>${value}</span>`});
}
render() {
return (
<React.Fragment>
<div className="indicator-input">
<ContentEditable onChange={this.onChange} html={this.state.html} onRef={this.onRef} >
</ContentEditable>
</div>
</React.Fragment>
)
}
}
export default ParentComponent
in My parent Component I have a sate(html) and set the html by this value
in this situation I don't have problem but if I use span instead of just using value then my cursor have a freaky behavior and it goes to left of my div
does anybody know how can i set the cursor to right? Provided that whenever the user write any things or delete text with backspace then the cursor must be at right(by the way:i used css for example direction but it isn't use full because backspace doesn't work in right position)
the sample of my code is here:
https://codepen.io/saeedafroozi/pen/WYweeO?editors=1010
please help me
html css reactjs
html css reactjs
edited Nov 8 at 12:43
zubair khanzada
5522513
5522513
asked Nov 8 at 11:09
saeed
45
45
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206544%2freact-div-content-editable-render-value-with-span%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown