@patternfly/chatbot 6.3.0-prerelease.19 → 6.3.0-prerelease.20

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.
@@ -22,7 +22,7 @@ export interface MessageBarWithAttachMenuProps {
22
22
  /** Callback to change the open state of the menu. Triggered by clicking outside of the menu. */
23
23
  onAttachMenuOpenChange?: (isOpen: boolean) => void;
24
24
  }
25
- export interface MessageBarProps extends TextAreaProps {
25
+ export interface MessageBarProps extends Omit<TextAreaProps, 'innerRef'> {
26
26
  /** Callback to get the value of input message by user */
27
27
  onSendMessage: (message: string | number) => void;
28
28
  /** Class Name for the MessageBar component */
@@ -79,6 +79,7 @@ export interface MessageBarProps extends TextAreaProps {
79
79
  onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, value: string | number) => void;
80
80
  /** Display mode of chatbot, if you want to message bar to resize when the display mode changes */
81
81
  displayMode?: ChatbotDisplayMode;
82
+ /** Whether message bar is compact */
82
83
  isCompact?: boolean;
83
84
  /** Specifies the file types accepted by the attachment upload component.
84
85
  * Files that don't match the accepted types will be disabled in the file picker.
@@ -86,6 +87,10 @@ export interface MessageBarProps extends TextAreaProps {
86
87
  * allowedFileTypes: { 'application/json': ['.json'], 'text/plain': ['.txt'] }
87
88
  **/
88
89
  allowedFileTypes?: Accept;
90
+ /** Ref applied to message bar textarea, for use with focus or other custom behaviors */
91
+ innerRef?: React.Ref<HTMLTextAreaElement>;
89
92
  }
90
- export declare const MessageBar: FunctionComponent<MessageBarProps>;
93
+ export declare const MessageBarBase: FunctionComponent<MessageBarProps>;
94
+ declare const MessageBar: import("react").ForwardRefExoticComponent<MessageBarProps & import("react").RefAttributes<HTMLTextAreaElement>>;
95
+ export { MessageBar };
91
96
  export default MessageBar;
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.MessageBar = void 0;
17
+ exports.MessageBar = exports.MessageBarBase = void 0;
18
18
  const jsx_runtime_1 = require("react/jsx-runtime");
19
19
  const react_1 = require("react");
20
20
  const react_core_1 = require("@patternfly/react-core");
@@ -24,14 +24,16 @@ const MicrophoneButton_1 = __importDefault(require("./MicrophoneButton"));
24
24
  const AttachButton_1 = require("./AttachButton");
25
25
  const AttachMenu_1 = __importDefault(require("../AttachMenu"));
26
26
  const StopButton_1 = __importDefault(require("./StopButton"));
27
- const MessageBar = (_a) => {
28
- var { onSendMessage, className, alwayShowSendButton, placeholder = 'Send a message...', hasAttachButton = true, hasMicrophoneButton, listeningText = 'Listening', handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode, value, isCompact = false, allowedFileTypes } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "placeholder", "hasAttachButton", "hasMicrophoneButton", "listeningText", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value", "isCompact", "allowedFileTypes"]);
27
+ const MessageBarBase = (_a) => {
28
+ var _b;
29
+ var { onSendMessage, className, alwayShowSendButton, placeholder = 'Send a message...', hasAttachButton = true, hasMicrophoneButton, listeningText = 'Listening', handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode, value, isCompact = false, allowedFileTypes, innerRef } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "placeholder", "hasAttachButton", "hasMicrophoneButton", "listeningText", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value", "isCompact", "allowedFileTypes", "innerRef"]);
29
30
  // Text Input
30
31
  // --------------------------------------------------------------------------
31
32
  const [message, setMessage] = (0, react_1.useState)(value !== null && value !== void 0 ? value : '');
32
33
  const [isListeningMessage, setIsListeningMessage] = (0, react_1.useState)(false);
33
34
  const [hasSentMessage, setHasSentMessage] = (0, react_1.useState)(false);
34
- const textareaRef = (0, react_1.useRef)(null);
35
+ const inputRef = (0, react_1.useRef)(null);
36
+ const textareaRef = (_b = innerRef) !== null && _b !== void 0 ? _b : inputRef;
35
37
  const attachButtonRef = (0, react_1.useRef)(null);
36
38
  const topMargin = '1rem';
37
39
  const setInitialLineHeight = (field) => {
@@ -193,5 +195,7 @@ const MessageBar = (_a) => {
193
195
  }
194
196
  return (0, jsx_runtime_1.jsx)("div", { className: `pf-chatbot__message-bar ${className !== null && className !== void 0 ? className : ''}`, children: messageBarContents });
195
197
  };
198
+ exports.MessageBarBase = MessageBarBase;
199
+ const MessageBar = (0, react_1.forwardRef)((props, ref) => ((0, jsx_runtime_1.jsx)(exports.MessageBarBase, Object.assign({ innerRef: ref }, props))));
196
200
  exports.MessageBar = MessageBar;
197
- exports.default = exports.MessageBar;
201
+ exports.default = MessageBar;
@@ -18,6 +18,7 @@ const react_core_1 = require("@patternfly/react-core");
18
18
  const react_icons_1 = require("@patternfly/react-icons");
19
19
  const react_1 = require("@testing-library/react");
20
20
  const user_event_1 = __importDefault(require("@testing-library/user-event"));
21
+ const react_2 = require("react");
21
22
  const SourceDetailsMenuItem_1 = __importDefault(require("../SourceDetailsMenuItem"));
22
23
  const MessageBar_1 = require("./MessageBar");
23
24
  const ATTACH_MENU_ITEMS = [
@@ -261,4 +262,11 @@ describe('Message bar', () => {
261
262
  expect(react_1.screen.getByRole('textbox', { name: /Send a message.../i })).toBeTruthy();
262
263
  expect(react_1.screen.getByRole('textbox', { name: /Send a message.../i })).toHaveValue('test');
263
264
  });
265
+ it('should focus textarea when using a custom ref', () => {
266
+ var _a;
267
+ const ref = (0, react_2.createRef)();
268
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(MessageBar_1.MessageBar, { onSendMessage: jest.fn, innerRef: ref }));
269
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.focus();
270
+ expect(document.activeElement).toBe(react_1.screen.getByRole('textbox'));
271
+ });
264
272
  });
@@ -22,7 +22,7 @@ export interface MessageBarWithAttachMenuProps {
22
22
  /** Callback to change the open state of the menu. Triggered by clicking outside of the menu. */
23
23
  onAttachMenuOpenChange?: (isOpen: boolean) => void;
24
24
  }
25
- export interface MessageBarProps extends TextAreaProps {
25
+ export interface MessageBarProps extends Omit<TextAreaProps, 'innerRef'> {
26
26
  /** Callback to get the value of input message by user */
27
27
  onSendMessage: (message: string | number) => void;
28
28
  /** Class Name for the MessageBar component */
@@ -79,6 +79,7 @@ export interface MessageBarProps extends TextAreaProps {
79
79
  onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, value: string | number) => void;
80
80
  /** Display mode of chatbot, if you want to message bar to resize when the display mode changes */
81
81
  displayMode?: ChatbotDisplayMode;
82
+ /** Whether message bar is compact */
82
83
  isCompact?: boolean;
83
84
  /** Specifies the file types accepted by the attachment upload component.
84
85
  * Files that don't match the accepted types will be disabled in the file picker.
@@ -86,6 +87,10 @@ export interface MessageBarProps extends TextAreaProps {
86
87
  * allowedFileTypes: { 'application/json': ['.json'], 'text/plain': ['.txt'] }
87
88
  **/
88
89
  allowedFileTypes?: Accept;
90
+ /** Ref applied to message bar textarea, for use with focus or other custom behaviors */
91
+ innerRef?: React.Ref<HTMLTextAreaElement>;
89
92
  }
90
- export declare const MessageBar: FunctionComponent<MessageBarProps>;
93
+ export declare const MessageBarBase: FunctionComponent<MessageBarProps>;
94
+ declare const MessageBar: import("react").ForwardRefExoticComponent<MessageBarProps & import("react").RefAttributes<HTMLTextAreaElement>>;
95
+ export { MessageBar };
91
96
  export default MessageBar;
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { useCallback, useEffect, useRef, useState } from 'react';
13
+ import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
14
14
  import { TextArea } from '@patternfly/react-core';
15
15
  // Import Chatbot components
16
16
  import SendButton from './SendButton';
@@ -18,14 +18,16 @@ import MicrophoneButton from './MicrophoneButton';
18
18
  import { AttachButton } from './AttachButton';
19
19
  import AttachMenu from '../AttachMenu';
20
20
  import StopButton from './StopButton';
21
- export const MessageBar = (_a) => {
22
- var { onSendMessage, className, alwayShowSendButton, placeholder = 'Send a message...', hasAttachButton = true, hasMicrophoneButton, listeningText = 'Listening', handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode, value, isCompact = false, allowedFileTypes } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "placeholder", "hasAttachButton", "hasMicrophoneButton", "listeningText", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value", "isCompact", "allowedFileTypes"]);
21
+ export const MessageBarBase = (_a) => {
22
+ var _b;
23
+ var { onSendMessage, className, alwayShowSendButton, placeholder = 'Send a message...', hasAttachButton = true, hasMicrophoneButton, listeningText = 'Listening', handleAttach, attachMenuProps, isSendButtonDisabled, handleStopButton, hasStopButton, buttonProps, onChange, displayMode, value, isCompact = false, allowedFileTypes, innerRef } = _a, props = __rest(_a, ["onSendMessage", "className", "alwayShowSendButton", "placeholder", "hasAttachButton", "hasMicrophoneButton", "listeningText", "handleAttach", "attachMenuProps", "isSendButtonDisabled", "handleStopButton", "hasStopButton", "buttonProps", "onChange", "displayMode", "value", "isCompact", "allowedFileTypes", "innerRef"]);
23
24
  // Text Input
24
25
  // --------------------------------------------------------------------------
25
26
  const [message, setMessage] = useState(value !== null && value !== void 0 ? value : '');
26
27
  const [isListeningMessage, setIsListeningMessage] = useState(false);
27
28
  const [hasSentMessage, setHasSentMessage] = useState(false);
28
- const textareaRef = useRef(null);
29
+ const inputRef = useRef(null);
30
+ const textareaRef = (_b = innerRef) !== null && _b !== void 0 ? _b : inputRef;
29
31
  const attachButtonRef = useRef(null);
30
32
  const topMargin = '1rem';
31
33
  const setInitialLineHeight = (field) => {
@@ -187,4 +189,6 @@ export const MessageBar = (_a) => {
187
189
  }
188
190
  return _jsx("div", { className: `pf-chatbot__message-bar ${className !== null && className !== void 0 ? className : ''}`, children: messageBarContents });
189
191
  };
192
+ const MessageBar = forwardRef((props, ref) => (_jsx(MessageBarBase, Object.assign({ innerRef: ref }, props))));
193
+ export { MessageBar };
190
194
  export default MessageBar;
@@ -13,6 +13,7 @@ import { DropdownGroup, DropdownItem, DropdownList } from '@patternfly/react-cor
13
13
  import { BellIcon, CalendarAltIcon, ClipboardIcon, CodeIcon } from '@patternfly/react-icons';
14
14
  import { render, screen } from '@testing-library/react';
15
15
  import userEvent from '@testing-library/user-event';
16
+ import { createRef } from 'react';
16
17
  import SourceDetailsMenuItem from '../SourceDetailsMenuItem';
17
18
  import { MessageBar } from './MessageBar';
18
19
  const ATTACH_MENU_ITEMS = [
@@ -256,4 +257,11 @@ describe('Message bar', () => {
256
257
  expect(screen.getByRole('textbox', { name: /Send a message.../i })).toBeTruthy();
257
258
  expect(screen.getByRole('textbox', { name: /Send a message.../i })).toHaveValue('test');
258
259
  });
260
+ it('should focus textarea when using a custom ref', () => {
261
+ var _a;
262
+ const ref = createRef();
263
+ render(_jsx(MessageBar, { onSendMessage: jest.fn, innerRef: ref }));
264
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.focus();
265
+ expect(document.activeElement).toBe(screen.getByRole('textbox'));
266
+ });
259
267
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/chatbot",
3
- "version": "6.3.0-prerelease.19",
3
+ "version": "6.3.0-prerelease.20",
4
4
  "description": "This library provides React components based on PatternFly 6 that can be used to build chatbots.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -3,6 +3,7 @@ import { DropdownGroup, DropdownItem, DropdownList } from '@patternfly/react-cor
3
3
  import { BellIcon, CalendarAltIcon, ClipboardIcon, CodeIcon } from '@patternfly/react-icons';
4
4
  import { render, screen } from '@testing-library/react';
5
5
  import userEvent from '@testing-library/user-event';
6
+ import { createRef } from 'react';
6
7
  import SourceDetailsMenuItem from '../SourceDetailsMenuItem';
7
8
  import { MessageBar } from './MessageBar';
8
9
 
@@ -380,4 +381,10 @@ describe('Message bar', () => {
380
381
  expect(screen.getByRole('textbox', { name: /Send a message.../i })).toBeTruthy();
381
382
  expect(screen.getByRole('textbox', { name: /Send a message.../i })).toHaveValue('test');
382
383
  });
384
+ it('should focus textarea when using a custom ref', () => {
385
+ const ref = createRef<HTMLTextAreaElement>();
386
+ render(<MessageBar onSendMessage={jest.fn} innerRef={ref} />);
387
+ ref.current?.focus();
388
+ expect(document.activeElement).toBe(screen.getByRole('textbox'));
389
+ });
383
390
  });
@@ -1,5 +1,5 @@
1
- import type { ChangeEvent, FunctionComponent, KeyboardEvent as ReactKeyboardEvent } from 'react';
2
- import { useCallback, useEffect, useRef, useState } from 'react';
1
+ import type { ChangeEvent, FunctionComponent, KeyboardEvent as ReactKeyboardEvent, Ref } from 'react';
2
+ import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
3
3
  import { Accept } from 'react-dropzone/.';
4
4
  import { ButtonProps, DropEvent, TextArea, TextAreaProps, TooltipProps } from '@patternfly/react-core';
5
5
 
@@ -32,7 +32,7 @@ export interface MessageBarWithAttachMenuProps {
32
32
  onAttachMenuOpenChange?: (isOpen: boolean) => void;
33
33
  }
34
34
 
35
- export interface MessageBarProps extends TextAreaProps {
35
+ export interface MessageBarProps extends Omit<TextAreaProps, 'innerRef'> {
36
36
  /** Callback to get the value of input message by user */
37
37
  onSendMessage: (message: string | number) => void;
38
38
  /** Class Name for the MessageBar component */
@@ -78,6 +78,7 @@ export interface MessageBarProps extends TextAreaProps {
78
78
  onChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, value: string | number) => void;
79
79
  /** Display mode of chatbot, if you want to message bar to resize when the display mode changes */
80
80
  displayMode?: ChatbotDisplayMode;
81
+ /** Whether message bar is compact */
81
82
  isCompact?: boolean;
82
83
  /** Specifies the file types accepted by the attachment upload component.
83
84
  * Files that don't match the accepted types will be disabled in the file picker.
@@ -85,9 +86,11 @@ export interface MessageBarProps extends TextAreaProps {
85
86
  * allowedFileTypes: { 'application/json': ['.json'], 'text/plain': ['.txt'] }
86
87
  **/
87
88
  allowedFileTypes?: Accept;
89
+ /** Ref applied to message bar textarea, for use with focus or other custom behaviors */
90
+ innerRef?: React.Ref<HTMLTextAreaElement>;
88
91
  }
89
92
 
90
- export const MessageBar: FunctionComponent<MessageBarProps> = ({
93
+ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
91
94
  onSendMessage,
92
95
  className,
93
96
  alwayShowSendButton,
@@ -106,6 +109,7 @@ export const MessageBar: FunctionComponent<MessageBarProps> = ({
106
109
  value,
107
110
  isCompact = false,
108
111
  allowedFileTypes,
112
+ innerRef,
109
113
  ...props
110
114
  }: MessageBarProps) => {
111
115
  // Text Input
@@ -113,7 +117,8 @@ export const MessageBar: FunctionComponent<MessageBarProps> = ({
113
117
  const [message, setMessage] = useState<string | number>(value ?? '');
114
118
  const [isListeningMessage, setIsListeningMessage] = useState<boolean>(false);
115
119
  const [hasSentMessage, setHasSentMessage] = useState(false);
116
- const textareaRef = useRef<HTMLTextAreaElement>(null);
120
+ const inputRef = useRef<HTMLTextAreaElement>(null);
121
+ const textareaRef = (innerRef as React.RefObject<HTMLTextAreaElement>) ?? inputRef;
117
122
  const attachButtonRef = useRef<HTMLButtonElement>(null);
118
123
 
119
124
  const topMargin = '1rem';
@@ -391,4 +396,9 @@ export const MessageBar: FunctionComponent<MessageBarProps> = ({
391
396
  return <div className={`pf-chatbot__message-bar ${className ?? ''}`}>{messageBarContents}</div>;
392
397
  };
393
398
 
399
+ const MessageBar = forwardRef((props: MessageBarProps, ref: Ref<HTMLTextAreaElement>) => (
400
+ <MessageBarBase innerRef={ref} {...props} />
401
+ ));
402
+
403
+ export { MessageBar };
394
404
  export default MessageBar;