Skip to content

[TabContext] Introduced new prop to allow deterministic button ids on tabs#47715

Open
filipomar wants to merge 1 commit intomui:masterfrom
filipomar:master
Open

[TabContext] Introduced new prop to allow deterministic button ids on tabs#47715
filipomar wants to merge 1 commit intomui:masterfrom
filipomar:master

Conversation

@filipomar
Copy link

While running my own tests, which relied on the tabs, I couldn't get a deterministic snapshot of them.
I have visited this issue before on PR #38192 (but got side tracked)
And it fixes Issue #32038

I decided to make a simpler set of changes this time around, simply exposing the Math.random to be replaced.

@mui-bot
Copy link

mui-bot commented Feb 3, 2026

Netlify deploy preview

https://deploy-preview-47715--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 🔺+19B(+0.06%) 🔺+12B(+0.15%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against fb2fb43

Copy link
Member

@mj12albert mj12albert left a comment

Choose a reason for hiding this comment

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

The generated ids are an implementation detail of the library and snapshot tests aren't great for this reason

Have you tried mocking Math.random in your tests as suggested in the comments of the linked issue?

@filipomar
Copy link
Author

The generated ids are an implementation detail of the library and snapshot tests aren't great for this reason

Have you tried mocking Math.random in your tests as suggested in the comments of the linked issue?

Yes, we are mocking them as linked on the original PR and that works "fine".

However I find it cumbersome to have to have this additional mocking and wanted a way to provide my own generated ids (through this PR) so that is also not needed anymore.

Regarding this PR, if this solution isn't good enough, I could probably work on an alternative with a non random and non injected id as well.
How do you feel about it?

@filipomar filipomar requested a review from mj12albert February 4, 2026 13:23
@zannager zannager added the scope: tabs Changes related to the tabs. label Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: tabs Changes related to the tabs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tabs] Snapshot test not matching

4 participants