mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-28 18:40:34 -05:00
Save name fields on unfocus (#2327)
This commit is contained in:
committed by
GitHub
parent
6e16262b63
commit
30f03e8079
@@ -126,7 +126,8 @@ export function AccountHeader({
|
||||
<Input
|
||||
defaultValue={accountName}
|
||||
onEnter={e => onSaveName(e.target.value)}
|
||||
onBlur={() => onExposeName(false)}
|
||||
onBlur={e => onSaveName(e.target.value)}
|
||||
onEscape={() => onExposeName(false)}
|
||||
style={{
|
||||
fontSize: 25,
|
||||
fontWeight: 500,
|
||||
|
||||
@@ -26,6 +26,7 @@ export type InputProps = InputHTMLAttributes<HTMLInputElement> & {
|
||||
style?: CSSProperties;
|
||||
inputRef?: Ref<HTMLInputElement>;
|
||||
onEnter?: (event: KeyboardEvent<HTMLInputElement>) => void;
|
||||
onEscape?: (event: KeyboardEvent<HTMLInputElement>) => void;
|
||||
onUpdate?: (newValue: string) => void;
|
||||
focused?: boolean;
|
||||
};
|
||||
@@ -34,6 +35,7 @@ export function Input({
|
||||
style,
|
||||
inputRef,
|
||||
onEnter,
|
||||
onEscape,
|
||||
onUpdate,
|
||||
focused,
|
||||
...nativeProps
|
||||
@@ -65,6 +67,10 @@ export function Input({
|
||||
onEnter(e);
|
||||
}
|
||||
|
||||
if (e.key === 'Escape' && onEscape) {
|
||||
onEscape(e);
|
||||
}
|
||||
|
||||
nativeProps.onKeyDown?.(e);
|
||||
}}
|
||||
onChange={e => {
|
||||
|
||||
@@ -59,6 +59,17 @@ function EditableBudgetName({ prefs, savePrefs }: EditableBudgetNameProps) {
|
||||
{ name: 'close', text: 'Close file' },
|
||||
];
|
||||
|
||||
const onSaveChanges = async e => {
|
||||
const inputEl = e.target;
|
||||
const newBudgetName = inputEl.value;
|
||||
if (newBudgetName.trim() !== '') {
|
||||
await savePrefs({
|
||||
budgetName: inputEl.value,
|
||||
});
|
||||
setEditing(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (editing) {
|
||||
return (
|
||||
<InitialFocus>
|
||||
@@ -69,17 +80,9 @@ function EditableBudgetName({ prefs, savePrefs }: EditableBudgetNameProps) {
|
||||
fontWeight: 500,
|
||||
}}
|
||||
defaultValue={prefs.budgetName}
|
||||
onEnter={async e => {
|
||||
const inputEl = e.target as HTMLInputElement;
|
||||
const newBudgetName = inputEl.value;
|
||||
if (newBudgetName.trim() !== '') {
|
||||
await savePrefs({
|
||||
budgetName: inputEl.value,
|
||||
});
|
||||
setEditing(false);
|
||||
}
|
||||
}}
|
||||
onBlur={() => setEditing(false)}
|
||||
onEnter={onSaveChanges}
|
||||
onBlur={onSaveChanges}
|
||||
onEscape={() => setEditing(false)}
|
||||
/>
|
||||
</InitialFocus>
|
||||
);
|
||||
|
||||
6
upcoming-release-notes/2327.md
Normal file
6
upcoming-release-notes/2327.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [jfdoming]
|
||||
---
|
||||
|
||||
Save budget/account name fields on blur
|
||||
Reference in New Issue
Block a user