Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a max length for the input #225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ type Props = {
sendMessage: (event: any) => void;
buttonAlt: string;
onTextInputChange?: (event: any) => void;
maxLength: number;
}

function Sender({ sendMessage, placeholder, disabledInput, autofocus, onTextInputChange, buttonAlt }: Props) {
function Sender({ sendMessage, placeholder, disabledInput, autofocus, onTextInputChange, buttonAlt, maxLength }: Props) {
const showChat = useSelector((state: GlobalState) => state.behavior.showChat);
const inputRef = useRef(null);
// @ts-ignore
Expand All @@ -34,6 +35,7 @@ function Sender({ sendMessage, placeholder, disabledInput, autofocus, onTextInpu
autoFocus={autofocus}
autoComplete="off"
onChange={onTextInputChange}
maxLength={maxLength}
/>
<button type="submit" className="rcw-send">
<img src={send} className="rcw-send-icon" alt={buttonAlt} />
Expand Down
5 changes: 4 additions & 1 deletion src/components/Widget/components/Conversation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Props = {
onTextInputChange?: (event: any) => void;
sendButtonAlt: string;
showTimeStamp: boolean;
maxLength: number;
};

function Conversation({
Expand All @@ -43,7 +44,8 @@ function Conversation({
onQuickButtonClicked,
onTextInputChange,
sendButtonAlt,
showTimeStamp
showTimeStamp,
maxLength
}: Props) {
return (
<div className={cn('rcw-conversation-container', className)} aria-live="polite">
Expand All @@ -63,6 +65,7 @@ function Conversation({
autofocus={autofocus}
onTextInputChange={onTextInputChange}
buttonAlt={sendButtonAlt}
maxLength={maxLength}
/>
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions src/components/Widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Props = {
imagePreview?: boolean;
zoomStep?: number;
handleSubmit?: AnyFunction;
maxLength: number;
}

function Widget({
Expand All @@ -49,6 +50,7 @@ function Widget({
showTimeStamp,
imagePreview,
zoomStep,
maxLength,
handleSubmit
}: Props) {
const dispatch = useDispatch();
Expand Down Expand Up @@ -98,6 +100,7 @@ function Widget({
showTimeStamp={showTimeStamp}
imagePreview={imagePreview}
zoomStep={zoomStep}
maxLength={maxLength}
/>
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Widget/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Props = {
showTimeStamp: boolean;
imagePreview?: boolean;
zoomStep?: number;
maxLength: number;
}

function WidgetLayout({
Expand All @@ -56,6 +57,7 @@ function WidgetLayout({
showTimeStamp,
imagePreview,
zoomStep,
maxLength,
}: Props) {
const dispatch = useDispatch();
const { dissableInput, showChat, visible } = useSelector((state: GlobalState) => ({
Expand Down Expand Up @@ -131,6 +133,7 @@ function WidgetLayout({
onTextInputChange={onTextInputChange}
sendButtonAlt={sendButtonAlt}
showTimeStamp={showTimeStamp}
maxLength={maxLength}
/>
}
{customLauncher ?
Expand Down
4 changes: 4 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Props = {
imagePreview?: boolean;
zoomStep?: number;
handleSubmit?: AnyFunction;
maxLength: number;
} & typeof defaultProps;

function ConnectedWidget({
Expand All @@ -50,6 +51,7 @@ function ConnectedWidget({
showTimeStamp,
imagePreview,
zoomStep,
maxLength,
handleSubmit
}: Props) {
return (
Expand All @@ -75,6 +77,7 @@ function ConnectedWidget({
imagePreview={imagePreview}
zoomStep={zoomStep}
handleSubmit={handleSubmit}
maxLength={maxLength}
/>
</Provider>
);
Expand All @@ -94,6 +97,7 @@ const defaultProps = {
showTimeStamp: true,
imagePreview: false,
zoomStep: 80,
maxLength: -1
};
ConnectedWidget.defaultProps = defaultProps;

Expand Down