Skip to content

Commit 6fb2008

Browse files
authored
Merge pull request #48 from aimeex3/mention
feat(mention): add mention open/close handlers
2 parents ad5c3b6 + fe0c1c3 commit 6fb2008

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/components/ComposerQuill/composer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class Composer extends React.Component {
5252
this.handleEnter = this.handleEnter.bind(this);
5353
this.handleTextChange = this.handleTextChange.bind(this);
5454
this.handleMentionSelect = this.handleMentionSelect.bind(this);
55+
this.handleMentionOpen = this.handleMentionOpen.bind(this);
56+
this.handleMentionClose = this.handleMentionClose.bind(this);
5557
this.saveToDraft = this.saveToDraft.bind(this);
5658
this.openMentionList = this.openMentionList.bind(this);
5759
this.handleFocus = this.handleFocus.bind(this);
@@ -96,6 +98,8 @@ class Composer extends React.Component {
9698
defaultMenuOrientation: 'top',
9799
mentionDenotationChars: ['@'],
98100
onSelect: this.handleMentionSelect,
101+
onOpen: this.handleMentionOpen,
102+
onClose: this.handleMentionClose,
99103
renderItem: this.handleMentionItem,
100104
source: this.handleMention.bind(this),
101105
spaceAfterInsert: false,
@@ -338,6 +342,22 @@ class Composer extends React.Component {
338342
}
339343
}
340344

345+
handleMentionOpen() {
346+
const {onMentionOpen} = this.props;
347+
348+
if (onMentionOpen) {
349+
onMentionOpen();
350+
}
351+
}
352+
353+
handleMentionClose() {
354+
const {onMentionClose} = this.props;
355+
356+
if (onMentionClose) {
357+
onMentionClose();
358+
}
359+
}
360+
341361
handleTextChange(delta, oldDelta, source) {
342362
const {notifyKeyDown} = this.props;
343363

@@ -443,6 +463,8 @@ Composer.propTypes = {
443463
}),
444464
}),
445465
notifyKeyDown: PropTypes.func,
466+
onMentionClose: PropTypes.func,
467+
onMentionOpen: PropTypes.func,
446468
onError: PropTypes.func,
447469
placeholder: PropTypes.string,
448470
send: PropTypes.func,
@@ -454,6 +476,8 @@ Composer.defaultProps = {
454476
markdown: undefined,
455477
mentions: undefined,
456478
notifyKeyDown: undefined,
479+
onMentionClose: undefined,
480+
onMentionOpen: undefined,
457481
onError: undefined,
458482
placeholder: 'Compose something awesome...',
459483
send: undefined,

src/components/MessageComposer/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const MessageComposer = ({
1818
draft,
1919
setEmitter,
2020
notifyKeyDown,
21+
onMentionOpen,
22+
onMentionClose,
2123
placeholder,
2224
onError,
2325
keyBindings,
@@ -49,6 +51,8 @@ const MessageComposer = ({
4951
emitter={emitter.current}
5052
active={setActive}
5153
notifyKeyDown={notifyKeyDown}
54+
onMentionOpen={onMentionOpen}
55+
onMentionClose={onMentionClose}
5256
placeholder={placeholder}
5357
onError={onError}
5458
keyBindings={keyBindings}
@@ -77,6 +81,8 @@ MessageComposer.propTypes = {
7781
participants: PropTypes.object,
7882
}),
7983
notifyKeyDown: PropTypes.func,
84+
onMentionClose: PropTypes.func,
85+
onMentionOpen: PropTypes.func,
8086
onError: PropTypes.func,
8187
placeholder: PropTypes.string,
8288
send: PropTypes.func,
@@ -92,6 +98,8 @@ MessageComposer.defaultProps = {
9298
markdown: undefined,
9399
mentions: undefined,
94100
notifyKeyDown: null,
101+
onMentionClose: undefined,
102+
onMentionOpen: undefined,
95103
onError: undefined,
96104
placeholder: '',
97105
send: undefined,

0 commit comments

Comments
 (0)