Skip to content

Commit 4fc9d3a

Browse files
author
Dan Carbonell
committed
Merge branch 'master' into textarea-paste-limit
2 parents ed96de3 + 37b5e5a commit 4fc9d3a

File tree

16 files changed

+77
-28
lines changed

16 files changed

+77
-28
lines changed

src/components/AutoCompleteTextarea/List.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,12 @@ const List = (props) => {
104104

105105
if (value[0] === ':') {
106106
const html = `<strong>${value.replace(':', '')}</strong>`;
107-
return `${t('Emoji matching')} ${html}}`;
107+
return `${t('Emoji matching')} ${html}`;
108108
}
109109

110110
if (value[0] === '@') {
111-
return t('Searching for people');
111+
const html = `<strong>${value.replace('@', '')}</strong>`;
112+
return `${t('People matching')} ${html}`;
112113
}
113114

114115
return null;

src/components/AutoCompleteTextarea/Textarea.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ class ReactTextareaAutocomplete extends React.Component {
431431
'closeOnClickOutside',
432432
'containerClassName',
433433
'containerStyle',
434+
'disableMentions',
434435
'dropdownClassName',
435436
'dropdownStyle',
436437
'grow',
@@ -623,6 +624,7 @@ class ReactTextareaAutocomplete extends React.Component {
623624
className,
624625
containerClassName,
625626
containerStyle,
627+
disableMentions,
626628
dropdownClassName,
627629
dropdownStyle,
628630
itemClassName,
@@ -632,23 +634,21 @@ class ReactTextareaAutocomplete extends React.Component {
632634
SuggestionList = DefaultSuggestionList,
633635
} = this.props;
634636

637+
let { maxRows } = this.props;
638+
635639
const { component, currentTrigger, dataLoading, value } = this.state;
636640

637641
const selectedItem = this._getItemOnSelect();
638642
const suggestionData = this._getSuggestions();
639643
const textToReplace = this._getTextToReplace();
640644

641-
let { maxRows } = this.props;
642-
if (!this.props.grow) maxRows = 1;
643-
644-
return (
645-
<div
646-
className={`rta ${dataLoading === true ? 'rta--loading' : ''} ${
647-
containerClassName || ''
648-
}`}
649-
style={containerStyle}
650-
>
651-
{(dataLoading || suggestionData) && currentTrigger && (
645+
const SuggestionListContainer = () => {
646+
if (
647+
(dataLoading || suggestionData) &&
648+
currentTrigger &&
649+
!(disableMentions && currentTrigger === '@')
650+
) {
651+
return (
652652
<div
653653
className={`rta__autocomplete ${dropdownClassName || ''}`}
654654
ref={(ref) => {
@@ -671,7 +671,21 @@ class ReactTextareaAutocomplete extends React.Component {
671671
/>
672672
)}
673673
</div>
674-
)}
674+
);
675+
}
676+
return null;
677+
};
678+
679+
if (!this.props.grow) maxRows = 1;
680+
681+
return (
682+
<div
683+
className={`rta ${dataLoading === true ? 'rta--loading' : ''} ${
684+
containerClassName || ''
685+
}`}
686+
style={containerStyle}
687+
>
688+
<SuggestionListContainer />
675689
<Textarea
676690
{...this._cleanUpProps()}
677691
className={`rta__textarea ${className || ''}`}
@@ -700,6 +714,7 @@ ReactTextareaAutocomplete.propTypes = {
700714
closeOnClickOutside: PropTypes.bool,
701715
containerClassName: PropTypes.string,
702716
containerStyle: PropTypes.object,
717+
disableMentions: PropTypes.bool,
703718
dropdownClassName: PropTypes.string,
704719
dropdownStyle: PropTypes.object,
705720
itemClassName: PropTypes.string,

src/components/ChatAutoComplete/ChatAutoComplete.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ const emojiReplace = (word) => {
2525

2626
/** @type {React.FC<import("types").ChatAutoCompleteProps>} */
2727
const ChatAutoComplete = (props) => {
28+
const { commands, onSelectItem, triggers } = props;
29+
2830
const { channel } = useContext(ChannelContext);
31+
2932
const members = channel?.state?.members;
3033
const watchers = channel?.state?.watchers;
3134

@@ -66,7 +69,6 @@ const ChatAutoComplete = (props) => {
6669
[channel?.queryMembers],
6770
);
6871

69-
const { commands, onSelectItem, triggers } = props;
7072
/**
7173
* dataProvider accepts `onReady` function, which will executed once the data is ready.
7274
* Another approach would have been to simply return the data from dataProvider and let the
@@ -187,9 +189,9 @@ const ChatAutoComplete = (props) => {
187189
},
188190
},
189191
[
190-
members,
191-
getMembersAndWatchers,
192192
commands,
193+
getMembersAndWatchers,
194+
members,
193195
onSelectItem,
194196
queryMembersdebounced,
195197
triggers,
@@ -227,6 +229,7 @@ const ChatAutoComplete = (props) => {
227229
value={props.value}
228230
grow={props.grow}
229231
disabled={props.disabled}
232+
disableMentions={props.disableMentions}
230233
SuggestionList={props.SuggestionList}
231234
additionalTextareaProps={props.additionalTextareaProps}
232235
/>
@@ -242,6 +245,8 @@ ChatAutoComplete.propTypes = {
242245
maxRows: PropTypes.number,
243246
/** Make the textarea disabled */
244247
disabled: PropTypes.bool,
248+
/** Disable mentions */
249+
disableMentions: PropTypes.bool,
245250
/** The value of the textarea */
246251
value: PropTypes.string,
247252
/** Function to run on pasting within the textarea */

src/components/ChatAutoComplete/__tests__/ChatAutocomplete.test.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ describe('ChatAutoComplete', () => {
110110
it('should let you select users when you type @<username>', async () => {
111111
const onSelectItem = jest.fn();
112112
const userAutocompleteText = `@${user.name}`;
113-
const { typeText, findByText } = await renderComponent({ onSelectItem });
113+
const { typeText, getAllByText } = await renderComponent({ onSelectItem });
114114
typeText(userAutocompleteText);
115-
const userText = await findByText(user.name);
115+
const userText = await getAllByText(user.name);
116116

117-
expect(userText).toBeInTheDocument();
117+
expect(userText).toHaveLength(2);
118118

119-
fireEvent.click(userText);
119+
fireEvent.click(userText[1]);
120120

121121
expect(onSelectItem).toHaveBeenCalledWith(
122122
expect.objectContaining({
@@ -165,6 +165,19 @@ describe('ChatAutoComplete', () => {
165165
expect(textarea.value).toContain('/giphy');
166166
});
167167

168+
it('should disable mention popup list', async () => {
169+
const onSelectItem = jest.fn();
170+
const userAutocompleteText = `@${user.name}`;
171+
const { typeText, queryAllByText } = await renderComponent({
172+
onSelectItem,
173+
disableMentions: true,
174+
});
175+
typeText(userAutocompleteText);
176+
const userText = await queryAllByText(user.name);
177+
178+
expect(userText).toHaveLength(0);
179+
});
180+
168181
it('should use the queryMembers API for mentions if a channel has many members', async () => {
169182
const users = Array(100).fill().map(generateUser);
170183
const members = users.map((u) => generateMember({ user: u }));

src/components/MessageInput/MessageInputFlat.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const MessageInputFlat = (props) => {
6464
triggers={props.autocompleteTriggers}
6565
grow={props.grow}
6666
disabled={props.disabled}
67+
disableMentions={props.disableMentions}
6768
SuggestionList={props.SuggestionList}
6869
additionalTextareaProps={props.additionalTextareaProps}
6970
/>
@@ -116,6 +117,8 @@ MessageInputFlat.propTypes = {
116117
maxRows: PropTypes.number.isRequired,
117118
/** Make the textarea disabled */
118119
disabled: PropTypes.bool,
120+
/** Disable mentions in textarea */
121+
disableMentions: PropTypes.bool,
119122
/** enable/disable firing the typing event */
120123
publishTypingEvent: PropTypes.bool,
121124
/**

src/components/MessageInput/MessageInputLarge.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const MessageInputLarge = (props) => {
9191
triggers={props.autocompleteTriggers}
9292
grow={props.grow}
9393
disabled={props.disabled}
94+
disableMentions={props.disableMentions}
9495
SuggestionList={props.SuggestionList}
9596
additionalTextareaProps={props.additionalTextareaProps}
9697
/>
@@ -161,6 +162,8 @@ MessageInputLarge.propTypes = {
161162
maxRows: PropTypes.number.isRequired,
162163
/** Make the textarea disabled */
163164
disabled: PropTypes.bool,
165+
/** Disable mentions in textarea */
166+
disableMentions: PropTypes.bool,
164167
/** enable/disable firing the typing event */
165168
publishTypingEvent: PropTypes.bool,
166169
/**

src/components/MessageInput/MessageInputSimple.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const MessageInputSimple = (props) => {
4343
triggers={props.autocompleteTriggers}
4444
grow={props.grow}
4545
disabled={props.disabled}
46+
disableMentions={props.disableMentions}
4647
SuggestionList={props.SuggestionList}
4748
additionalTextareaProps={props.additionalTextareaProps}
4849
/>
@@ -72,6 +73,8 @@ MessageInputSimple.propTypes = {
7273
maxRows: PropTypes.number.isRequired,
7374
/** Make the textarea disabled */
7475
disabled: PropTypes.bool,
76+
/** Disable mentions in textarea */
77+
disableMentions: PropTypes.bool,
7578
/** enable/disable firing the typing event */
7679
publishTypingEvent: PropTypes.bool,
7780
/**

src/components/MessageInput/MessageInputSmall.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const MessageInputSmall = (props) => {
6565
triggers={props.autocompleteTriggers}
6666
grow={props.grow}
6767
disabled={props.disabled}
68+
disableMentions={props.disableMentions}
6869
SuggestionList={props.SuggestionList}
6970
additionalTextareaProps={props.additionalTextareaProps}
7071
/>
@@ -117,6 +118,8 @@ MessageInputSmall.propTypes = {
117118
maxRows: PropTypes.number.isRequired,
118119
/** Make the textarea disabled */
119120
disabled: PropTypes.bool,
121+
/** Disable mentions in textarea */
122+
disableMentions: PropTypes.bool,
120123
/** enable/disable firing the typing event */
121124
publishTypingEvent: PropTypes.bool,
122125
/**

src/i18n/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"Nothing yet...": "Nothing yet...",
2929
"Only visible to you": "Only visible to you",
3030
"Open emoji picker": "Open emoji picker",
31+
"People matching": "People matching",
3132
"Pick your emoji": "Pick your emoji",
32-
"Searching for people": "Searching for people",
3333
"Send": "Send",
3434
"Sending...": "Sending...",
3535
"Start of a new thread": "Start of a new thread",

src/i18n/fr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"Nothing yet...": "Aucun message...",
2929
"Only visible to you": "Visible uniquement pour vous",
3030
"Open emoji picker": "Ouvrez le sélecteur d'emoji",
31+
"People matching": "Correspondance de personnes",
3132
"Pick your emoji": "Choisissez votre emoji",
32-
"Searching for people": "Recherche de personnes",
3333
"Send": "Envoyer",
3434
"Sending...": "Envoi en cours...",
3535
"Start of a new thread": "Début d'un nouveau fil de discussion",

0 commit comments

Comments
 (0)