Problem/Motivation
While digging into a smaller issue, "@todo state.closeButton is never a function, this condition can be removed" in Modal.svelte, it was uncovered that the Modal component as it stands is unnecessarily complicated for the use case we have (currently only one). It would be great to refactor this code to make it much simpler, ideally in a way that conforms with how core does Modals (if at all).
Steps to reproduce
Proposed resolution
Slim down the existing Modal component to just what we need, or replace with a more lightweight Modal component from packages. As a matter of preference, my top choice would be to keep something somewhat custom but much smaller, that utilizes any core libraries that may be available.
Remaining tasks
- ✅ File an issue about this project
- ☐ Manual Testing
- ☐ Code Review
- ☐ Accessibility Review
- ☐ Automated tests needed/written?
Issue fork project_browser-3284094
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #5
bnjmnmComment #6
bnjmnmComment #8
narendrarComment #9
bnjmnmSee comment in MR. It should either be confirmed it's Ok to remove the parent condition, or limit the changes to just removing the condition as described in the issue summary.
Comment #10
narendrarThis popup code seems to be inspired from https://svelte.dev/repl/033e824fad0a4e34907666e7196caec4?version=3.20.1 and may require more refactoring or can be replaced with some other simple popup.
Comment #11
chrisfromredfinOK so after some digging it seems like the reason for all this is because you can pass in all these parameters through props, i.e. whether or not to have a closeButton at all, for example. So, to that end:
It's "needed" in the sense that if we were to have a second modal where we didn't want a closeButton, it could be useful to be able to pass it in as a prop. Leaving that piece in allows us to do that.
In terms of this issue, I think it addresses the primary current concern, but that doesn't really move the needle.
I also see the following which may also want to come out?
https://git.drupalcode.org/project/project_browser/-/blob/b5a813e9bee97a...
The purpose of the isFunction is that you could declare these individual pieces, ex.g. the close button, as Components in and of themselves, not relying on the default one.
That totally seems like overkill to me. So I land where narendraR did... which I think is that this Modal is probably unnecessarily complicated because it was brought in from boilerplate, and I think this could be simplified quite a bit, or we could pull in some other Modal (is there anything in core/Claro?).
Updating issue summary to reflect.
Comment #12
bnjmnmGood observations! We could feasibly use the existing Drupal.dialog library because the contents of the modal don't need to interact with the rest of the app. It also happens to be a very accessible dialog, so that would address several concerns we'd otherwise have with the current modal.
It would have to work a little differently, but if you add
core/drupal.dialogas a dependency, this is roughly what would be needed in the callback that is invoked when someone clicks "download"Drupal.dialog(document.querySelector('#the-id-of-the-element-created-in-prior-step')).showModal()When the modal closes ,it automatically removes the modal content DOM element, so you could re-use the same ID, and would not have to worry about a bunch of visually hidden former modals stacking up.
Comment #13
narendrarComment #15
narendrarUsed
Drupal.dialogand removed svelte modal.Comment #16
srishtiiee commentedThe code is largely simplified with this new implementation and works as expected (has enhanced its accessibility rather).
The one thing that is missing is that the background scrolling on the page should be disabled when a modal/dialog is opened. Marking NW for this one change, everything else is good to go otherwise.
Comment #17
narendrarVery good point @srishtiiee.
A discussion is going around it at https://www.drupal.org/project/drupal/issues/2707291 and may be we don't need to do it explicitly here.
Comment #18
bnjmnmWe definitely don't need to address the scrolling, that's a drupal.dialog issue and #2707291: Disable body-level scrolling when a dialog is open as a modal is the proper home for it. Project Browser doesn't need to figure that one out.
Spotted one thing in the MR that I'd like changed so setting to NW, but overall looks good. Also rerolled to make things a little easier.
Comment #19
narendrarComment #20
bnjmnmLooks good! Test are running again because I rebased, but it'll switch out of the RTBC if for some reason the tests stop passing.
Comment #22
tim.plunkettMerged, thanks!
Comment #24
tim.plunkett