Skip to content

Commit

Permalink
feat(message-input): added arguments to onChange and onSend
Browse files Browse the repository at this point in the history
Two Additional arguments has been added: textContent, innerText, and cloned array of
nodes from contenteditable div of message input.
  • Loading branch information
supersnager committed May 5, 2021
1 parent abaa4db commit 9f8b2cc
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/components/MessageInput/MessageInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ function MessageInputInner(
}
});

const getContent = () => {
// Direct reference to contenteditable div
const contentEditableRef = msgRef.current.msgRef.current;
return [
contentEditableRef.textContent,
contentEditableRef.innerText,
contentEditableRef.cloneNode(true).childNodes,
];
};

const send = () => {
if (stateValue.length > 0) {
// Clear input only when it's uncontrolled mode
Expand All @@ -131,7 +141,9 @@ function MessageInputInner(
setStateSendDisabled(true);
}

onSend(stateValue);
const content = getContent();

onSend(stateValue, content[0], content[1], content[2]);
}
};

Expand All @@ -142,8 +154,8 @@ function MessageInputInner(
}
};

const handleChange = (val, textContent, innerText) => {
setStateValue(val);
const handleChange = (innerHTML, textContent, innerText) => {
setStateValue(innerHTML);
if (typeof sendDisabled === "undefined") {
setStateSendDisabled(textContent.length === 0);
}
Expand All @@ -152,7 +164,9 @@ function MessageInputInner(
scrollRef.current.updateScroll();
}

onChange(val);
const content = getContent();

onChange(innerHTML, textContent, innerText, content[2]);
};

const cName = `${prefix}-message-input`,
Expand Down

0 comments on commit 9f8b2cc

Please sign in to comment.