Skip to content

Prevent page from scrolling when Modal is open and implement focus trap (#397)#432

Merged
adamkudrna merged 1 commit into
masterfrom
feature/397
May 31, 2023
Merged

Prevent page from scrolling when Modal is open and implement focus trap (#397)#432
adamkudrna merged 1 commit into
masterfrom
feature/397

Conversation

@hubacekj

Copy link
Copy Markdown
Contributor

I am not that confident of this implementation. Any suggestions are welcome. @adamkudrna

Closes #397

@hubacekj hubacekj changed the title Prevent page from scrolling when is open (#397) Prevent page from scrolling when Modal is open (#397) Nov 22, 2022
@bedrich-schindler

Copy link
Copy Markdown
Contributor

Please, fix commit message to: Prevent page from scrolling when Modal is open (#397), you forgot word "Modal"

Comment thread package-lock.json
Comment thread src/lib/components/Modal/Modal.jsx Outdated
Comment thread src/lib/components/Modal/Modal.jsx Outdated
Comment thread src/lib/components/Modal/Modal.jsx Outdated
Comment thread src/lib/components/Modal/Modal.jsx Outdated
@hubacekj

Copy link
Copy Markdown
Contributor Author

Ready for next round, thanks! @adamkudrna @bedrich-schindler @dacerondrej @mbohal

Comment thread src/lib/components/Modal/README.mdx
Comment thread src/lib/components/Modal/README.mdx
Comment thread src/lib/components/Modal/Modal.jsx Outdated
@hubacekj hubacekj changed the title Prevent page from scrolling when Modal is open (#397) Prevent page from scrolling when Modal is open and enforce focus (#397) Apr 24, 2023

@adamkudrna adamkudrna left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nicely done! 👏🏻 My major comments are:

  • focus trap vs. focus enforce,
  • code readability because of long hooks.

Comment thread src/lib/components/Modal/README.mdx Outdated
Comment thread src/lib/components/Modal/Modal.jsx Outdated
Comment thread src/lib/components/Modal/Modal.jsx Outdated
Comment thread src/lib/components/Modal/Modal.jsx Outdated
Comment thread src/lib/components/Modal/Modal.jsx Outdated
Comment thread src/lib/components/Modal/Modal.jsx Outdated
Comment thread src/lib/components/Modal/Modal.jsx Outdated
Comment thread src/lib/components/Modal/Modal.jsx Outdated
Comment thread src/lib/components/Modal/README.mdx Outdated
@hubacekj hubacekj changed the title Prevent page from scrolling when Modal is open and enforce focus (#397) Prevent page from scrolling when Modal is open and implement focus trap (#397) May 12, 2023
@hubacekj

Copy link
Copy Markdown
Contributor Author

Should be ready for hopefully the final round. @bedrich-schindler @adamkudrna

@hubacekj
hubacekj requested review from adamkudrna and mbohal May 15, 2023 11:42

@adamkudrna adamkudrna left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great job, thank you! 👏🏻

Comment thread src/lib/components/Modal/Modal.jsx
Comment thread src/lib/components/Modal/README.mdx Outdated
Comment thread src/lib/components/Modal/__tests__/Modal.test.jsx
Comment thread src/lib/components/Modal/_hooks/useModalFocus.js Outdated
Comment thread src/lib/components/Modal/_hooks/useModalScrollPrevention.js
Comment thread src/lib/components/Modal/README.mdx
Comment thread src/lib/components/Modal/README.mdx Outdated
Comment thread src/lib/components/Modal/Modal.jsx
Comment thread src/lib/components/Modal/Modal.jsx

@bedrich-schindler bedrich-schindler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would approve it as it is. But there are some opened topics to be resolved. When they are resolved, I will approve it.

Comment thread src/lib/components/Modal/_hooks/useModalFocus.js
Comment thread src/lib/components/Modal/_hooks/useModalFocus.js Outdated
Comment thread src/lib/components/Modal/_hooks/useModalScrollPrevention.js

@bedrich-schindler bedrich-schindler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would approve it as it is. But there are some opened topics to be resolved. When they are resolved, I will approve it.

@bedrich-schindler bedrich-schindler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would approve it as it is. But there are some opened topics to be resolved. When they are resolved, I will approve it.

Comment thread src/lib/components/Modal/Modal.jsx
Comment thread src/lib/components/Modal/Modal.jsx
Comment thread src/lib/components/Modal/README.mdx Outdated
Comment thread src/lib/components/Modal/_hooks/useModalFocus.js
Comment thread src/lib/components/Modal/_hooks/useModalFocus.js Outdated
Comment thread src/lib/components/Modal/_hooks/useModalScrollPrevention.js
@hubacekj

Copy link
Copy Markdown
Contributor Author

@bedrich-schindler should be ready for approval

@hubacekj

Copy link
Copy Markdown
Contributor Author

Modal now always traps focus. Based on the recent discussion, we leave the option to disable autoFocus for cases in which user doesn't want the long content inside Modal to automatically scroll to the autoFocused element.

@hubacekj
hubacekj force-pushed the feature/397 branch 4 times, most recently from 5aaafad to 1119744 Compare May 30, 2023 13:15
@bedrich-schindler

Copy link
Copy Markdown
Contributor

I tested it and it works as expected. I checked code just slightly as I have already seen it. This PR was discussed primarily with @adamkudrna and @mbohal , so I expect them to check it detaily

@adamkudrna adamkudrna left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool! I only tweaked a last little detail regarding scrolling and autofocus, and it's ✅.

@adamkudrna
adamkudrna merged commit 0d17b59 into master May 31, 2023
@adamkudrna
adamkudrna deleted the feature/397 branch May 31, 2023 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent page from scrolling when Modal is open

5 participants