diff --git a/package.json b/package.json index 5e1aa4c..e39202b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "material-ui-confirm", "version": "3.0.10", - "description": "Higher order component for straightforward use of @material-ui/core confirmation dialogs.", + "description": "Simple confirmation dialogs built on top of @mui/material", "keywords": [ "Material UI", "confirmation", diff --git a/src/ConfirmProvider.js b/src/ConfirmProvider.js index 5d29b94..e48d2e6 100644 --- a/src/ConfirmProvider.js +++ b/src/ConfirmProvider.js @@ -73,10 +73,12 @@ let confirmGlobal; const ConfirmProvider = ({ children, defaultOptions = {} }) => { const [options, setOptions] = useState({}); const [resolveReject, setResolveReject] = useState([]); + const [key, setKey] = useState(0); const [resolve, reject] = resolveReject; const confirm = useCallback((options = {}) => { return new Promise((resolve, reject) => { + setKey((key) => key + 1); setOptions(options); setResolveReject([resolve, reject]); }); @@ -108,6 +110,7 @@ const ConfirmProvider = ({ children, defaultOptions = {} }) => { {children} { expect(confirmationButton.disabled).toBe(false); }); + + test("resets the input value on every open", () => { + const { getByText, getAllByText } = render( + + ); + + fireEvent.click(getByText("Delete")); + + let textfield = getAllByText( + (content, element) => element.tagName.toLowerCase() === "input" + )[0]; + + expect(textfield).toBeTruthy(); + fireEvent.change(textfield, { target: { value: "DELETE" } }); + + fireEvent.click(getByText("Ok")); + + fireEvent.click(getByText("Delete")); + + textfield = getAllByText( + (content, element) => element.tagName.toLowerCase() === "input" + )[0]; + + expect(textfield.value).toEqual(""); + }); }); + test("renders textfield with custom props", () => { const { getByText, queryByPlaceholderText } = render(