Skip to content

New: allow multiple modals (fix #101)#127

Closed
xfra35 wants to merge 1 commit intokylefox:masterfrom
xfra35:unique
Closed

New: allow multiple modals (fix #101)#127
xfra35 wants to merge 1 commit intokylefox:masterfrom
xfra35:unique

Conversation

@xfra35
Copy link
Copy Markdown
Contributor

@xfra35 xfra35 commented Oct 23, 2015

Here's a code change proposal to allow multiple modals to be opened at the same time (#101).

In short:

  • the current variable is replaced by a modals array
  • a new unique option is introduced, which determines if the new modal should be unique or not (i.e if existing modals should be closed or not). This option defaults to true, in order to keep backwards compatibility
  • only one blocker is used for any number of modals
  • the front modal gets the current class while the other ones get the behind class, thus allowing any styling for the modals in background

A test demo is visible here.

NB: if you're interested in this change, as well as the one suggested in #110, you might be interested by the merging result of those two, which I prepared as well (I needed it for a project).

@hultberg
Copy link
Copy Markdown

I was worried about this change as I have always used the modals with the thought of just one being visible at the time, but then I read about unique being true as default then: 👍

@kylefox
Copy link
Copy Markdown
Owner

kylefox commented Oct 24, 2015

Cool, looks good! I can't say I've ever needed multiple modals myself, but the request for multiple modals has come up before so it seems legit 🍔

A couple things to sort out before I merge:

  1. Blocking previous modals: Because modals are just being stacked on top of each other, nothing is preventing the user from interacting with "inactive" modals deeper in the stack. See here for an example. I think each modal should probably have it's own (transparent) blocker layer so that the user cannot interact with anything except the currently active modal. Thoughts?
  2. Events: I wonder if we need to add a new event to indicate when all the modals have closed because we can no longer assume that CLOSE means the page has returned to it's non-modal state. For example, if you have two open modals and you close them, maybe the event sequence should be:
    1. "modal:close" (second modal)
    2. "modal:close" (first modal)
    3. "modal:unblock" (all modal are now closed)
  3. REAME: Please update the README to include a description of your new unique option and any other details that explain how to use multiple modals.

@damreywil
Copy link
Copy Markdown

+1

Was about to sit down and extend the plugin with this same functionality. Glad I checked out the issues first. ;)

Can I suggest going with solo vs unique as the option name?

@kylefox
Copy link
Copy Markdown
Owner

kylefox commented Oct 30, 2015

I'm not crazy about unique or solo — when I think of modals, that just how I expect them to work. Turn an assumed behavior to false seems backwards to me. I think it should be opting in to non-default behavior.

For example, instead of unique: false to get multiple modals, how about multiple: true or stacked: true (with the default of false)?

@damreywil
Copy link
Copy Markdown

Agreed. Definitely should be added as an opt-in option to allow the behavior, and the default settings should keep the behavior intact as it stands now without the option. I assumed solo: true by default, and setting it tofalse would "stack" the new instance on top of any open modals.

The example use case I'm running into right now is, I have a modal with a form which has rules & privacy links. The rules & privacy content are both setup as individual modals which are linked to from other parts of the application apart from the form modal links. I don't want to close out the form to show the rules, but rather just have the additional modals displayed on top of the form modal.

@xfra35
Copy link
Copy Markdown
Contributor Author

xfra35 commented Oct 30, 2015

@kylefox I had first named it multiple, until I realized it was not such a good idea since this setting defines the behaviour of each modal. In other words, it feels weird to require a single modal to be "multiple". That's where came the "unique" word.

Now that you're raising the point, maybe we could use a verb instead of an adjective: closeAll: true? That's indeed the sole purpose of this setting: to close or not to close existing modals.

@kylefox
Copy link
Copy Markdown
Owner

kylefox commented Oct 30, 2015

@xfra35 Good point. closeAllBeforeOpen or closeAllOnOpen ? It's longer but I think a bit more clear.

Appreciate the thought everyone is putting into this 😎

@kylefox
Copy link
Copy Markdown
Owner

kylefox commented Oct 30, 2015

Or maybe closeExisting ?

@hultberg
Copy link
Copy Markdown

closeExisting sounds good.

What is the status of this PR? I see that the author must resolve some conflicts.

@xfra35
Copy link
Copy Markdown
Contributor Author

xfra35 commented Feb 20, 2016

Sorry guys, was so busy at that time that I've completely missed it. Will try to merge it in a week or two.

@kylefox
Copy link
Copy Markdown
Owner

kylefox commented Feb 25, 2016

Cool, thanks for bumping this @hultberg — I think it would be a valuable addition :)

@xfra35
Copy link
Copy Markdown
Contributor Author

xfra35 commented Mar 14, 2016

Hey guys, I finally had time to dig into this PR. I've refactored it in #146.

@xfra35 xfra35 closed this Mar 14, 2016
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.

4 participants