Skip to content

Commit

Permalink
fix: select all text on budget input focus
Browse files Browse the repository at this point in the history
fix #21
  • Loading branch information
Xiphe committed Apr 30, 2020
1 parent 45bb988 commit 1b6b6f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/views/Month/BudgetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,31 @@ type Props = {
onChange: (ev: { amount: number; id: string }) => void;
};

function select({ target }: React.FocusEvent<HTMLInputElement>) {
setTimeout(() => {
target.select();
}, 0);
}

export default function BudgetInput({
onChange,
value,
numberFormatter,
categoryId,
}: Props) {
const props = useAmountInputProps({
numberFormatter,
value,
onChange: useCallback(
(amount: number) => onChange({ amount, id: categoryId }),
[categoryId, onChange],
),
});

return <input {...props} className={styles.budgetInput} type="string" />;
return (
<input
{...useAmountInputProps({
numberFormatter,
value,
onChange: useCallback(
(amount: number) => onChange({ amount, id: categoryId }),
[categoryId, onChange],
),
})}
onFocus={select}
className={styles.budgetInput}
type="string"
/>
);
}
1 change: 1 addition & 0 deletions src/views/Month/Month.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
@include focusOutline();
cursor: text;
z-index: 15;
color: var(--main-color);
outline: none;
background-color: var(--background-color);
}
Expand Down

0 comments on commit 1b6b6f5

Please sign in to comment.