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?
Command icon 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

hooroomoo created an issue. See original summary.

Vighnesh. made their first commit to this issue’s fork.

Ruturaj Chaubey made their first commit to this issue’s fork.

bnjmnm’s picture

Status: Active » Needs work
bnjmnm’s picture

Issue tags: +Project Browser MVP

narendraR made their first commit to this issue’s fork.

narendrar’s picture

Status: Needs work » Needs review
bnjmnm’s picture

Status: Needs review » Needs work

See 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.

narendrar’s picture

Status: Needs work » Needs review

This 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.

chrisfromredfin’s picture

Title: Remove isFunction() condition in modal.svelte » Simplify Svelte Modal component / usage
Issue summary: View changes
Status: Needs review » Needs work

OK 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 possible {#if state.closeButton} is not needed either, but we should get some confirmation of that before going ahead with removing it.

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...

    if (isFunction(show)) {
      open(show);
    } else {
      close();
    }

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.

bnjmnm’s picture

Good 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.dialog as a dependency, this is roughly what would be needed in the callback that is invoked when someone clicks "download"

  • Create a new DOM element with a unique id that has the contents of what should appear in the modal. It won't be a svelte component, just a plain old dom element
  • 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.

narendrar’s picture

Assigned: Unassigned » narendrar

narendrar’s picture

Assigned: narendrar » Unassigned
Status: Needs work » Needs review

Used Drupal.dialog and removed svelte modal.

srishtiiee’s picture

Status: Needs review » Needs work

The 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.

narendrar’s picture

Status: Needs work » Needs review

Very 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.

bnjmnm’s picture

Status: Needs review » Needs work

We 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.

narendrar’s picture

Status: Needs work » Needs review
bnjmnm’s picture

Status: Needs review » Reviewed & tested by the community

Looks good! Test are running again because I rebased, but it'll switch out of the RTBC if for some reason the tests stop passing.

tim.plunkett made their first commit to this issue’s fork.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Fixed

Merged, thanks!

tim.plunkett’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.