Skip to content

Commit

Permalink
Feat: Support onKeyDown (#14)
Browse files Browse the repository at this point in the history
* feat: add onKeyDown support

* 2.1.0
  • Loading branch information
cvle authored Mar 4, 2021
1 parent 146bf49 commit 7f811a8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coralproject/rte",
"version": "2.0.0",
"version": "2.1.0",
"description": "Coral Rich Text Editor",
"author": "The Coral Project Team @coralproject",
"license": "Apache-2.0",
Expand Down
11 changes: 11 additions & 0 deletions src/RTE.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ interface PropTypes {
onFocus?: EventHandler<FocusEvent>;
/** onFocus is called whenenver the RTE looses focus */
onBlur?: EventHandler<FocusEvent>;
/** onKeyDown is called whenever a key is pressed down on the RTE */
onKeyDown?: KeyboardEventHandler<Element>;
/** onKeyPress is called whenever a key is pressed on the RTE */
onKeyPress?: KeyboardEventHandler<Element>;

Expand Down Expand Up @@ -173,6 +175,7 @@ class RTE extends React.Component<PropTypes, State> {
this.squire.addEventListener("focus", this.handleContentEditableFocus);
this.squire.addEventListener("blur", this.handleContentEditableBlur);
this.squire.addEventListener("keypress", this.handleKeyPress);
this.squire.addEventListener("keydown", this.handleKeyDown);

// Reset shortcuts. We add shortcuts through the added features.
[
Expand Down Expand Up @@ -347,6 +350,14 @@ class RTE extends React.Component<PropTypes, State> {
this.props.onKeyPress(event);
};

private handleKeyDown = (event: React.KeyboardEvent<Element>) => {
if (!this.props.onKeyDown) {
return;
}

this.props.onKeyDown(event);
};

private renderFeatures() {
if (!this.squire) {
return null;
Expand Down

0 comments on commit 7f811a8

Please sign in to comment.