Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🎚️ refactor: Give InputNumber an Option Variant for Setting Values (#16831)

Marco Berettad397ecc9fffd
diff --git a/client/src/components/Endpoints/Settings/Advanced.tsx b/client/src/components/Endpoints/Settings/Advanced.tsx
index 9668b0b57e..292b78a71f 100644
--- a/client/src/components/Endpoints/Settings/Advanced.tsx
+++ b/client/src/components/Endpoints/Settings/Advanced.tsx
@@ -137,13 +137,8 @@ export default function Settings({
min={0}
step={0.01}
controls={false}
- className={cn(
- defaultTextProps,
- cn(
- optionText,
- 'reset-rc-number-input reset-rc-number-input-text-right group-hover/temp:border-border-light h-auto w-12 border-0',
- ),
- )}
+ variant="option"
+ className="w-12"
/>
</div>
<Slider
@@ -178,13 +173,8 @@ export default function Settings({
min={0}
step={0.01}
controls={false}
- className={cn(
- defaultTextProps,
- cn(
- optionText,
- 'reset-rc-number-input reset-rc-number-input-text-right group-hover/temp:border-border-light h-auto w-12 border-0',
- ),
- )}
+ variant="option"
+ className="w-12"
/>
</div>
<Slider
@@ -220,13 +210,8 @@ export default function Settings({
min={-2}
step={0.01}
controls={false}
- className={cn(
- defaultTextProps,
- cn(
- optionText,
- 'reset-rc-number-input reset-rc-number-input-text-right group-hover/temp:border-border-light h-auto w-12 border-0',
- ),
- )}
+ variant="option"
+ className="w-12"
/>
</div>
<Slider
@@ -262,13 +247,8 @@ export default function Settings({
min={-2}
step={0.01}
controls={false}
- className={cn(
- defaultTextProps,
- cn(
- optionText,
- 'reset-rc-number-input reset-rc-number-input-text-right group-hover/temp:border-border-light h-auto w-12 border-0',
- ),
- )}
+ variant="option"
+ className="w-12"
/>
</div>
<Slider
diff --git a/client/src/components/Nav/SettingsTabs/Speech/STT/AutoSendTextSelector.tsx b/client/src/components/Nav/SettingsTabs/Speech/STT/AutoSendTextSelector.tsx
index 2913e021a5..5b93dda1dd 100644
--- a/client/src/components/Nav/SettingsTabs/Speech/STT/AutoSendTextSelector.tsx
+++ b/client/src/components/Nav/SettingsTabs/Speech/STT/AutoSendTextSelector.tsx
@@ -1,7 +1,6 @@
import React, { useState, useEffect } from 'react';
import { useRecoilState, useRecoilValue } from 'recoil';
import { Slider, InputNumber, Switch } from '@librechat/client';
-import { cn, defaultTextProps, optionText } from '~/utils/';
import { useLocalize } from '~/hooks';
import store from '~/store';
@@ -70,7 +69,7 @@ export default function AutoSendTextSelector() {
{isEnabled && (
<div className="mt-2 flex items-center justify-between">
<div className="flex items-center justify-between">
- <div id="auto-send-delay-label" className="text-sm text-text-secondary">
+ <div id="auto-send-delay-label" className="text-text-secondary text-sm">
{localize('com_nav_setting_delay')}
</div>
</div>
@@ -99,13 +98,8 @@ export default function AutoSendTextSelector() {
min={0}
max={60}
aria-labelledby="auto-send-delay-label"
- className={cn(
- defaultTextProps,
- cn(
- optionText,
- 'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-border-light',
- ),
- )}
+ variant="option"
+ className="w-12"
/>
</div>
</div>
diff --git a/client/src/components/Nav/SettingsTabs/Speech/STT/DecibelSelector.tsx b/client/src/components/Nav/SettingsTabs/Speech/STT/DecibelSelector.tsx
index de83f0b6e6..19fe9bcc7d 100755
--- a/client/src/components/Nav/SettingsTabs/Speech/STT/DecibelSelector.tsx
+++ b/client/src/components/Nav/SettingsTabs/Speech/STT/DecibelSelector.tsx
@@ -1,7 +1,6 @@
import React from 'react';
import { Slider, InputNumber } from '@librechat/client';
import { useRecoilState, useRecoilValue } from 'recoil';
-import { cn, defaultTextProps, optionText } from '~/utils';
import { useLocalize } from '~/hooks';
import store from '~/store';
@@ -15,7 +14,7 @@ export default function DecibelSelector() {
<div className="flex items-center justify-between">
<div id="decibel-selector-label">{localize('com_nav_db_sensitivity')}</div>
<div className="w-2" />
- <small className="opacity-40 high-contrast:opacity-100">
+ <small className="high-contrast:opacity-100 opacity-40">
({localize('com_endpoint_default_with_num', { 0: '-45' })})
</small>
</div>
@@ -39,13 +38,8 @@ export default function DecibelSelector() {
min={-100}
max={-30}
aria-labelledby="decibel-selector-label"
- className={cn(
- defaultTextProps,
- cn(
- optionText,
- 'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-border-light',
- ),
- )}
+ variant="option"
+ className="w-12"
/>
</div>
</div>
diff --git a/client/src/components/Nav/SettingsTabs/Speech/TTS/PlaybackRate.tsx b/client/src/components/Nav/SettingsTabs/Speech/TTS/PlaybackRate.tsx
index 7e1a55844f..d32fea0a8a 100755
--- a/client/src/components/Nav/SettingsTabs/Speech/TTS/PlaybackRate.tsx
+++ b/client/src/components/Nav/SettingsTabs/Speech/TTS/PlaybackRate.tsx
@@ -1,7 +1,6 @@
import React from 'react';
import { useRecoilState, useRecoilValue } from 'recoil';
import { Slider, InputNumber } from '@librechat/client';
-import { cn, defaultTextProps, optionText } from '~/utils';
import { useLocalize } from '~/hooks';
import store from '~/store';
@@ -15,7 +14,7 @@ export default function DecibelSelector() {
<div className="flex items-center justify-between">
<div id="playback-rate-label">{localize('com_nav_playback_rate')}</div>
<div className="w-2" />
- <small className="opacity-40 high-contrast:opacity-100">
+ <small className="high-contrast:opacity-100 opacity-40">
({localize('com_endpoint_default_with_num', { 0: '1' })})
</small>
</div>
@@ -39,13 +38,8 @@ export default function DecibelSelector() {
min={0.1}
max={2}
aria-labelledby="playback-rate-label"
- className={cn(
- defaultTextProps,
- cn(
- optionText,
- 'reset-rc-number-input reset-rc-number-input-text-right h-auto w-12 border-0 group-hover/temp:border-border-light',
- ),
- )}
+ variant="option"
+ className="w-12"
/>
</div>
</div>
diff --git a/client/src/style.css b/client/src/style.css
index 85ca06a666..c9b9496ea6 100644
--- a/client/src/style.css
+++ b/client/src/style.css
@@ -386,16 +386,6 @@ html.high-contrast.dark .btn-neutral:hover {
}
}
-.reset-rc-number-input input {
- width: 100%;
- border: none !important;
- background: transparent;
-}
-
-.reset-rc-number-input-text-right input {
- text-align: right;
-}
-
p > small {
opacity: 0;
animation: fadein 3s forwards;
diff --git a/e2e/specs/mock/scenarios/input-number-reset.spec.ts b/e2e/specs/mock/scenarios/input-number-reset.spec.ts
new file mode 100644
index 0000000000..defb8e0de8
--- /dev/null
+++ b/e2e/specs/mock/scenarios/input-number-reset.spec.ts
@@ -0,0 +1,62 @@
+import { expect, test } from '@playwright/test';
+import type { Page } from '@playwright/test';
+import { NEW_CHAT_PATH } from '../helpers';
+
+/**
+ * The `option` InputNumber variant resets the input rc-input-number nests in its wrapper. The reset
+ * ships with the component's own stylesheet, so any consumer of `@librechat/client` gets it, and
+ * the app renders the nested input exactly as it did when the rule lived in the app stylesheet.
+ */
+
+type Mode = 'light' | 'dark';
+type Reset = { width: string; borderStyle: string; background: string; textAlign: string };
+
+async function probeReset(page: Page, mode: Mode): Promise<Reset> {
+ await page.addInitScript((appearance) => {
+ localStorage.setItem('color-theme', appearance);
+ }, mode);
+ await page.goto(NEW_CHAT_PATH, { timeout: 15000 });
+ await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible({
+ timeout: 30000,
+ });
+ await expect(page.locator('html')).toHaveClass(mode === 'dark' ? /\bdark\b/ : /\blight\b/);
+ return page.evaluate(() => {
+ const wrapper = document.createElement('div');
+ wrapper.style.width = '120px';
+ wrapper.className = 'reset-rc-number-input reset-rc-number-input-text-right';
+ const input = document.createElement('input');
+ input.style.border = '1px solid red';
+ wrapper.append(input);
+ document.body.append(wrapper);
+ const style = getComputedStyle(input);
+ const result = {
+ width: style.width,
+ borderStyle: style.borderTopStyle,
+ background: style.backgroundColor,
+ textAlign: style.textAlign,
+ };
+ wrapper.remove();
+ return result;
+ });
+}
+
+const EXPECTED: Reset = {
+ width: '120px',
+ borderStyle: 'none',
+ background: 'rgba(0, 0, 0, 0)',
+ textAlign: 'right',
+};
+
+test.describe('InputNumber option reset', () => {
+ test('the nested input is reset in the light theme @scenario:input-number-reset-light', async ({
+ page,
+ }) => {
+ expect(await probeReset(page, 'light')).toEqual(EXPECTED);
+ });
+
+ test('the nested input is reset in the dark theme @scenario:input-number-reset-dark', async ({
+ page,
+ }) => {
+ expect(await probeReset(page, 'dark')).toEqual(EXPECTED);
+ });
+});
diff --git a/eslint-suppressions.json b/eslint-suppressions.json
index 8e74221da6..617ccfe3bf 100644
--- a/eslint-suppressions.json
+++ b/eslint-suppressions.json
@@ -651,10 +651,10 @@
},
"client/src/components/Endpoints/Settings/Advanced.tsx": {
"shadcn/no-restyle": {
- "count": 34
+ "count": 18
},
"shadcn/require-static-classes": {
- "count": 12
+ "count": 4
}
},
"client/src/components/Endpoints/Settings/Assistants.tsx": {
@@ -887,30 +887,6 @@
"count": 5
}
},
- "client/src/components/Nav/SettingsTabs/Speech/STT/AutoSendTextSelector.tsx": {
- "shadcn/no-restyle": {
- "count": 4
- },
- "shadcn/require-static-classes": {
- "count": 2
- }
- },
- "client/src/components/Nav/SettingsTabs/Speech/STT/DecibelSelector.tsx": {
- "shadcn/no-restyle": {
- "count": 4
- },
- "shadcn/require-static-classes": {
- "count": 2
- }
- },
- "client/src/components/Nav/SettingsTabs/Speech/TTS/PlaybackRate.tsx": {
- "shadcn/no-restyle": {
- "count": 4
- },
- "shadcn/require-static-classes": {
- "count": 2
- }
- },
"client/src/components/Nav/ShortcutRecorder.tsx": {
"shadcn/no-arbitrary-values": {
"count": 3
diff --git a/eslint.config.mjs b/eslint.config.mjs
index bb50529584..49b48793ba 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -286,6 +286,8 @@ export default [
'spinner',
'popover-ui',
'select-item',
+ 'reset-rc-number-input',
+ 'reset-rc-number-input-text-right',
'assistant-item',
'animated-tab',
'animated-tab-list',
diff --git a/packages/client/src/components/InputNumber.css b/packages/client/src/components/InputNumber.css
new file mode 100644
index 0000000000..64e3a70c6a
--- /dev/null
+++ b/packages/client/src/components/InputNumber.css
@@ -0,0 +1,11 @@
+/* The rc-input-number field renders its input inside a wrapper the `option` variant classes, so
+ the nested input is reset here, where the component ships, rather than in the app stylesheet. */
+.reset-rc-number-input input {
+ width: 100%;
+ border: none !important;
+ background: transparent;
+}
+
+.reset-rc-number-input-text-right input {
+ text-align: right;
+}
diff --git a/packages/client/src/components/InputNumber.spec.tsx b/packages/client/src/components/InputNumber.spec.tsx
index c876d9c490..b00878328e 100644
--- a/packages/client/src/components/InputNumber.spec.tsx
+++ b/packages/client/src/components/InputNumber.spec.tsx
@@ -1,4 +1,5 @@
import React from 'react';
+import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import { InputNumber } from './InputNumber';
@@ -17,4 +18,20 @@ describe('InputNumber', () => {
expect(container.firstElementChild).toHaveClass('theme-disabled-within:opacity-100');
});
+
+ it('keeps the bordered field by default', () => {
+ render(<InputNumber aria-label="count" />);
+ const wrapper = screen.getByRole('spinbutton').closest('.rc-input-number');
+
+ expect(wrapper).toHaveClass('w-full', 'border');
+ expect(wrapper).not.toHaveClass('reset-rc-number-input');
+ });
+
+ it('draws the option variant as a borderless value that a caller can size', () => {
+ render(<InputNumber aria-label="count" variant="option" className="w-12" />);
+ const wrapper = screen.getByRole('spinbutton').closest('.rc-input-number');
+
+ expect(wrapper).toHaveClass('border-0', 'reset-rc-number-input', 'text-right', 'w-12');
+ expect(wrapper).not.toHaveClass('w-full');
+ });
});
diff --git a/packages/client/src/components/InputNumber.tsx b/packages/client/src/components/InputNumber.tsx
index 4cd75b8b99..522e366de0 100644
--- a/packages/client/src/components/InputNumber.tsx
+++ b/packages/client/src/components/InputNumber.tsx
@@ -6,20 +6,34 @@ import RCInputNumber from 'rc-input-number';
import * as InputNumberPrimitive from 'rc-input-number';
import type { ValueType } from '@rc-component/mini-decimal';
import { cn, disabledWithinFillClasses } from '~/utils';
+import './InputNumber.css';
// TODO help needed
// React.ElementRef<typeof LabelPrimitive.Root>,
// React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
+/** `option` is the borderless value that sits beside a setting's label, such as a slider's
+ * number: it reads as text until the row is hovered or the field is focused. */
+const INPUT_NUMBER_VARIANTS: Record<'default' | 'option', string> = {
+ default: '',
+ option:
+ 'h-auto border-0 border-transparent p-0 pr-1 text-right shadow-none outline-hidden transition-colors hover:bg-surface-hover focus:border-border-heavy focus:bg-surface-secondary focus:ring-text-primary/20 focus:ring-offset-2 focus-within:placeholder:text-text-primary focus:placeholder:text-text-primary placeholder:text-text-secondary group-hover/temp:border-border-light reset-rc-number-input reset-rc-number-input-text-right',
+};
+
+export type InputNumberProps = InputNumberPrimitive.InputNumberProps<ValueType> & {
+ variant?: keyof typeof INPUT_NUMBER_VARIANTS;
+};
+
const InputNumber: React.ForwardRefExoticComponent<
- InputNumberPrimitive.InputNumberProps<ValueType> & React.RefAttributes<HTMLInputElement>
-> = React.forwardRef<React.ElementRef<typeof RCInputNumber>, InputNumberPrimitive.InputNumberProps>(
- ({ className, ...props }, ref) => {
+ InputNumberProps & React.RefAttributes<HTMLInputElement>
+> = React.forwardRef<React.ElementRef<typeof RCInputNumber>, InputNumberProps>(
+ ({ className, variant = 'default', ...props }, ref) => {
return (
<RCInputNumber
className={cn(
'border-border-medium text-text-primary placeholder:text-text-tertiary flex max-h-5 w-full rounded-md border bg-transparent px-3 py-2 text-sm focus:outline-hidden has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50',
disabledWithinFillClasses,
+ INPUT_NUMBER_VARIANTS[variant],
className ?? '',
)}
ref={ref}