From 49b086cef3025f66740d7db8cada6e0038fd6fc3 Mon Sep 17 00:00:00 2001 From: Biki Kalita <86558912+Biki-dev@users.noreply.github.com> Date: Mon, 29 Dec 2025 09:24:13 +0530 Subject: [PATCH] fix: make model selector label responsive to panel width (#443) * fix: make model selector label responsive to panel width * Apply suggestion from @DayuanJiang Co-authored-by: Dayuan Jiang <34411969+DayuanJiang@users.noreply.github.com> --------- Co-authored-by: Dayuan Jiang <34411969+DayuanJiang@users.noreply.github.com> --- components/model-selector.tsx | 303 ++++++++++++++++++++-------------- 1 file changed, 179 insertions(+), 124 deletions(-) diff --git a/components/model-selector.tsx b/components/model-selector.tsx index c67759b..370d40c 100644 --- a/components/model-selector.tsx +++ b/components/model-selector.tsx @@ -8,7 +8,7 @@ import { Server, Settings2, } from "lucide-react" -import { useMemo, useState } from "react" +import { useEffect, useMemo, useRef, useState } from "react" import { ModelSelectorContent, ModelSelectorEmpty, @@ -114,134 +114,189 @@ export function ModelSelector({ ? `${selectedModel.modelId} ${dict.modelConfig.clickToChange}` : `${dict.modelConfig.usingServerDefault} ${dict.modelConfig.clickToChange}` + const wrapperRef = useRef(null) + const [showLabel, setShowLabel] = useState(true) + + // Threshold (px) under which we hide the label (tweak as needed) + const HIDE_THRESHOLD = 240 + const SHOW_THRESHOLD = 260 + useEffect(() => { + const el = wrapperRef.current + if (!el) return + + const target = el.parentElement ?? el + + const ro = new ResizeObserver((entries) => { + for (const entry of entries) { + const width = entry.contentRect.width + setShowLabel((prev) => { + // if currently showing and width dropped below hide threshold -> hide + if (prev && width <= HIDE_THRESHOLD) return false + // if currently hidden and width rose above show threshold -> show + if (!prev && width >= SHOW_THRESHOLD) return true + // otherwise keep previous state (hysteresis) + return prev + }) + } + }) + + ro.observe(target) + + const initialWidth = target.getBoundingClientRect().width + setShowLabel(initialWidth >= SHOW_THRESHOLD) + + return () => ro.disconnect() + }, []) + return ( - - - - - - {selectedModel - ? selectedModel.modelId - : dict.modelConfig.default} - - - - - - - - - {displayModels.length === 0 && models.length > 0 - ? dict.modelConfig.noVerifiedModels - : dict.modelConfig.noModelsFound} - +
+ + + + + {/* show/hide visible label based on measured width */} + {showLabel ? ( + + {selectedModel + ? selectedModel.modelId + : dict.modelConfig.default} + + ) : ( + // Keep an sr-only label for screen readers when hidden + + {selectedModel + ? selectedModel.modelId + : dict.modelConfig.default} + + )} + + + - {/* Server Default Option */} - - - + + + + {displayModels.length === 0 && models.length > 0 + ? dict.modelConfig.noVerifiedModels + : dict.modelConfig.noModelsFound} + + + {/* Server Default Option */} + + - - - {dict.modelConfig.serverDefault} - - - - - {/* Configured Models by Provider */} - {Array.from(groupedModels.entries()).map( - ([ - providerLabel, - { provider, models: providerModels }, - ]) => ( - - {providerModels.map((model) => ( - handleSelect(model.id)} - className="cursor-pointer" - > - - - - {model.modelId} - - {model.validated !== true && ( - - - - )} - - ))} - - ), - )} + + + + {dict.modelConfig.serverDefault} + + + - {/* Configure Option */} - - - - - - {dict.modelConfig.configureModels} - - - - {/* Info text */} -
- {showUnvalidatedModels - ? dict.modelConfig.allModelsShown - : dict.modelConfig.onlyVerifiedShown} -
- - -
+ {/* Configured Models by Provider */} + {Array.from(groupedModels.entries()).map( + ([ + providerLabel, + { provider, models: providerModels }, + ]) => ( + + {providerModels.map((model) => ( + + handleSelect(model.id) + } + className="cursor-pointer" + > + + + + {model.modelId} + + {model.validated !== true && ( + + + + )} + + ))} + + ), + )} + + {/* Configure Option */} + + + + + + {dict.modelConfig.configureModels} + + + + {/* Info text */} +
+ {showUnvalidatedModels + ? dict.modelConfig.allModelsShown + : dict.modelConfig.onlyVerifiedShown} +
+ + + +
) }