mirror of
https://github.com/zadam/trilium.git
synced 2025-11-04 21:49:04 +01:00
fix(settings): max content width forces minimum when typing (closes #7423)
This commit is contained in:
parent
a664a58076
commit
d4a46ed4da
@ -9,22 +9,26 @@ interface FormTextBoxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function FormTextBox({ inputRef, className, type, currentValue, onChange, onBlur, autoFocus, ...rest}: FormTextBoxProps) {
|
export default function FormTextBox({ inputRef, className, type, currentValue, onChange, onBlur, autoFocus, ...rest}: FormTextBoxProps) {
|
||||||
if (type === "number" && currentValue) {
|
|
||||||
const { min, max } = rest;
|
|
||||||
const currentValueNum = parseInt(currentValue, 10);
|
|
||||||
if (min && currentValueNum < parseInt(String(min), 10)) {
|
|
||||||
currentValue = String(min);
|
|
||||||
} else if (max && currentValueNum > parseInt(String(max), 10)) {
|
|
||||||
currentValue = String(max);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (autoFocus) {
|
if (autoFocus) {
|
||||||
inputRef?.current?.focus();
|
inputRef?.current?.focus();
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
function applyLimits(value: string) {
|
||||||
|
if (type === "number") {
|
||||||
|
const { min, max } = rest;
|
||||||
|
const currentValueNum = parseInt(value, 10);
|
||||||
|
if (min && currentValueNum < parseInt(String(min), 10)) {
|
||||||
|
return String(min);
|
||||||
|
} else if (max && currentValueNum > parseInt(String(max), 10)) {
|
||||||
|
return String(max);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
@ -33,11 +37,13 @@ export default function FormTextBox({ inputRef, className, type, currentValue, o
|
|||||||
value={currentValue}
|
value={currentValue}
|
||||||
onInput={onChange && (e => {
|
onInput={onChange && (e => {
|
||||||
const target = e.currentTarget;
|
const target = e.currentTarget;
|
||||||
onChange?.(target.value, target.validity);
|
const currentValue = applyLimits(e.currentTarget.value);
|
||||||
|
onChange?.(currentValue, target.validity);
|
||||||
})}
|
})}
|
||||||
onBlur={onBlur && (e => {
|
onBlur={(e => {
|
||||||
const target = e.currentTarget;
|
const currentValue = applyLimits(e.currentTarget.value);
|
||||||
onBlur(target.value);
|
e.currentTarget.value = currentValue;
|
||||||
|
onBlur?.(currentValue);
|
||||||
})}
|
})}
|
||||||
{...rest}
|
{...rest}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -294,7 +294,7 @@ function MaxContentWidth() {
|
|||||||
<FormGroup name="max-content-width" label={t("max_content_width.max_width_label")}>
|
<FormGroup name="max-content-width" label={t("max_content_width.max_width_label")}>
|
||||||
<FormTextBoxWithUnit
|
<FormTextBoxWithUnit
|
||||||
type="number" min={MIN_CONTENT_WIDTH} step="10"
|
type="number" min={MIN_CONTENT_WIDTH} step="10"
|
||||||
currentValue={maxContentWidth} onChange={setMaxContentWidth}
|
currentValue={maxContentWidth} onBlur={setMaxContentWidth}
|
||||||
unit={t("max_content_width.max_width_unit")}
|
unit={t("max_content_width.max_width_unit")}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user