-
Notifications
You must be signed in to change notification settings - Fork 52
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
base: main
Are you sure you want to change the base?
fix: add field modal does not close on first close button click #1455
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -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 |
There was a problem hiding this comment.
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!
@@ -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 | |||
onMouseDown={close} // will execute the close function before Label input hijacks the focus |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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).
Small comment on the description: This doesn't seem to be caused by the label autofocus, the same happens if you open the modal, focus an input and try to close the modal with the X button. This is may be related to the re-render that happens on input blur. |
|
That's not the result I'm getting when I disabled the autofocus 😅 Kapture.2024-09-11.at.12.37.32.mp4 |
|
Resolves: DT-2345
Description
When adding a new field in a a page or custom type in
slice-machine
the edit modal won't close on the first X button click.This is happening because Label input is being auto-focused.
onMouseDown added to the close button will execute close function before the focus is being hijacked by input.
Checklist
Preview
BEFORE
Nagranie.z.ekranu.2024-09-11.o.12.16.24.mov
AFTER
Nagranie.z.ekranu.2024-09-11.o.12.30.53.mov
How to QA 1
Footnotes
Please use these labels when submitting a review:
⚠️ #issue: Strongly suggest a change.
❓ #ask: Ask a question.
💡 #idea: Suggest an idea.
🎉 #nice: Share a compliment. ↩