Skip to content
Snippets Groups Projects
Unverified Commit 30f03e80 authored by Julian Dominguez-Schatz's avatar Julian Dominguez-Schatz Committed by GitHub
Browse files

Save name fields on unfocus (#2327)

parent 6e16262b
No related branches found
No related tags found
No related merge requests found
......@@ -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>
);
......
---
category: Bugfix
authors: [jfdoming]
---
Save budget/account name fields on blur
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment