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: refactor Modal rendering and clickOutside handling #4035

Merged
merged 5 commits into from
Jun 10, 2024

Conversation

ndom91
Copy link
Contributor

@ndom91 ndom91 commented Jun 7, 2024

Notes

Based on what we discussed:

  • Doing the onMount(() => document.appendChild(...)) seems to just change where in the DOM these <dialog /> elements are appended. When using the onMount strategy they're appended to the end of the body, otherwise they're just in line in the dom wherever they the <Modal /> component is being used.
    • Imo this doesn't make much of a difference though because we're (a) still only adding the wrapping <dialog /> element to the DOM initially and none of its children, (b) when the user opens the modal, we render/mount the rest of the body of the <dialog /> and it gets rendered into the top-layer (making it's position in the dom more or less irrelevant).
  • Unfortunately it doesn't look like we can wrap the whole <dialog /> with an {#if open ..}, because that <dialog /> element at the very least needs to be in the DOM. The components consuming the <Modal /> freak out if it's not there because of the this binding. If the <dialog /> is not created then the showModal() or close(), etc. methods aren't available.

Todo

  • Still need to set enable: !!open for the click outside use: action. This will avoid adding a bunch of unnecessary event handlers on window to listen for clicks to check for Modal's that aren't even open. The use:clickOutside action is on the <form /> element, which is a child of the <dialog />, meaning it's not created and added to the dom until the user opens the modal anyway. And the event listener is removed from the document when the modal is closed 🥳

@ndom91 ndom91 marked this pull request as ready for review June 7, 2024 13:53
@ndom91 ndom91 requested a review from mtsgrd June 10, 2024 09:10
@ndom91 ndom91 merged commit 0c481fe into master Jun 10, 2024
15 checks passed
@ndom91 ndom91 deleted the ndom91/modal-logic branch June 10, 2024 09:12
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.

None yet

1 participant