Skip to content

Commit

Permalink
feat: resizable input
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 committed May 20, 2024
1 parent 5ceb124 commit 5bbc4bf
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/roomkit-react/src/Prebuilt/components/Chat/ChatFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ export const ChatFooter = ({ onSend, children }: { onSend: (count: number) => vo
}
}
}, [defaultSelection, selectedPeer, selectedRole, setRoleSelector, isMobile, isLandscapeHLSStream, elements?.chat]);

const resetInputHeight = () => {
if (inputRef.current) {
inputRef.current.style.height = `${Math.max(32, inputRef.current.value ? inputRef.current.scrollHeight : 0)}px`;
}
};

const sendMessage = useCallback(async () => {
const message = inputRef?.current?.value;
if (!message || !message.trim().length) {
Expand All @@ -116,6 +123,7 @@ export const ChatFooter = ({ onSend, children }: { onSend: (count: number) => vo
await hmsActions.sendBroadcastMessage(message);
}
inputRef.current.value = '';
resetInputHeight();
setTimeout(() => {
onSend(1);
}, 0);
Expand Down Expand Up @@ -197,11 +205,10 @@ export const ChatFooter = ({ onSend, children }: { onSend: (count: number) => vo
{selection && (
<Flex align="center" css={{ gap: '$4', w: '100%' }}>
<Flex
align="center"
align="end"
css={{
bg: isOverlayChat && isMobile ? '$surface_dim' : '$surface_default',
minHeight: '$16',
maxHeight: '$24',
position: 'relative',
py: '$6',
pl: '$8',
Expand Down Expand Up @@ -238,6 +245,11 @@ export const ChatFooter = ({ onSend, children }: { onSend: (count: number) => vo
}}
autoComplete="off"
aria-autocomplete="none"
onChange={e => {
const element = e.target;
element.style.height = `${Math.min(element.scrollHeight, 24 * 4)}px`;
}}
onBlur={resetInputHeight}
onPaste={e => e.stopPropagation()}
onCut={e => e.stopPropagation()}
onCopy={e => e.stopPropagation()}
Expand Down

0 comments on commit 5bbc4bf

Please sign in to comment.