react-mention-input 1.1.8 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,10 +2,11 @@ import React, { useState, useRef } from "react";
2
2
  import ReactDOM from "react-dom";
3
3
  import "./MentionInput.css";
4
4
  var MentionInput = function (_a) {
5
- var users = _a.users, _b = _a.placeholder, placeholder = _b === void 0 ? "Type a message..." : _b, containerClassName = _a.containerClassName, inputContainerClassName = _a.inputContainerClassName, inputClassName = _a.inputClassName, sendBtnClassName = _a.sendBtnClassName, suggestionListClassName = _a.suggestionListClassName, suggestionItemClassName = _a.suggestionItemClassName, sendButtonIcon = _a.sendButtonIcon, onSendMessage = _a.onSendMessage, _c = _a.suggestionPosition, suggestionPosition = _c === void 0 ? 'bottom' : _c;
6
- var _d = useState(""), inputValue = _d[0], setInputValue = _d[1]; // Plain text
7
- var _e = useState([]), suggestions = _e[0], setSuggestions = _e[1];
8
- var _f = useState(false), showSuggestions = _f[0], setShowSuggestions = _f[1];
5
+ var _b;
6
+ var users = _a.users, _c = _a.placeholder, placeholder = _c === void 0 ? "Type a message..." : _c, containerClassName = _a.containerClassName, inputContainerClassName = _a.inputContainerClassName, inputClassName = _a.inputClassName, sendBtnClassName = _a.sendBtnClassName, suggestionListClassName = _a.suggestionListClassName, suggestionItemClassName = _a.suggestionItemClassName, sendButtonIcon = _a.sendButtonIcon, onSendMessage = _a.onSendMessage, _d = _a.suggestionPosition, suggestionPosition = _d === void 0 ? 'bottom' : _d;
7
+ var _e = useState(""), inputValue = _e[0], setInputValue = _e[1]; // Plain text
8
+ var _f = useState([]), suggestions = _f[0], setSuggestions = _f[1];
9
+ var _g = useState(false), showSuggestions = _g[0], setShowSuggestions = _g[1];
9
10
  var inputRef = useRef(null);
10
11
  var suggestionListRef = useRef(null);
11
12
  var caretOffsetRef = useRef(0);
@@ -92,11 +93,6 @@ var MentionInput = function (_a) {
92
93
  var renderSuggestions = function () {
93
94
  if (!showSuggestions || !inputRef.current)
94
95
  return null;
95
- var inputRect = inputRef.current.getBoundingClientRect();
96
- var styles = {
97
- position: 'absolute',
98
- zIndex: 1000,
99
- };
100
96
  var getInitials = function (name) {
101
97
  var nameParts = name.split(" ");
102
98
  var initials = nameParts
@@ -105,6 +101,11 @@ var MentionInput = function (_a) {
105
101
  .join("");
106
102
  return initials;
107
103
  };
104
+ var inputRect = inputRef.current.getBoundingClientRect();
105
+ var styles = {
106
+ position: 'absolute',
107
+ zIndex: 1000,
108
+ };
108
109
  // Use suggestionPosition prop to adjust tooltip position
109
110
  switch (suggestionPosition) {
110
111
  case 'top':
@@ -183,6 +184,7 @@ var MentionInput = function (_a) {
183
184
  };
184
185
  return (React.createElement("div", { className: "mention-container ".concat(containerClassName || "") },
185
186
  React.createElement("div", { className: "mention-input-container ".concat(inputContainerClassName || "") },
187
+ (!inputValue || !inputRef.current || ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.innerText.trim()) === "") ? (React.createElement("span", { className: "placeholder" }, placeholder)) : null,
186
188
  React.createElement("div", { ref: inputRef, contentEditable: true, suppressContentEditableWarning: true, className: "mention-input ".concat(inputClassName || ""), onInput: handleInputChange, onKeyDown: handleKeyDown }),
187
189
  React.createElement("button", { onClick: handleSendMessage, className: "send-button ".concat(sendBtnClassName || "") }, sendButtonIcon || "➤")),
188
190
  renderSuggestions()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-mention-input",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -145,12 +145,6 @@ const MentionInput: React.FC<MentionInputProps> = ({
145
145
  const renderSuggestions = () => {
146
146
  if (!showSuggestions || !inputRef.current) return null;
147
147
 
148
- const inputRect = inputRef.current.getBoundingClientRect();
149
- const styles: React.CSSProperties = {
150
- position: 'absolute',
151
- zIndex: 1000,
152
- };
153
-
154
148
  const getInitials = (name: string) => {
155
149
  const nameParts = name.split(" ");
156
150
  const initials = nameParts
@@ -159,6 +153,12 @@ const MentionInput: React.FC<MentionInputProps> = ({
159
153
  .join("");
160
154
  return initials;
161
155
  };
156
+
157
+ const inputRect = inputRef.current.getBoundingClientRect();
158
+ const styles: React.CSSProperties = {
159
+ position: 'absolute',
160
+ zIndex: 1000,
161
+ };
162
162
 
163
163
  // Use suggestionPosition prop to adjust tooltip position
164
164
  switch (suggestionPosition) {
@@ -273,10 +273,12 @@ const MentionInput: React.FC<MentionInputProps> = ({
273
273
  };
274
274
 
275
275
 
276
-
277
276
  return (
278
277
  <div className={`mention-container ${containerClassName || ""}`}>
279
278
  <div className={`mention-input-container ${inputContainerClassName || ""}`}>
279
+ {(!inputValue || !inputRef.current || inputRef.current?.innerText.trim() === "") ? (
280
+ <span className="placeholder">{placeholder}</span>
281
+ ) : null}
280
282
  <div
281
283
  ref={inputRef}
282
284
  contentEditable
@@ -284,7 +286,8 @@ const MentionInput: React.FC<MentionInputProps> = ({
284
286
  className={`mention-input ${inputClassName || ""}`}
285
287
  onInput={handleInputChange}
286
288
  onKeyDown={handleKeyDown} // Add keydown listener
287
- ></div>
289
+ >
290
+ </div>
288
291
  <button
289
292
  onClick={handleSendMessage}
290
293
  className={`send-button ${sendBtnClassName || ""}`}