Skip to content

[fixed] Multiple modals on page causing contradictory class updates #328

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

Closed
wants to merge 16 commits into from
Closed

[fixed] Multiple modals on page causing contradictory class updates #328

wants to merge 16 commits into from

Conversation

fuller
Copy link
Contributor

@fuller fuller commented Feb 17, 2017

Changes proposed:

  • Modals should only update if they are either opening or closing. If they will remained closed then there is no reason to run the renderPortal() method.

Fixes #218 #231 #308

Used the tests from #326

Acceptance Checklist:

  • All commits have been squashed to one.
  • The commit message follows the guidelines in CONTRIBUTING.md.
  • Documentation (README.md) and examples have been updated as needed.
  • If this is a code change, a spec testing the functionality has been added.
  • If the commit message has [changed] or [removed], there is an upgrade path above.

claydiffrient and others added 15 commits December 31, 2016 14:49
* Add linting

* Make specs pass linter

* Make lib/helpers pass linter

* Make lib/components pass linter

This also does some signfiicant refactoring of the code
to appease the linter's pro-ES2015+ stance.

closes #289
closes #286

* Make travis run the lint task as well as specs

closes #284
* [fixed] Make use of es6 modules

* [fixed] Fix `this` scope
* Add sauce labs testing info to karma

This also removes Node versions 4, 5, 6 from Travis.  The node
version only matters for development not for use.  I don't
think it's a problem officially supporting only the latest node
for development.

* Make specs work under IE 11
this PR allow a stack of modals to give back focus
to parent modal.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.9%) to 79.57% when pulling 6098432 on ajfuller:feature/isOpen-false-no-update into ebec638 on reactjs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 79.928% when pulling 2e92ab8 on ajfuller:feature/isOpen-false-no-update into ebec638 on reactjs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 79.928% when pulling 2e92ab8 on ajfuller:feature/isOpen-false-no-update into ebec638 on reactjs:master.

Copy link
Collaborator

@diasbruno diasbruno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately regarding 'ReactModal__Body--open', it won't fix the case where many modals are stacked and the class should be removed only when the stack is empty.

renderModal({ isOpen: true });
expect(classList.contains(expectedBodyClass)).toBe(true);
unmountModal();
expect(classList.contains(expectedBodyClass)).toBe(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the problem. 2 modals were opened, one of those is unmounted, so document.body should actually have the class ReactModal__Body--open.

The class should be removed only if all modals were closed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh you're right I reversed that test inadvertently 😿

So the design decision is to allow for modal stacking then? I naively assumed from both an accessibility and UX perspective it should only allow one modal at a time to show. Would there be any consideration to disallowing stacking or is that firmly part of the component?

Thanks for the review and help understanding!

Copy link
Collaborator

@diasbruno diasbruno Feb 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any accessibility and UX problem on stacking modals (regarding that we get to manage the focus and open/exit modals correctly).

Modal should block the UI for a single context or scope (my view). Different from a window or popup.

Hope it make sense.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the correct fix for this issue is to have some sorta manager to deal with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have pretty strict guidelines around modals not being stackable, but I understand that it is not a universal guideline, so keeping the component flexible makes sense.

I'll likely continue to use the shouldComponentUpdate approach within my composition of the component, but feel free to close if it's not the direction you're looking for 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using redux or a normal component state, you can set an state to avoid opening more modals at the same time.

Just to illustrate the idea:

{ currentModal: null } // can open
{ currentModal: 'my-modal-1' } // already in use

@diasbruno
Copy link
Collaborator

Related issue #335.

@AndersDJohnson
Copy link
Contributor

Relates to #358.

@diasbruno
Copy link
Collaborator

@ajfuller Thank you so much for the attention to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Open two modals. Hit ESC then hit ECS but nothing happens
7 participants