diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-1-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-1-chromium-linux.png index a2e2fc3f1b9..db20f97c968 100644 Binary files a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-1-chromium-linux.png and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-1-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-2-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-2-chromium-linux.png index 6240ae33bc1..dd98f0c1392 100644 Binary files a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-2-chromium-linux.png and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-2-chromium-linux.png differ diff --git a/packages/desktop-client/src/components/Modals.tsx b/packages/desktop-client/src/components/Modals.tsx index e0c66f497a1..2953f58e4a0 100644 --- a/packages/desktop-client/src/components/Modals.tsx +++ b/packages/desktop-client/src/components/Modals.tsx @@ -11,6 +11,7 @@ import * as monthUtils from 'loot-core/src/shared/months'; import { useActions } from '../hooks/useActions'; import { useSyncServerStatus } from '../hooks/useSyncServerStatus'; +import { ModalTitle } from './common/Modal'; import { AccountAutocompleteModal } from './modals/AccountAutocompleteModal'; import { AccountMenuModal } from './modals/AccountMenuModal'; import { BudgetMenuModal } from './modals/BudgetMenuModal'; @@ -314,7 +315,7 @@ export function Modals() { return ( } inputPlaceholder="Category name" buttonText="Add" onValidate={options.onValidate} @@ -326,7 +327,7 @@ export function Modals() { return ( } inputPlaceholder="Category group name" buttonText="Add" onValidate={options.onValidate} diff --git a/packages/desktop-client/src/components/common/Modal.tsx b/packages/desktop-client/src/components/common/Modal.tsx index bbd7b573624..8435bdbedb4 100644 --- a/packages/desktop-client/src/components/common/Modal.tsx +++ b/packages/desktop-client/src/components/common/Modal.tsx @@ -370,6 +370,7 @@ type ModalTitleProps = { getStyle?: (isEditing: boolean) => CSSProperties; onEdit?: (isEditing: boolean) => void; onTitleUpdate?: (newName: string) => void; + shrinkOnOverflow?: boolean; }; export function ModalTitle({ @@ -377,6 +378,7 @@ export function ModalTitle({ isEditable, getStyle, onTitleUpdate, + shrinkOnOverflow = false, }: ModalTitleProps) { const [isEditing, setIsEditing] = useState(false); const style = getStyle?.(isEditing); @@ -405,6 +407,23 @@ export function ModalTitle({ } }, [isEditing]); + // Dynamic font size to avoid ellipsis. + const textRef = useRef(); + const [textFontSize, setTextFontSize] = useState(25); + useEffect(() => { + if (shrinkOnOverflow) { + const containerWidth = textRef.current.offsetWidth; + const textWidth = textRef.current.scrollWidth; + + if (textWidth > containerWidth) { + const newFontSize = Math.floor( + (containerWidth / textWidth) * textFontSize, + ); + setTextFontSize(newFontSize); + } + } + }, [textFontSize, shrinkOnOverflow]); + return isEditing ? ( ) : ( ; - title: string; + title: ComponentProps['title']; buttonText: string; onSubmit: (value: string) => void; onValidate?: (value: string) => string[];