Fix mobile composer keyboard focus race
- Replace JS-driven collapse state with a primed mobile focus attribute - Simplify keyboard expansion flow and update focus sequencing tests
This commit is contained in:
1 parent
34f4646ccf
commit
699caa754c
3 files changed
+163
-234
No files matched your search
@@ -30,7 +30,6 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { flushSync } from "react-dom";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useDebouncedValue } from "@tanstack/react-pacer";
|
||||
import { projectSearchEntriesQueryOptions } from "~/lib/projectReactQuery";
|
||||
@@ -141,13 +140,6 @@ const runtimeModeConfig: Record<
|
||||
const runtimeModeOptions = Object.keys(runtimeModeConfig) as RuntimeMode[];
|
||||
const COMPOSER_PATH_QUERY_DEBOUNCE_MS = 120;
|
||||
const EMPTY_PROJECT_ENTRIES: ProjectEntry[] = [];
|
||||
const COMPOSER_FLOATING_LAYER_SELECTOR = [
|
||||
'[data-slot="popover-popup"]',
|
||||
'[data-slot="menu-popup"]',
|
||||
'[data-slot="select-popup"]',
|
||||
'[data-slot="combobox-popup"]',
|
||||
'[data-slot="autocomplete-popup"]',
|
||||
].join(",");
|
||||
|
||||
const extendReplacementRangeForTrailingSpace = (
|
||||
text: string,
|
||||
@@ -177,10 +169,6 @@ const terminalContextIdListsEqual = (
|
||||
): boolean =>
|
||||
contexts.length === ids.length && contexts.every((context, index) => context.id === ids[index]);
|
||||
|
||||
function isInsideComposerFloatingLayer(element: Element): boolean {
|
||||
return element.closest(COMPOSER_FLOATING_LAYER_SELECTOR) !== null;
|
||||
}
|
||||
|
||||
const ComposerFooterModeControls = memo(function ComposerFooterModeControls(props: {
|
||||
showInteractionModeToggle: boolean;
|
||||
interactionMode: ProviderInteractionMode;
|
||||
@@ -797,9 +785,13 @@ export const ChatComposer = memo(
|
||||
const [isComposerFooterCompact, setIsComposerFooterCompact] = useState(false);
|
||||
const [isComposerPrimaryActionsCompact, setIsComposerPrimaryActionsCompact] = useState(false);
|
||||
const [isComposerModelPickerOpen, setIsComposerModelPickerOpen] = useState(false);
|
||||
const [isComposerFocused, setIsComposerFocused] = useState(false);
|
||||
const isMobileViewport = useMediaQuery("max-sm");
|
||||
const isComposerCollapsedMobile = isMobileViewport && !isComposerFocused;
|
||||
const mobileCollapsedOnlyClassName =
|
||||
"sm:hidden max-sm:group-focus-within/composer:hidden max-sm:group-data-[mobile-focus-primed=true]/composer:hidden";
|
||||
const mobileExpandedOnlyClassName =
|
||||
"max-sm:hidden max-sm:group-focus-within/composer:block max-sm:group-data-[mobile-focus-primed=true]/composer:block";
|
||||
const mobileExpandedFlexOnlyClassName =
|
||||
"max-sm:hidden max-sm:group-focus-within/composer:flex max-sm:group-data-[mobile-focus-primed=true]/composer:flex";
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Refs
|
||||
@@ -812,10 +804,7 @@ export const ChatComposer = memo(
|
||||
const composerMenuOpenRef = useRef(false);
|
||||
const composerMenuItemsRef = useRef<ComposerCommandItem[]>([]);
|
||||
const activeComposerMenuItemRef = useRef<ComposerCommandItem | null>(null);
|
||||
const composerBlurFrameRef = useRef<number | null>(null);
|
||||
const mobileComposerExpandFrameRef = useRef<number | null>(null);
|
||||
const mobileComposerExpandReleaseFrameRef = useRef<number | null>(null);
|
||||
const mobileComposerExpandInFlightRef = useRef(false);
|
||||
const mobileComposerPrimeReleaseFrameRef = useRef<number | null>(null);
|
||||
const dragDepthRef = useRef(0);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
@@ -960,8 +949,7 @@ export const ChatComposer = memo(
|
||||
isComposerApprovalState ||
|
||||
pendingUserInputs.length > 0 ||
|
||||
(showPlanFollowUpPrompt && activeProposedPlan !== null);
|
||||
const showCollapsedMobilePromptRow =
|
||||
isComposerCollapsedMobile && !isComposerApprovalState && pendingUserInputs.length === 0;
|
||||
const showCollapsedMobilePromptRow = !isComposerApprovalState && pendingUserInputs.length === 0;
|
||||
|
||||
const composerFooterHasWideActions = showPlanFollowUpPrompt || activePendingProgress !== null;
|
||||
const showPlanSidebarToggle = Boolean(activePlan || sidebarProposedPlan || planSidebarOpen);
|
||||
@@ -1057,8 +1045,7 @@ export const ChatComposer = memo(
|
||||
const collapsedComposerPrimaryActionDisabled =
|
||||
phase === "running" || isSendBusy || isConnecting || !composerSendState.hasSendableContent;
|
||||
const collapsedComposerPrimaryActionLabel = "Send message";
|
||||
const showMobilePendingAnswerActions =
|
||||
isMobileViewport && !isComposerCollapsedMobile && pendingPrimaryAction !== null;
|
||||
const showMobilePendingAnswerActions = isMobileViewport && pendingPrimaryAction !== null;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Prompt helpers
|
||||
@@ -1590,15 +1577,15 @@ export const ChatComposer = memo(
|
||||
|
||||
const blurMobileComposerAfterSend = useCallback(() => {
|
||||
if (!isMobileViewport) return;
|
||||
if (composerBlurFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(composerBlurFrameRef.current);
|
||||
composerBlurFrameRef.current = null;
|
||||
if (mobileComposerPrimeReleaseFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerPrimeReleaseFrameRef.current);
|
||||
mobileComposerPrimeReleaseFrameRef.current = null;
|
||||
}
|
||||
composerSurfaceRef.current?.setAttribute("data-mobile-focus-primed", "false");
|
||||
const activeElement = document.activeElement;
|
||||
if (activeElement instanceof HTMLElement) {
|
||||
activeElement.blur();
|
||||
}
|
||||
setIsComposerFocused(false);
|
||||
}, [isMobileViewport]);
|
||||
|
||||
const shouldBlurMobileComposerOnSubmit = useCallback(() => {
|
||||
@@ -1630,39 +1617,22 @@ export const ChatComposer = memo(
|
||||
);
|
||||
const expandMobileComposer = useCallback(() => {
|
||||
expandMobileComposerForKeyboard({
|
||||
cancelPendingBlur: () => {
|
||||
if (composerBlurFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(composerBlurFrameRef.current);
|
||||
composerBlurFrameRef.current = null;
|
||||
}
|
||||
},
|
||||
cancelPendingExpandFocus: () => {
|
||||
if (mobileComposerExpandFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerExpandFrameRef.current);
|
||||
mobileComposerExpandFrameRef.current = null;
|
||||
}
|
||||
},
|
||||
cancelPendingRelease: () => {
|
||||
if (mobileComposerExpandReleaseFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerExpandReleaseFrameRef.current);
|
||||
mobileComposerExpandReleaseFrameRef.current = null;
|
||||
if (mobileComposerPrimeReleaseFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerPrimeReleaseFrameRef.current);
|
||||
mobileComposerPrimeReleaseFrameRef.current = null;
|
||||
}
|
||||
},
|
||||
setExpandInFlight: (inFlight) => {
|
||||
mobileComposerExpandInFlightRef.current = inFlight;
|
||||
},
|
||||
commitExpandedState: () => {
|
||||
flushSync(() => {
|
||||
setIsComposerFocused(true);
|
||||
});
|
||||
primeExpandedState: () => {
|
||||
composerSurfaceRef.current?.setAttribute("data-mobile-focus-primed", "true");
|
||||
},
|
||||
focusEditorAtEnd: () => {
|
||||
composerEditorRef.current?.focusAtEnd();
|
||||
},
|
||||
scheduleRelease: () => {
|
||||
mobileComposerExpandReleaseFrameRef.current = window.requestAnimationFrame(() => {
|
||||
mobileComposerExpandReleaseFrameRef.current = null;
|
||||
mobileComposerExpandInFlightRef.current = false;
|
||||
mobileComposerPrimeReleaseFrameRef.current = window.requestAnimationFrame(() => {
|
||||
mobileComposerPrimeReleaseFrameRef.current = null;
|
||||
composerSurfaceRef.current?.setAttribute("data-mobile-focus-primed", "false");
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -1808,47 +1778,10 @@ export const ChatComposer = memo(
|
||||
const handleImplementPlanInNewThreadPrimaryAction = useCallback(() => {
|
||||
void onImplementPlanInNewThread();
|
||||
}, [onImplementPlanInNewThread]);
|
||||
const scheduleComposerCollapseCheck = useCallback(() => {
|
||||
if (!isMobileViewport) {
|
||||
return;
|
||||
}
|
||||
if (mobileComposerExpandInFlightRef.current) {
|
||||
return;
|
||||
}
|
||||
if (composerBlurFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(composerBlurFrameRef.current);
|
||||
}
|
||||
composerBlurFrameRef.current = window.requestAnimationFrame(() => {
|
||||
composerBlurFrameRef.current = null;
|
||||
if (mobileComposerExpandInFlightRef.current) {
|
||||
return;
|
||||
}
|
||||
const composerSurface = composerSurfaceRef.current;
|
||||
const activeElement = document.activeElement;
|
||||
if (activeElement instanceof Element && isInsideComposerFloatingLayer(activeElement)) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
composerSurface &&
|
||||
activeElement instanceof Node &&
|
||||
composerSurface.contains(activeElement)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setIsComposerFocused(false);
|
||||
});
|
||||
}, [isMobileViewport]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (composerBlurFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(composerBlurFrameRef.current);
|
||||
}
|
||||
if (mobileComposerExpandFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerExpandFrameRef.current);
|
||||
}
|
||||
if (mobileComposerExpandReleaseFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerExpandReleaseFrameRef.current);
|
||||
if (mobileComposerPrimeReleaseFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(mobileComposerPrimeReleaseFrameRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
@@ -1981,63 +1914,62 @@ export const ChatComposer = memo(
|
||||
>
|
||||
<div
|
||||
ref={composerSurfaceRef}
|
||||
data-chat-composer-mobile-collapsed={isComposerCollapsedMobile ? "true" : "false"}
|
||||
data-mobile-focus-primed="false"
|
||||
className={cn(
|
||||
"rounded-[20px] border bg-card transition-colors duration-200 has-focus-visible:border-ring/45",
|
||||
"group/composer rounded-[20px] border bg-card transition-colors duration-200 has-focus-visible:border-ring/45",
|
||||
isDragOverComposer ? "border-primary/70 bg-accent/30" : "border-border",
|
||||
environmentUnavailable ? "opacity-75" : null,
|
||||
composerProviderState.composerSurfaceClassName,
|
||||
)}
|
||||
onFocusCapture={(event) => {
|
||||
const activeElement = event.target;
|
||||
if (
|
||||
isComposerCollapsedMobile &&
|
||||
activeElement instanceof HTMLElement &&
|
||||
activeElement.closest('[data-chat-composer-collapsed-controls="true"]')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (composerBlurFrameRef.current !== null) {
|
||||
window.cancelAnimationFrame(composerBlurFrameRef.current);
|
||||
composerBlurFrameRef.current = null;
|
||||
}
|
||||
setIsComposerFocused(true);
|
||||
}}
|
||||
onBlurCapture={() => {
|
||||
scheduleComposerCollapseCheck();
|
||||
}}
|
||||
>
|
||||
{!isComposerCollapsedMobile &&
|
||||
(activePendingApproval ? (
|
||||
<div className="rounded-t-[19px] border-b border-border/65 bg-muted/20">
|
||||
<ComposerPendingApprovalPanel
|
||||
approval={activePendingApproval}
|
||||
pendingCount={pendingApprovals.length}
|
||||
/>
|
||||
</div>
|
||||
) : pendingUserInputs.length > 0 ? (
|
||||
<div className="rounded-t-[19px] border-b border-border/65 bg-muted/20">
|
||||
<ComposerPendingUserInputPanel
|
||||
pendingUserInputs={pendingUserInputs}
|
||||
respondingRequestIds={respondingRequestIds}
|
||||
answers={activePendingDraftAnswers}
|
||||
questionIndex={activePendingQuestionIndex}
|
||||
onToggleOption={onSelectActivePendingUserInputOption}
|
||||
onAdvance={onAdvanceActivePendingUserInput}
|
||||
/>
|
||||
</div>
|
||||
) : showPlanFollowUpPrompt && activeProposedPlan ? (
|
||||
<div className="rounded-t-[19px] border-b border-border/65 bg-muted/20">
|
||||
<ComposerPlanFollowUpBanner
|
||||
key={activeProposedPlan.id}
|
||||
planTitle={proposedPlanTitle(activeProposedPlan.planMarkdown) ?? null}
|
||||
/>
|
||||
</div>
|
||||
) : null)}
|
||||
|
||||
{isComposerCollapsedMobile && activePendingApproval ? (
|
||||
{activePendingApproval ? (
|
||||
<div
|
||||
className="rounded-t-[19px] border-b border-border/65 bg-muted/20"
|
||||
className={cn(
|
||||
"rounded-t-[19px] border-b border-border/65 bg-muted/20",
|
||||
mobileExpandedOnlyClassName,
|
||||
)}
|
||||
>
|
||||
<ComposerPendingApprovalPanel
|
||||
approval={activePendingApproval}
|
||||
pendingCount={pendingApprovals.length}
|
||||
/>
|
||||
</div>
|
||||
) : pendingUserInputs.length > 0 ? (
|
||||
<div
|
||||
className={cn(
|
||||
"rounded-t-[19px] border-b border-border/65 bg-muted/20",
|
||||
mobileExpandedOnlyClassName,
|
||||
)}
|
||||
>
|
||||
<ComposerPendingUserInputPanel
|
||||
pendingUserInputs={pendingUserInputs}
|
||||
respondingRequestIds={respondingRequestIds}
|
||||
answers={activePendingDraftAnswers}
|
||||
questionIndex={activePendingQuestionIndex}
|
||||
onToggleOption={onSelectActivePendingUserInputOption}
|
||||
onAdvance={onAdvanceActivePendingUserInput}
|
||||
/>
|
||||
</div>
|
||||
) : showPlanFollowUpPrompt && activeProposedPlan ? (
|
||||
<div
|
||||
className={cn(
|
||||
"rounded-t-[19px] border-b border-border/65 bg-muted/20",
|
||||
mobileExpandedOnlyClassName,
|
||||
)}
|
||||
>
|
||||
<ComposerPlanFollowUpBanner
|
||||
key={activeProposedPlan.id}
|
||||
planTitle={proposedPlanTitle(activeProposedPlan.planMarkdown) ?? null}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{activePendingApproval ? (
|
||||
<div
|
||||
className={cn(
|
||||
"rounded-t-[19px] border-b border-border/65 bg-muted/20",
|
||||
mobileCollapsedOnlyClassName,
|
||||
)}
|
||||
data-chat-composer-collapsed-controls="true"
|
||||
>
|
||||
<ComposerPendingApprovalPanel
|
||||
@@ -2052,9 +1984,12 @@ export const ChatComposer = memo(
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : isComposerCollapsedMobile && pendingUserInputs.length > 0 ? (
|
||||
) : pendingUserInputs.length > 0 ? (
|
||||
<div
|
||||
className="rounded-t-[19px] border-b border-border/65 bg-muted/20"
|
||||
className={cn(
|
||||
"rounded-t-[19px] border-b border-border/65 bg-muted/20",
|
||||
mobileCollapsedOnlyClassName,
|
||||
)}
|
||||
data-chat-composer-collapsed-controls="true"
|
||||
>
|
||||
<ComposerPendingUserInputPanel
|
||||
@@ -2115,7 +2050,12 @@ export const ChatComposer = memo(
|
||||
) : null}
|
||||
|
||||
{showCollapsedMobilePromptRow ? (
|
||||
<div className="flex items-center justify-between gap-2 px-3 py-2">
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center justify-between gap-2 px-3 py-2",
|
||||
mobileCollapsedOnlyClassName,
|
||||
)}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
@@ -2164,7 +2104,7 @@ export const ChatComposer = memo(
|
||||
className={cn(
|
||||
"relative px-3 pb-2 sm:px-4",
|
||||
hasComposerHeader ? "pt-2.5 sm:pt-3" : "pt-3.5 sm:pt-4",
|
||||
isComposerCollapsedMobile && "hidden",
|
||||
mobileExpandedOnlyClassName,
|
||||
)}
|
||||
>
|
||||
{composerMenuOpen && !isComposerApprovalState && (
|
||||
@@ -2186,73 +2126,72 @@ export const ChatComposer = memo(
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isComposerCollapsedMobile &&
|
||||
!isComposerApprovalState &&
|
||||
pendingUserInputs.length === 0 &&
|
||||
composerImages.length > 0 && (
|
||||
<div className="mb-3 flex flex-wrap gap-2">
|
||||
{composerImages.map((image) => (
|
||||
<div
|
||||
key={image.id}
|
||||
className="relative h-16 w-16 overflow-hidden rounded-lg border border-border/80 bg-background"
|
||||
>
|
||||
{image.previewUrl ? (
|
||||
<button
|
||||
type="button"
|
||||
className="h-full w-full cursor-zoom-in"
|
||||
aria-label={`Preview ${image.name}`}
|
||||
onClick={() => {
|
||||
const preview = buildExpandedImagePreview(composerImages, image.id);
|
||||
if (!preview) return;
|
||||
onExpandImage(preview);
|
||||
}}
|
||||
>
|
||||
<img
|
||||
src={image.previewUrl}
|
||||
alt={image.name}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
</button>
|
||||
) : (
|
||||
<div className="flex h-full w-full items-center justify-center px-1 text-center text-[10px] text-muted-foreground/70">
|
||||
{image.name}
|
||||
</div>
|
||||
)}
|
||||
{nonPersistedComposerImageIdSet.has(image.id) && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<span
|
||||
role="img"
|
||||
aria-label="Draft attachment may not persist"
|
||||
className="absolute left-1 top-1 inline-flex items-center justify-center rounded bg-background/85 p-0.5 text-amber-600"
|
||||
>
|
||||
<CircleAlertIcon className="size-3" />
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<TooltipPopup
|
||||
side="top"
|
||||
className="max-w-64 whitespace-normal leading-tight"
|
||||
>
|
||||
Draft attachment could not be saved locally and may be lost on
|
||||
navigation.
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="absolute right-1 top-1 bg-background/80 hover:bg-background/90"
|
||||
onClick={() => removeComposerImage(image.id)}
|
||||
aria-label={`Remove ${image.name}`}
|
||||
{!isComposerApprovalState &&
|
||||
pendingUserInputs.length === 0 &&
|
||||
composerImages.length > 0 ? (
|
||||
<div className="mb-3 flex flex-wrap gap-2">
|
||||
{composerImages.map((image) => (
|
||||
<div
|
||||
key={image.id}
|
||||
className="relative h-16 w-16 overflow-hidden rounded-lg border border-border/80 bg-background"
|
||||
>
|
||||
{image.previewUrl ? (
|
||||
<button
|
||||
type="button"
|
||||
className="h-full w-full cursor-zoom-in"
|
||||
aria-label={`Preview ${image.name}`}
|
||||
onClick={() => {
|
||||
const preview = buildExpandedImagePreview(composerImages, image.id);
|
||||
if (!preview) return;
|
||||
onExpandImage(preview);
|
||||
}}
|
||||
>
|
||||
<XIcon />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<img
|
||||
src={image.previewUrl}
|
||||
alt={image.name}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
</button>
|
||||
) : (
|
||||
<div className="flex h-full w-full items-center justify-center px-1 text-center text-[10px] text-muted-foreground/70">
|
||||
{image.name}
|
||||
</div>
|
||||
)}
|
||||
{nonPersistedComposerImageIdSet.has(image.id) && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<span
|
||||
role="img"
|
||||
aria-label="Draft attachment may not persist"
|
||||
className="absolute left-1 top-1 inline-flex items-center justify-center rounded bg-background/85 p-0.5 text-amber-600"
|
||||
>
|
||||
<CircleAlertIcon className="size-3" />
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
<TooltipPopup
|
||||
side="top"
|
||||
className="max-w-64 whitespace-normal leading-tight"
|
||||
>
|
||||
Draft attachment could not be saved locally and may be lost on
|
||||
navigation.
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="absolute right-1 top-1 bg-background/80 hover:bg-background/90"
|
||||
onClick={() => removeComposerImage(image.id)}
|
||||
aria-label={`Remove ${image.name}`}
|
||||
>
|
||||
<XIcon />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="relative">
|
||||
<ComposerPromptEditor
|
||||
@@ -2327,8 +2266,13 @@ export const ChatComposer = memo(
|
||||
</div>
|
||||
|
||||
{/* Bottom toolbar */}
|
||||
{isComposerCollapsedMobile ? null : activePendingApproval ? (
|
||||
<div className="flex items-center justify-end gap-2 px-2.5 pb-2.5 sm:px-3 sm:pb-3">
|
||||
{activePendingApproval ? (
|
||||
<div
|
||||
className={cn(
|
||||
"flex items-center justify-end gap-2 px-2.5 pb-2.5 sm:px-3 sm:pb-3",
|
||||
mobileExpandedFlexOnlyClassName,
|
||||
)}
|
||||
>
|
||||
<ComposerPendingApprovalActions
|
||||
requestId={activePendingApproval.requestId}
|
||||
isResponding={respondingRequestIds.includes(activePendingApproval.requestId)}
|
||||
@@ -2342,7 +2286,9 @@ export const ChatComposer = memo(
|
||||
className={cn(
|
||||
"flex min-w-0 flex-nowrap items-center justify-between gap-2 overflow-visible px-2.5 pb-2.5 sm:px-3 sm:pb-3",
|
||||
isComposerFooterCompact ? "gap-1.5" : "gap-2 sm:gap-0",
|
||||
showMobilePendingAnswerActions && "hidden sm:flex",
|
||||
showMobilePendingAnswerActions
|
||||
? "max-sm:hidden"
|
||||
: mobileExpandedFlexOnlyClassName,
|
||||
)}
|
||||
>
|
||||
<div className="-m-1 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto p-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
|
||||
|
||||
@@ -6,23 +6,12 @@ describe("expandMobileComposerForKeyboard", () => {
|
||||
const calls: string[] = [];
|
||||
|
||||
expandMobileComposerForKeyboard({
|
||||
cancelPendingBlur: vi.fn(() => calls.push("cancel-blur")),
|
||||
cancelPendingExpandFocus: vi.fn(() => calls.push("cancel-expand-focus")),
|
||||
cancelPendingRelease: vi.fn(() => calls.push("cancel-release")),
|
||||
setExpandInFlight: vi.fn((inFlight) => calls.push(`in-flight:${inFlight}`)),
|
||||
commitExpandedState: vi.fn(() => calls.push("commit-expanded")),
|
||||
primeExpandedState: vi.fn(() => calls.push("prime-expanded")),
|
||||
focusEditorAtEnd: vi.fn(() => calls.push("focus")),
|
||||
scheduleRelease: vi.fn(() => calls.push("schedule-release")),
|
||||
});
|
||||
|
||||
expect(calls).toEqual([
|
||||
"cancel-blur",
|
||||
"cancel-expand-focus",
|
||||
"cancel-release",
|
||||
"in-flight:true",
|
||||
"commit-expanded",
|
||||
"focus",
|
||||
"schedule-release",
|
||||
]);
|
||||
expect(calls).toEqual(["cancel-release", "prime-expanded", "focus", "schedule-release"]);
|
||||
});
|
||||
});
|
||||
@@ -1,19 +1,13 @@
|
||||
export interface MobileComposerExpandOptions {
|
||||
cancelPendingBlur: () => void;
|
||||
cancelPendingExpandFocus: () => void;
|
||||
cancelPendingRelease: () => void;
|
||||
setExpandInFlight: (inFlight: boolean) => void;
|
||||
commitExpandedState: () => void;
|
||||
primeExpandedState: () => void;
|
||||
focusEditorAtEnd: () => void;
|
||||
scheduleRelease: () => void;
|
||||
}
|
||||
|
||||
export function expandMobileComposerForKeyboard(options: MobileComposerExpandOptions) {
|
||||
options.cancelPendingBlur();
|
||||
options.cancelPendingExpandFocus();
|
||||
options.cancelPendingRelease();
|
||||
options.setExpandInFlight(true);
|
||||
options.commitExpandedState();
|
||||
options.primeExpandedState();
|
||||
options.focusEditorAtEnd();
|
||||
options.scheduleRelease();
|
||||
}
|
||||
Reference in new issue
Block a user