Skip to content

Commit e689e69

Browse files
committed
Conditionally update border-radius on textarea
1 parent 47d6fc0 commit e689e69

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

packages/module/src/MessageBar/MessageBar.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@
156156
}
157157
}
158158

159+
// ============================================================================
160+
// Multiline textarea styles (2+ lines)
161+
// ============================================================================
162+
.pf-chatbot__message-bar.pf-m-multiline {
163+
border-radius: calc(var(--pf-t--global--border--radius--small) * 2);
164+
}
165+
159166
// ============================================================================
160167
// High contrast styles
161168
// ============================================================================

packages/module/src/MessageBar/MessageBar.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
161161
const [isListeningMessage, setIsListeningMessage] = useState<boolean>(false);
162162
const [hasSentMessage, setHasSentMessage] = useState(false);
163163
const [isComposing, setIsComposing] = useState(false);
164+
const [isMultiline, setIsMultiline] = useState(false);
164165
const inputRef = useRef<HTMLTextAreaElement>(null);
165166
const textareaRef = (innerRef as React.RefObject<HTMLTextAreaElement>) ?? inputRef;
166167
const attachButtonRef = useRef<HTMLButtonElement>(null);
@@ -209,6 +210,19 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
209210
return lines > 2;
210211
};
211212

213+
const checkIfMultiline = useCallback(
214+
(field: HTMLTextAreaElement) => {
215+
const parent = field.parentElement;
216+
const grandparent = parent?.parentElement;
217+
if (grandparent) {
218+
const containerHeight = grandparent.offsetHeight;
219+
const threshold = isCompact ? 56 : 70;
220+
setIsMultiline(containerHeight > threshold);
221+
}
222+
},
223+
[isCompact]
224+
);
225+
212226
const setAutoWidth = useCallback((field: HTMLTextAreaElement) => {
213227
const parent = field.parentElement;
214228
if (parent) {
@@ -263,12 +277,14 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
263277
if (field) {
264278
if (field.value === '') {
265279
setInitialLineHeight(field);
280+
setIsMultiline(false);
266281
} else {
267282
setAutoHeight(field);
268283
setAutoWidth(field);
284+
checkIfMultiline(field);
269285
}
270286
}
271-
}, [displayMode, message, setAutoWidth]);
287+
}, [displayMode, message, setAutoWidth, checkIfMultiline]);
272288

273289
useEffect(() => {
274290
const field = textareaRef.current;
@@ -284,13 +300,15 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
284300
if (textareaRef.current) {
285301
if (event.target.value === '') {
286302
setInitialLineHeight(textareaRef.current);
303+
setIsMultiline(false);
287304
} else {
288305
setAutoHeight(textareaRef.current);
306+
checkIfMultiline(textareaRef.current);
289307
}
290308
}
291309
setMessage(event.target.value);
292310
},
293-
[onChange]
311+
[onChange, checkIfMultiline]
294312
);
295313

296314
// Handle sending message
@@ -453,7 +471,7 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
453471
return (
454472
<AttachMenu
455473
toggle={(toggleRef) => (
456-
<div ref={toggleRef} className={`pf-chatbot__message-bar ${className ?? ''}`}>
474+
<div ref={toggleRef} className={css('pf-chatbot__message-bar', isMultiline && 'pf-m-multiline', className)}>
457475
{messageBarContents}
458476
</div>
459477
)}
@@ -481,6 +499,7 @@ export const MessageBarBase: FunctionComponent<MessageBarProps> = ({
481499
isPrimary && 'pf-m-primary',
482500
hasAiIndicator && 'pf-v6-m-ai-indicator',
483501
isThinking && 'pf-v6-m-thinking',
502+
isMultiline && 'pf-m-multiline',
484503
className
485504
)}
486505
>

0 commit comments

Comments
 (0)