Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set minimum size of text inputs depending on handle #2938

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/renderer/components/inputs/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { DragHandleSVG } from '../CustomIcons';
import { AutoLabel } from './InputContainer';
import { InputProps } from './props';

const DEFAULT_SIZE = { width: 222, height: 80 } as const;
const DEFAULT_SIZE_WITHOUT_HANDLE = { width: 222, height: 80 } as const;
const DEFAULT_SIZE = { width: 214, height: 80 } as const;

const invalidRegexCache = new Map<string | null | undefined, RegExp | undefined>();
const getInvalidRegex = (pattern: string): RegExp | undefined => {
Expand Down Expand Up @@ -165,22 +166,23 @@ export const TextInput = memo(
));

// size
const defaultSize = input.hasHandle ? DEFAULT_SIZE : DEFAULT_SIZE_WITHOUT_HANDLE;
useEffect(() => {
if (!size) {
setSize(DEFAULT_SIZE);
setSize(defaultSize);
}
}, [size, setSize]);
}, [size, setSize, defaultSize]);

const zoom = useContextSelector(GlobalVolatileContext, (c) => c.zoom);

const startSize = useRef(size ?? DEFAULT_SIZE);
const startSize = useRef(size ?? defaultSize);

let inputElement;
if (multiline) {
inputElement = (
<Resizable
className="nodrag"
defaultSize={size ?? DEFAULT_SIZE}
defaultSize={size ?? defaultSize}
enable={{
top: false,
right: !isLocked,
Expand Down Expand Up @@ -208,7 +210,7 @@ export const TextInput = memo(
),
}}
minHeight={80}
minWidth={DEFAULT_SIZE.width}
minWidth={defaultSize.width}
scale={zoom}
size={size}
onResize={(e, direction, ref, d) => {
Expand All @@ -220,7 +222,7 @@ export const TextInput = memo(
}
}}
onResizeStart={() => {
startSize.current = size ?? DEFAULT_SIZE;
startSize.current = size ?? defaultSize;
}}
>
<Textarea
Expand Down
Loading