Skip to content

Commit

Permalink
Merge pull request liquity#359 from liquity/dependabot/npm_and_yarn/p…
Browse files Browse the repository at this point in the history
…ackages/dev-frontend/testing-library/react-11.2.5

chore(deps): bump @testing-library/react from 9.5.0 to 11.2.5 in /packages/dev-frontend
  • Loading branch information
danielattilasimon authored Mar 14, 2021
2 parents ea62ab6 + 7a46074 commit 96d7d96
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/dev-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@popperjs/core": "^2.9.1",
"@testing-library/dom": "^7.30.0",
"@testing-library/jest-dom": "^5.1.1",
"@testing-library/react": "^9.4.0",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^10.0.0",
"@types/jest": "^26.0.20",
"@types/react": "^17.0.0",
Expand Down
77 changes: 41 additions & 36 deletions packages/dev-frontend/src/components/Trove/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { Icon } from "../Icon";

type RowProps = {
label: string;
labelId?: string;
labelFor?: string;
unit?: string;
};

const Row: React.FC<RowProps> = ({ label, labelFor, unit, children }) => {
const Row: React.FC<RowProps> = ({ label, labelId, labelFor, unit, children }) => {
return (
<Flex sx={{ alignItems: "stretch" }}>
<Label htmlFor={labelFor} sx={{ width: unit ? "106px" : "170px" }}>
<Label id={labelId} htmlFor={labelFor} sx={{ width: unit ? "106px" : "170px" }}>
{label}
</Label>
{unit && (
Expand All @@ -27,6 +28,7 @@ const Row: React.FC<RowProps> = ({ label, labelFor, unit, children }) => {

type StaticAmountsProps = {
inputId: string;
labelledBy?: string;
amount: string;
color?: string;
pendingAmount?: string;
Expand All @@ -39,6 +41,7 @@ type StaticAmountsProps = {
const StaticAmounts: React.FC<StaticAmountsProps & SxProp> = ({
sx,
inputId,
labelledBy,
amount,
color,
pendingAmount,
Expand All @@ -51,6 +54,7 @@ const StaticAmounts: React.FC<StaticAmountsProps & SxProp> = ({
<Label
variant={variant}
id={inputId}
aria-labelledby={labelledBy}
sx={{
...sx,
...(invalid ? { backgroundColor: "invalid" } : {}),
Expand Down Expand Up @@ -125,42 +129,43 @@ export const EditableRow: React.FC<EditableRowProps> = ({
const [editing, setEditing] = editingState;
const [invalid, setInvalid] = useState<boolean>(false);

return (
return editing === inputId ? (
<Row {...{ label, labelFor: inputId, unit }}>
{editing === inputId ? (
<Input
autoFocus
sx={invalid ? { backgroundColor: "invalid" } : {}}
id={inputId}
type="number"
step="any"
defaultValue={editedAmount}
{...{ invalid }}
onChange={e => {
try {
setEditedAmount(e.target.value);
setInvalid(false);
} catch {
setInvalid(true);
}
}}
onBlur={() => {
setEditing(undefined);
<Input
autoFocus
sx={invalid ? { backgroundColor: "invalid" } : {}}
id={inputId}
type="number"
step="any"
defaultValue={editedAmount}
{...{ invalid }}
onChange={e => {
try {
setEditedAmount(e.target.value);
setInvalid(false);
}}
/>
) : (
<StaticAmounts
inputId={inputId}
amount={amount}
color={color}
pendingAmount={pendingAmount}
pendingColor={pendingColor}
invalid={invalid}
variant={variant}
onClick={() => setEditing(inputId)}
/>
)}
} catch {
setInvalid(true);
}
}}
onBlur={() => {
setEditing(undefined);
setInvalid(false);
}}
/>
</Row>
) : (
<Row labelId={`${inputId}-label`} {...{ label, unit }}>
<StaticAmounts
inputId={inputId}
labelledBy={`${inputId}-label`}
amount={amount}
color={color}
pendingAmount={pendingAmount}
pendingColor={pendingColor}
invalid={invalid}
variant={variant}
onClick={() => setEditing(inputId)}
/>
</Row>
);
};

0 comments on commit 96d7d96

Please sign in to comment.