-
Notifications
You must be signed in to change notification settings - Fork 5
EES-5960 update publication modal focus close fix #5707
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
EES-5960 update publication modal focus close fix #5707
Conversation
Instead of refactoring to use 'triggerButton' like we do on other modals we handle focus manually by focussing the button via a ref. This is to keep the form validation/submit behaviour working as it currently does.
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've left a couple of change ideas that I think makes things a bit clearer
const cancelConfirmModal = () => { | ||
toggleConfirmModal.off(); | ||
// This setTimeout is needed because the focus() fn needs to be called | ||
// on the next tick. Without it, the button doesn't focus. | ||
// I think the modal tries to handle the focus on close, which prevents | ||
// our custom focus handling from working at that point. | ||
setTimeout(() => submitButtonRef.current?.focus(), 0); | ||
}; |
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 use a useEffect instead of setTimeout, to automatically set focus every time the modal closes
useEffect(() => {
if (showConfirmModal === false) {
submitButtonRef.current?.focus();
}
}, [showConfirmModal]);
onExit={toggleConfirmModal.off} | ||
onCancel={toggleConfirmModal.off} | ||
onExit={cancelConfirmModal} | ||
onCancel={cancelConfirmModal} |
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.
Can revert this once we use the useEffect
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.
Clean!
This PR fixes focus restoration when the 'edit publication' modal is closed in the admin site - returning focus to the modal trigger button.
Instead of refactoring to use 'triggerButton' like we do on other modals, we handle focus manually by focussing the button via a ref.
This is to keep the form validation/submit behaviour working as it currently does.