Skip to content

Commit 755253b

Browse files
saphidclaude
authored andcommitted
fix(web): size the model picker to its content
The model picker popover was always 346px tall, leaving a large empty area when a provider or favorites had only a few models. It now fits its rows and the provider sidebar, capped at the same height, and holds its height while searching so the input doesn't jump when it opens upward. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 31a9da1 commit 755253b

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

‎apps/web/src/components/chat/ModelPickerContent.tsx‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export function adjacentModelPickerProvider(input: {
144144
}
145145

146146
const EMPTY_MODEL_JUMP_LABELS = new Map<string, string>();
147+
const MODEL_LIST_ESTIMATED_ITEM_SIZE = 52;
147148

148149
function ModelListSeparator() {
149150
return <div className="h-0.5" />;
@@ -197,6 +198,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
197198
const [showBottomScrollFade, setShowBottomScrollFade] = useState(false);
198199
const searchInputRef = useRef<HTMLInputElement>(null);
199200
const modelListRef = useRef<LegendListRef | null>(null);
201+
const pickerContentRef = useRef<HTMLDivElement>(null);
200202
const highlightedModelKeyRef = useRef<string | null>(null);
201203
const favorites = useClientSettings((s) => s.favorites ?? []);
202204
const activeEntry = props.instanceEntries.find(
@@ -699,6 +701,17 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
699701
),
700702
[visibleModels],
701703
);
704+
const [modelListContentSize, setModelListContentSize] = useState(
705+
() => filteredItemKeys.length * MODEL_LIST_ESTIMATED_ITEM_SIZE,
706+
);
707+
const [searchMinHeight, setSearchMinHeight] = useState(0);
708+
useLayoutEffect(
709+
() => modelListRef.current?.getState().listen("totalSize", setModelListContentSize),
710+
[],
711+
);
712+
// Fit the list to its rows plus the combobox list `py-1` and LegendList `py-1.5`.
713+
const modelListHeight =
714+
filteredItemKeys.length === 0 ? 0 : `calc(${modelListContentSize}px + var(--spacing) * 5)`;
702715
const updateModelListScrollFades = useCallback(() => {
703716
const scrollElement = modelListRef.current?.getScrollableNode();
704717
if (!(scrollElement instanceof HTMLElement)) {
@@ -815,7 +828,10 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
815828
return (
816829
<TooltipProvider delay={0}>
817830
<div
818-
className="relative flex h-screen max-h-86.5 w-screen max-w-90 flex-row overflow-hidden"
831+
ref={pickerContentRef}
832+
className="relative flex max-h-86.5 w-screen max-w-90 flex-row overflow-hidden"
833+
// Don't shrink while searching, so the input stays put when the popover opens upward.
834+
style={isSearching ? { minHeight: searchMinHeight } : undefined}
819835
data-model-picker-content="true"
820836
>
821837
{/* Sidebar */}
@@ -890,7 +906,11 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
890906
ref={searchInputRef}
891907
placeholder="Search models..."
892908
value={searchQuery}
893-
onChange={(e) => setSearchQuery(e.target.value)}
909+
onChange={(e) => {
910+
const height = pickerContentRef.current?.offsetHeight ?? 0;
911+
setSearchMinHeight((min) => (isSearching ? Math.max(min, height) : height));
912+
setSearchQuery(e.target.value);
913+
}}
894914
onKeyDown={(e) => {
895915
if (
896916
showSidebar &&
@@ -944,7 +964,10 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
944964
/>
945965

946966
{/* Model list */}
947-
<div className="relative min-h-0 flex-1 overflow-hidden pr-px">
967+
<div
968+
className="relative min-h-0 overflow-hidden pr-px"
969+
style={{ height: modelListHeight }}
970+
>
948971
<ComboboxListVirtualized>
949972
<LegendList<string>
950973
ref={modelListRef}
@@ -1013,7 +1036,7 @@ export const ModelPickerContent = memo(function ModelPickerContent(props: {
10131036
/>
10141037
);
10151038
}}
1016-
estimatedItemSize={52}
1039+
estimatedItemSize={MODEL_LIST_ESTIMATED_ITEM_SIZE}
10171040
drawDistance={480}
10181041
recycleItems
10191042
contentContainerClassName="pl-2 pr-px"

0 commit comments

Comments
 (0)