Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Enabled save button only when link is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Jan 6, 2023
1 parent e532205 commit 7674548
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ interface LinkModalProps {
}

export function LinkModal({ composer, isTextEnabled, onClose, composerContext, isEditing }: LinkModalProps) {
const [hasLinkChanged, setHasLinkChanged] = useState(false);
const [fields, setFields] = useState({ text: "", link: isEditing ? composer.getLink() : "" });
const isSaveDisabled = (isTextEnabled && isEmpty(fields.text)) || isEmpty(fields.link);
const isSaveDisabled = !hasLinkChanged && ((isTextEnabled && isEmpty(fields.text)) || isEmpty(fields.link));

return (
<BaseDialog
Expand Down Expand Up @@ -97,9 +98,10 @@ export function LinkModal({ composer, isTextEnabled, onClose, composerContext, i
label={_td("Link")}
value={fields.link}
placeholder=""
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setFields((fields) => ({ ...fields, link: e.target.value }))
}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
setHasLinkChanged(true);
setFields((fields) => ({ ...fields, link: e.target.value }));
}}
/>

<div className="mx_LinkModal_buttons">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,12 @@ describe("LinkModal", () => {

// Then
expect(screen.getByLabelText("Link")).toContainHTML("my initial content");
expect(screen.getByText("Save")).toBeDisabled();

// When
await userEvent.type(screen.getByLabelText("Link"), "l");

// Then
await waitFor(() => expect(screen.getByText("Save")).toBeEnabled());
});
});

0 comments on commit 7674548

Please sign in to comment.