Skip to content
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

feat: Nest modal support #14320

Merged
merged 17 commits into from
Feb 22, 2024

Conversation

davidmenendez
Copy link
Contributor

Closes #14104

this is a concept for nested modal support changes. the general idea with this PR was just to demonstrate that a few small changes could make nested modal support possible. i wanted to gauge reception before continuing to integrate all the necessary testing and functionality that needs to be modified.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 26, 2023

DCO Assistant Lite bot All contributors have signed the DCO.

@netlify
Copy link

netlify bot commented Jul 26, 2023

Deploy Preview for v11-carbon-react ready!

Name Link
🔨 Latest commit 71a8f64
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/65d64cf3d437fa00086ea433
😎 Deploy Preview https://deploy-preview-14320--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Jul 26, 2023

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit cefbf94
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/6525b42ed84d58000851995d
😎 Deploy Preview https://deploy-preview-14320--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Very cool to see this working! I'm not sure if we could make this change right now though with the way it's proposed here.

Focus sentinel
</span>
</div>
<Portal>
Copy link
Member

Choose a reason for hiding this comment

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

I think that rendering the modal in a portal by default would be a breaking change. The majority of usage in the wild probably already renders the modal via a portal and would result in nested portals. Users could/would run into not being able to access events of the innermost portal, facebook/react#14540

Copy link
Member

Choose a reason for hiding this comment

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

One way to evaluate backwards compatibility would be to leave the existing 'with state manager' story as-is and use it as a testing grounds for how most modals are used right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point

@tay1orjones
Copy link
Member

The lack of focus returning to the trigger element that opened the modal (#13680) is particularly glaring when keyboard navigating through the nested modals.

Figuring out a fix that is compatible with both non-nested and nested modals would be really nice. I'm not sure if it's a full blocker to landing nested modals here, but it's close.

@andreancardona
Copy link
Contributor

@davidmenendez Hey David - let us know if you have any other questions here!

@davidmenendez
Copy link
Contributor Author

apologies. been busy! i'll be looking at this today

@davidmenendez
Copy link
Contributor Author

@tay1orjones i'll continue to look at the keyboard issues. i just pushed up a change to revert the portal issue you pointed out. the story uses the original ModalStateManager but it's using the internal Portal component. When you get a chance please let me know what you think about this implementation.

@davidmenendez
Copy link
Contributor Author

@tay1orjones whenever you have a chance to re-review it would be greatly appreciated!

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Hey sorry for the delay. I left some comments below, I'm mainly worried about how ubiquitous modals are and if this change steps into the realm of being a breaking change.

Also I think it would be great if we could confirm support for the new launcherButtonRef functionality added in #14355 works in the nested situation.

packages/styles/scss/components/modal/_modal.scss Outdated Show resolved Hide resolved
packages/react/src/components/Modal/Modal.js Outdated Show resolved Hide resolved
@tay1orjones
Copy link
Member

Additionally I just noticed that when pressing escape with both modals open, both modals close instead of just the second one.

@davidmenendez
Copy link
Contributor Author

thanks for the feedback! will work through this and reply soon

@andreancardona
Copy link
Contributor

@davidmenendez Hey David, just thought I'd follow up here :)

@davidmenendez
Copy link
Contributor Author

apologies. i've gotten a little behind on this. still a priority. i'll have a follow up ASAP!

@davidmenendez
Copy link
Contributor Author

double apologies. i'm working on this today 😬

@davidmenendez
Copy link
Contributor Author

davidmenendez commented Dec 6, 2023

@tay1orjones thanks for the feedback. yeah after reevaluating it i don't think the background element was necessary and i was able to make the necessary changes to get the support to work with the current implementation. the escape button should work now, but you have to remove the onBlur handler to get it work properly. the last little hurdle appears to be fixing that issue, which appears to happen because focus isn't being properly assigned to the child modal once it's opened.

just wanted to get your feedback before i continue to chip away at this.

@ferdelamad
Copy link

Hello 👋 , thanks @davidmenendez for adding this feature!
Can the evt.stopPropagation(); also be added to the ComposedModal please?

Are there any plans to merge and release this feature soon?

Thanks for all the hard work on carbon 🙌

@davidmenendez
Copy link
Contributor Author

@ferdelamad seems reasonable.

Can the evt.stopPropagation(); also be added to the ComposedModal please?

@tay1orjones any thoughts?

@tay1orjones
Copy link
Member

@davidmenendez Sorry for the delay here, was out for the holidays. I so appreciate your continued effort on this! In addition to the focus/onBlur fix you mention, I have a couple other thoughts:

  • Portal is an internal helper component and is not exported. Looking at the source, I don't think there's anything particularly special in there anyway. Could the storybook example be updated to invoke ReactDOM.createPortal() again?
  • Eventually, just before merging, I'd like to remove the nested story. Due to the UX concerns, nested modals aren't something we want to "recommend" by having a story for it.
  • That said, I think it's important to document in a new section in Modal.mdx: "Nesting of modals isn't recommended due to various UX concerns, but there should be no blockers to implementing nested modals. Here is an example" - and link out to a stackblitz essentially containing what the nested story contains right now
  • I don't see why we couldn't add the fix to ComposedModal as well

It's really interesting that this so far has boiled down to just the evt.stopPropagation and some example/configuration code in storybook. @ferdelamad I'm eager to get this merged in, with the above ironed out I think this would be in great shape to do so 👍

@davidmenendez
Copy link
Contributor Author

@tay1orjones happy holidays! haha no worries. we've all been on cruise control these past few weeks 😂

thanks for the feedback. i totally agree with your stance on removing the story as to not promote this practice of nested modals and to include such verbiage in the documentation. that's the approach we also want to take in the C4P library. i will make the updates you suggested ASAP 👍

@davidmenendez
Copy link
Contributor Author

@tay1orjones changes made 👍

@davidmenendez
Copy link
Contributor Author

i see there's an issue with the E2E test. i'll investigate and fix ASAP 👍

@davidmenendez
Copy link
Contributor Author

E2E test pass but now percy is failing. i'm not familiar with this testing so i'll have to do some investigation. i would definitely welcome any help there haha

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Awesome, thanks again for the work on this! I think the two remaining ideas can be contained in a new/follow-up PR if you or someone else wants to.

  • That said, I think it's important to document in a new section in Modal.mdx: "Nesting of modals isn't recommended due to various UX concerns, but there should be no blockers to implementing nested modals. Here is an example" - and link out to a stackblitz essentially containing what the nested story contains right now
  • I don't see why we couldn't add the fix to ComposedModal as well

@davidmenendez
Copy link
Contributor Author

yeah i can totally follow back up 👍

Copy link
Member

@tw15egan tw15egan left a comment

Choose a reason for hiding this comment

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

Who knew this is all it took! Thanks for following through with this @davidmenendez 🤘🏻 🎉

@tw15egan tw15egan added this pull request to the merge queue Feb 22, 2024
Merged via the queue into carbon-design-system:main with commit 688a183 Feb 22, 2024
22 checks passed
mHuzefa pushed a commit to mHuzefa/carbon that referenced this pull request Feb 27, 2024
* feat: nested modal support

* fix: revert portal change

* fix: revert modal background change and add escape

* fix: reorder props

* fix: add prevent default

* fix: remove nested modal story

* fix: revert additional changes to modal story code

* fix: stopPropagation not preventDefault

---------

Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>
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.

[Modal]: Support nested modals
5 participants