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

[Checkbox, Menu, and Radio] Fix: Update keepMounted Prop Logic for Inline Elements #1329

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

onehanddev
Copy link
Contributor

@onehanddev onehanddev commented Jan 13, 2025

Overview

This pull request addresses the behavior of the keepMounted prop across several components, ensuring that the hidden attribute is not applied when keepMounted is set to true. This change affects the CheckboxIndicator, MenuCheckboxItemIndicator, MenuRadioItemIndicator, and RadioIndicator components.

Fixes #1298

@mui-bot
Copy link

mui-bot commented Jan 13, 2025

Netlify deploy preview

https://deploy-preview-1329--base-ui.netlify.app/

Generated by 🚫 dangerJS against c09a5d9

@onehanddev onehanddev marked this pull request as draft January 13, 2025 11:41
Copy link

netlify bot commented Jan 13, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 0cb08ff
🔍 Latest deploy log https://app.netlify.com/sites/base-ui/deploys/678e2bb2431aee0007ff6b05
😎 Deploy Preview https://deploy-preview-1329--base-ui.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.

@onehanddev onehanddev marked this pull request as ready for review January 15, 2025 09:17
@zannager zannager added component: menu This is the name of the generic UI component, not the React module! component: checkbox This is the name of the generic UI component, not the React module! component: radio This is the name of the generic UI component, not the React module! labels Jan 15, 2025
@onehanddev
Copy link
Contributor Author

I was wondering—do we still need the hidden prop? It seems the only scenario where it was set to true was when the keepMounted prop was used on the Indicator. Now that we’re removing that logic, I’m unsure if it’s still necessary.

@atomiks
Copy link
Contributor

atomiks commented Jan 16, 2025

do we still need the hidden prop

Nope, it can be removed entirely for the indicator components

Comment on lines 64 to 66
await waitFor(() => {
expect(screen.getByTestId('indicator')).to.have.attribute('hidden');
});
Copy link
Contributor

@atomiks atomiks Jan 17, 2025

Choose a reason for hiding this comment

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

I think each of these tests can be kept, just check for null instead of hidden (removing the keepMounted prop in the test)?

Comment on lines -34 to -38
<Radio.Indicator
className="animation-test-indicator"
keepMounted
data-testid="indicator-a"
/>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@atomiks while reverting the test cases removal commit, I have found that the keepMounted will always be true for Radio.Indicator component (refer: radio/indicator/RadioIndicator.tsx), which is not the case for other components, is this an expected behaviour or unintended ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for spotting - that's unintended. All indicators should unmount by default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@atomiks I set it to false by default, like other indicator components. I also reverted the test cases you suggested earlier. Instead of checking for hidden props, I now check if the indicator element exists. Please check the latest commit and let me know if any modifications are needed.

…ent exists instead of its hidden state, set keepMounted to false by default for RadioIndicator like the rest of the Indicator components.
Copy link
Contributor

@atomiks atomiks left a comment

Choose a reason for hiding this comment

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

Looks great, just need to run pnpm proptypes && pnpm docs:api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: checkbox This is the name of the generic UI component, not the React module! component: menu This is the name of the generic UI component, not the React module! component: radio This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't apply hidden when keepMounted=true for inline elements
4 participants