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 ConfirmationModal to focus on positive confirm button#945 #949

Closed

Conversation

britneywwc
Copy link

Done

  • Allow ConfirmationModal to focus on the positive confirm button when opening the modal, letting users press enter to confirm
  • If confirm button is not positive, modal focus will be on the cancel button

QA

Storybook

To see rendered examples of all react-components, run:

yarn start

QA in your project

from react-components run:

yarn build
npm pack

Install the resulting tarball in your project with:

yarn add <path-to-tarball>

QA steps

  • Use ConfirmationModal component and changeconfirmButtonAppearance to positive/negative/neutral. Click enter to verify which buttons are clicked.

Fixes

Fixes: #945

@webteam-app
Copy link

webteam-app commented Jul 23, 2023

Comment on lines +65 to +69
<div
className="p-confirmation-modal"
ref={modalRef as RefObject<HTMLDivElement>}
>
{children}
</Modal>
<Modal
Copy link
Contributor

Choose a reason for hiding this comment

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

The additional div wrapper with the unused p-confirmation-modal class is unnecessary: we can set the ref to the Modal directly - which is a div itself.

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean passing/forwarding the current ref to Modal? Since Modal already has a ref on itsdiv.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, forwarding the ref should work in this case - but now that you mention it, I wonder whether it would make more sense to apply the changes proposed in this PR to the Modal itself, since we already have the ref there, which we're already using for focusing purposes.

However, this proposed change requires UX input, as I'm not sure that focusing the positive button when we have one is what we want to do. As a general guideline, I've been told that we want to keep the least destructive option focused by default, which would still be the "Cancel" button then.

Copy link
Author

Choose a reason for hiding this comment

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

I agree that applying these changes in Modal would make more sense. Since this change requires UX input and may not be the least destructive option, should I set these changes on pause then?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, let's wait some feedback from them first.

@bartaz
Copy link
Contributor

bartaz commented Jul 27, 2023

@britneywwc Thanks for the suggestion. Can you explain a bit why you think such change is an improvement?

Our current focus rules with Modal component we are following the accessibility recommendations from https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/:

image

When opening modal the first focusable element is focused by default, and it's recommended for it to be a button that closes the modal (so it's easy to go back if it was opened by mistake).

It's even more important if the action on the modal is destructive. And with ConfirmationModal it seems by definition we ask user for confirmation because the action they are about to perform is hard or impossible to revert. In such case it's recommended for default focus NOT to be the main action, but cancel action, so it's easier to cancel than perform the action by mistake.

So from accessibility point of view, I don't think we want to focus on primary button by default.

Of course, these are not strict rules and there may be situations when focusing on something else will not have bad consequences. So it may be worth considering updating the Modal component, so that the default focused can be changed, but it should be used with caution and I don't know if we have currently a use case for such feature.

@britneywwc
Copy link
Author

@bartaz Thanks for your input. Initially I thought this change would be necessary due to users' expectations when they are prompted with a "positive" Confirm button. Although after reading the information you have shared, I agree that it is a much safer option to stay focused on a non-destructive option. If there is currently no use case for such feature then I will close this PR for now.

@britneywwc britneywwc closed this Jul 28, 2023
@bartaz
Copy link
Contributor

bartaz commented Jul 28, 2023

Thanks @britneywwc, it's always good to have such discussions, so if you have any other ideas for improvements feel free to propose them as issues or PRs!

@britneywwc britneywwc deleted the focus-confirmation-modal#945 branch October 6, 2023 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Focus on confirm in ConfirmationModal
4 participants