Skip to content

Conversation

@timfuhrmann
Copy link
Contributor

@timfuhrmann timfuhrmann commented Oct 28, 2025

If you wanted to apply ModalPresence to a shared modal, you had to either individually wrap your component for every occurrence:

// definition
export const MyModal = ({ onSubmit, onClose }) => {
    ...
}

// usage
<ModalPresence open={open}>
   <MyModal onSubmit={noop} onClose={noop} />
</ModalPresence>

or compose your modal differently:

// definition
export const MyModal = () => {
    return (
      <ModalPresence>
           <MyModalContent onSubmit={noop} onClose={noop} />
      </ModalPresence>
    )
}

const MyModalContent = ({ onSubmit, onClose }) => {
    ...
}

// usage
<MyModal open={open} onSubmit={noop} onClose={noop} />

To improve the DX, this PR adds higher-order functions for both ModalPresence and ComposedModalPresence:

// definition
export const MyModal = withModalPresence(
  ({ onSubmit, onClose }) => {
    ...
  },
);

// usage
<MyModal open={open} onSubmit={noop} onClose={noop} />

This helps maintaining re-usability while improving DX.

Changelog

New

  • withModalPresence
  • withComposedModalPresence

Testing / Reviewing

  • Define your shared modal component using withModalPresence
  • Call your modal component
  • See if it unmounts/mounts

PR Checklist

As the author of this PR, before marking ready for review, confirm you:

  • Reviewed every line of the diff
  • Updated documentation and storybook examples
  • Wrote passing tests that cover this change
  • Addressed any impact on accessibility (a11y)
  • Tested for cross-browser consistency
  • Validated that this code is ready for review and status checks should pass

More details can be found in the pull request guide

@timfuhrmann timfuhrmann requested a review from a team as a code owner October 28, 2025 10:58
@timfuhrmann
Copy link
Contributor Author

I have not added tests, since it's simply calling ModalPresence, which is covered by test already. Please let me know, if you don't agree.

@netlify
Copy link

netlify bot commented Oct 28, 2025

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 96858c1
🔍 Latest deploy log https://app.netlify.com/projects/carbon-elements/deploys/6900a1c31bcd1e0008bc5ecf
😎 Deploy Preview https://deploy-preview-20826--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 project configuration.

@netlify
Copy link

netlify bot commented Oct 28, 2025

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 96858c1
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/6900a1c32bde7000085afe5a
😎 Deploy Preview https://deploy-preview-20826--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 project configuration.

@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.19%. Comparing base (84b09fc) to head (96858c1).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20826      +/-   ##
==========================================
+ Coverage   92.46%   97.19%   +4.73%     
==========================================
  Files         508      151     -357     
  Lines       35753    21294   -14459     
  Branches     5673      815    -4858     
==========================================
- Hits        33058    20697   -12361     
+ Misses       2550      589    -1961     
+ Partials      145        8     -137     
Flag Coverage Δ
main-packages ?
web-components 97.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@netlify
Copy link

netlify bot commented Oct 28, 2025

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit 96858c1
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/6900a1c3888d130008c74ff9
😎 Deploy Preview https://deploy-preview-20826--v11-carbon-web-components.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 project configuration.

Copy link
Member

@emyarod emyarod left a comment

Choose a reason for hiding this comment

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

looks good to me!

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.

2 participants