Skip to content

Add modal with transition example #129

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

Conversation

roomman
Copy link

@roomman roomman commented Feb 17, 2022

This PR adds an example of a modal dialog, with nested transitions for the overlay, and modal containter.

@roomman roomman changed the title feat: added model with transition example Add modal with transition example Feb 17, 2022
@roomman
Copy link
Author

roomman commented Feb 17, 2022

Hello all, I would be interested in any feedback on this draft PR, which adds an example of a Modal with Transitions.

Implementing this has exposed a few, minor inconsistencies when compared with the headlessui.dev docs. For example:

  • We need to apply @appear to each Child in a Transition, whereas headlessui applies appear to the Transition's root only.
  • We need to pass isOpen into the Dialog component (else an error is thrown), whereas the headlessui docs say to remove this argument.
  • The Transition component behaves differently to the headlessui implementation, In terms of how it applies classes (see below).

On the last point, headlessui's docs offer this code example:

<TransitionRoot appear :show="isOpen" as="template">
  <span class="inline-block h-screen align-middle" aria-hidden="true">
    &#8203;
  </span>
  <TransitionChild
    as="template"
    enter="duration-300 ease-out"
    enter-from="opacity-0 scale-95"
    enter-to="opacity-100 scale-100"
    leave="duration-200 ease-in"
    leave-from="opacity-100 scale-100"
    leave-to="opacity-0 scale-95"
  >
      <div
        class="inline-block w-full max-w-md p-6 my-8 overflow-hidden text-left align-middle transition-all transform bg-white shadow-xl rounded-2xl"
      >
        {{! more code here }}
      </div>
  </TransitionChild>
</TransitionRoot>

In this example, the transition-all and transform classes are applied to the element nested within the TransitionChild and this is sufficient, and the transition works. The span element (which is used to centre the content on screen) sits above and outside of the TransitionChild.

In this PR the implementation had to be different, to get the transition to work:

<Transition @show={{this.isOpen}} as |t|>
  <t.Child
    @appear={{true}}
    @enter='ease-out duration-300'
    @enterFrom='opacity-0 scale-95'
    @enterTo='opacity-100 scale-100'
    @leave='ease-in duration-200'
    @leaveFrom='opacity-100 scale-100'
    @leaveTo='opacity-0 scale-95'
    class='transition-all transform'
  >
    <span
      class='hidden sm:inline-block sm:align-middle sm:h-screen'
      aria-hidden='true'
    >
      ​
    </span>

    <div
      class='inline-block px-4 pt-5 pb-4 overflow-hidden text-left align-bottom transition-all transform bg-white rounded-lg shadow-xl sm:my-8 sm:align-middle sm:max-w-sm sm:w-full sm:p-6'
    >
    </div>
  </t.Child>
</Transition>

Here, the transition-all and transform classes need to be added to t.Child itself, or the transition wasn't applied to the nested element. The span element has to be nested inside t.Child or the content wasn't aligned properly on the screen.

How consistent do people feel this implementation should be, when compared to the docs over at headlessui? As we don't have any docs yet, I tend to start with the headlessui examples, and then look through tests in this repo, and put the pieces together. How are others working, and is it too early to think about some documentation?

@roomman roomman mentioned this pull request Feb 22, 2022
@roomman roomman force-pushed the add-modal-with-transition-example branch from 4bd52f1 to 3b9cea4 Compare June 1, 2022 14:19
@roomman roomman marked this pull request as ready for review June 1, 2022 14:24
@NullVoxPopuli
Copy link
Collaborator

👋 thanks for this lovely contribution!!

can you delete the package-lock.json?

this repo uses pnpm instead of npm -- so installing deps would be pnpm install instead of npm install.

@roomman
Copy link
Author

roomman commented Jun 1, 2022

@NullVoxPopuli done, thanks.

On a related note, now the project is using pnpm I'm experiencing hanging when I run an ember install... command.

@NullVoxPopuli
Copy link
Collaborator

On a related note, now the project is using pnpm I'm experiencing hanging when I run an ember install... command.

ah! good catch -- we need to upgrade ember-cli for pnpm support. whoops. if you want to do that, that'd be a huge help! <3

@NullVoxPopuli NullVoxPopuli merged commit 751b0e0 into GavinJoyce:master Jun 1, 2022
@NullVoxPopuli NullVoxPopuli added the documentation Improvements or additions to documentation label Jun 1, 2022
@roomman roomman deleted the add-modal-with-transition-example branch June 2, 2022 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants