Skip to content

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

Merged
merged 5 commits into from
Mar 25, 2025

Conversation

Guy-HiveIT
Copy link
Collaborator

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.

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.
Copy link
Collaborator

@bennettstuart bennettstuart left a 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

Comment on lines 75 to 82
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);
};
Copy link
Collaborator

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]);

Comment on lines 174 to 187
onExit={toggleConfirmModal.off}
onCancel={toggleConfirmModal.off}
onExit={cancelConfirmModal}
onCancel={cancelConfirmModal}
Copy link
Collaborator

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

Copy link
Collaborator

@bennettstuart bennettstuart left a comment

Choose a reason for hiding this comment

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

Clean!

@bennettstuart bennettstuart merged commit ac20e1d into dev Mar 25, 2025
11 checks passed
@bennettstuart bennettstuart deleted the EES-5960-update-publication-modal-focus-close-fix branch March 25, 2025 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants