Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add field modal does not close on first close button click #1455

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ const EditModal = ({ close, data, fields, onSave, zoneType }) => {
/>
<Close // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-assignment
onClick={close}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Copy link
Contributor

@dani-mp dani-mp Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add this comment at the top of the file so we don't have to add it in each line. We said we were going to do this but if we never start we'll never do it!

onMouseDown={close} // will execute the close function before Label input hijacks the focus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is the best way to solve this, it looks like a hack. This is a common scenario on the web (clicking a button while another element has the focus). We rarely have to duplicate the on-click handler to fix this, and with this, we're executing the close function twice (it might be ok for this particular scenario, but it is still not ideal).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure about what is exact root of the problem, it's most likely related with re-render happening when input is validated, and my idea was that after the re-render focus is brought back to input (if I disable autofocus, button works without any problem).
I agree the solution looks like a hack, but couldn't find any other working (might try to spend some more time on it).

type="button"
/>
</Flex>
Expand Down
Loading