Skip to content

Refactor / replace modal with HTML Dialog #505

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 7 commits into from
May 13, 2024
Merged

Conversation

ChristiaanScheermeijer
Copy link
Collaborator

Description

This PR is an alternative to #485. In the modal manager PR, we try to manage everything ourselves, which gives us ultimate control but is risky and needs to be maintained in the future.

The HTML Dialog element has been out for some time now, but I actually never used it because of the browser support. But looking at the support table, I don't see why we shouldn't use it. Over 96% of the global browsers support the HTML Dialog element.

Using the native dialog element removes the need for the ModalProvider, because we can use the DOM to close open modals.

Only the body scrolling was still possible so I modified the useModal hook to hide the scrollbars when a modal is open.

Although we don't have to manage focus anymore, I did find one edge case when opening the account modal from the sidebar. Because the last focused element doesn't exist anymore (I fixed this in the ModalProvider), the body receives focus when closing the last modal.

This is a proposal PR, so let me know if you have any feedback or criticism.

Copy link

github-actions bot commented Apr 18, 2024

Visit the preview URL for this PR (updated for commit 3fd7f4f):

https://ottwebapp--pr505-feat-use-html-dialog-iooqd9g7.web.app

(expires Wed, 12 Jun 2024 11:14:23 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: c198f8a3a199ba8747819f7f1e45cf602b777529

@ChristiaanScheermeijer ChristiaanScheermeijer deleted the feat/use-html-dialog branch April 18, 2024 09:36
@ChristiaanScheermeijer ChristiaanScheermeijer restored the feat/use-html-dialog branch April 18, 2024 09:47
@ChristiaanScheermeijer
Copy link
Collaborator Author

^ not sure what happened here 🤔

@ChristiaanScheermeijer
Copy link
Collaborator Author

@AntonLantukh @dbudzins, what do you think of this PR as an alternative to #485?

I do have to test this (and the polyfill) for older browsers (TV browsers), but if you have a strong preference over this or #485, please let me know 😄

AntonLantukh
AntonLantukh previously approved these changes Apr 25, 2024
Copy link
Collaborator

@AntonLantukh AntonLantukh left a comment

Choose a reason for hiding this comment

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

@ChristiaanScheermeijer I like this approach. Do you think it will also work with TV devices? If it does, then I would proceed with this one.

</div>
</div>
`;
exports[`<SideBar /> > renders sideBar closed 1`] = `<div />`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, all the content got removed. Is it expected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the Sidebar is now rendered in a modal/dialog which doesn't render when it is hidden.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But... I found that the Sidebar open snapshot was also empty. This is because there is nothing rendered in the container due to the usage of portals in the Modal component. This is fixed now.

@ChristiaanScheermeijer
Copy link
Collaborator Author

@ChristiaanScheermeijer I like this approach. Do you think it will also work with TV devices? If it does, then I would proceed with this one.

We're testing this, but currently, the web app isn't working at all on (older) TV devices. PR #519 fixes this problem :-)

@ChristiaanScheermeijer ChristiaanScheermeijer changed the base branch from feat/modal-manager to develop April 26, 2024 08:12
@ChristiaanScheermeijer ChristiaanScheermeijer dismissed AntonLantukh’s stale review April 26, 2024 08:12

The base branch was changed.

@ChristiaanScheermeijer
Copy link
Collaborator Author

I've tested this on Chrome 68 (which we will support after #519), and it seems to work fine. The HTML dialog element is supported from Chrome 37 and up.

@royschut
Copy link
Collaborator

royschut commented May 1, 2024

We have performed our manual testing workflow, including this PR and found 2 bugs that I have fixed just now:

  • When the player unmounts, an infinite render loop was initiated. The useCallback wrapper fixes this.
  • A click on the backdrop didn't close the modals anymore. Fixed by a simple click handler that checks if the modal itself (which can only be the backdrop) is clicked.

@AntonLantukh
Copy link
Collaborator

AntonLantukh commented May 13, 2024

@royschut @ChristiaanScheermeijer looks good to me! I want to merge this PR if all the tests pass. Any objections?

UPD: tests seem to fail, could you take a look?

@ChristiaanScheermeijer
Copy link
Collaborator Author

Hi @AntonLantukh, thanks! I've fixed the e2e issues. This PR is ready to be (squashed) merged 😄

@AntonLantukh AntonLantukh merged commit 6ee0305 into develop May 13, 2024
10 checks passed
@AntonLantukh AntonLantukh deleted the feat/use-html-dialog branch May 13, 2024 17:22
anoblet pushed a commit to conversionxl/ott-web-app that referenced this pull request Feb 17, 2025
* refactor: use html dialog elements

* refactor(player): fix endless unmount loop

* refactor: re-fix backdrop click to close modal

* refactor(project): use events for animation open close callbacks

* test(e2e): fix close modal by backdrop test

* test(e2e): fix timeout on choose offer modal

* test(e2e): skip click outside modal test for mobile

---------

Co-authored-by: Roy Schut <[email protected]>
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.

3 participants