Skip to content

[switch] Add value prop - #3676

Merged
atomiks merged 13 commits into
mui:masterfrom
Grafikart:patch-1
Jan 13, 2026
Merged

atomiks merged 13 commits into
mui:masterfrom
Grafikart:patch-1

Conversation

@Grafikart

@Grafikart Grafikart commented Jan 4, 2026 •

Copy link
Copy Markdown
Contributor

Add 'value' prop to SwitchRoot component for form submission. For instance in a project i'm working on I want the value "1" or "0".

Closes #3410

Add 'value' prop to SwitchRoot component for form submission.

Signed-off-by: Jonathan <[email protected]>
@pkg-pr-new

pkg-pr-new Bot commented Jan 4, 2026 •

Copy link
Copy Markdown
  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3676
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3676
    

commit: 25e7e74

@netlify

netlify Bot commented Jan 4, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 25e7e74
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/696602141ddc910008e8a6bd
😎 Deploy Preview https://deploy-preview-3676--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 project configuration.

@atomiks atomiks added component: switch Changes related to the switch component. type: new feature Expand the scope of the product to solve a new problem. labels Jan 5, 2026
@atomiks

atomiks commented Jan 5, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the contribution - I've linked the issue: #3410

I'm not sure it's this simple though: Checkbox has a value prop but it's a bit more involved. Though this may be due to checkboxes being able to be grouped (CheckboxGroup).

    // React <19 sets an empty value if `undefined` is passed explicitly
    // To avoid this, we only set the value if it's defined
    valueProp !== undefined
      ? { value: (groupContext ? checked && valueProp : valueProp) || '' }
      : EMPTY_OBJECT,

Tests would be good in any case though

@Grafikart

Copy link
Copy Markdown
Contributor Author

@atomiks thanks, I added the same logic as the checkbox and added a test

Comment on lines +313 to +317
/**
* The value submitted with the form when the switch is on.
* By default, switches submit the value "on", matching native checkbox behavior.
*/
value?: string;

@atomiks atomiks Jan 6, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pnpm docs:api needs to be ran to generate the docs for this prop

There are also some lint errors to address

@mui-bot

mui-bot commented Jan 6, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+35B(+0.01%) 🔺+19B(+0.01%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@LukasTy LukasTy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the contribution. 🙏
As James said, please run pnpm prettier && pnpm doc:api.

@LukasTy LukasTy changed the title Add value prop to SwitchRoot component [switch] Add value prop Jan 6, 2026
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jan 7, 2026
Comment thread package.json Resolved
Comment thread package.json Resolved
Signed-off-by: Lukas Tyla <[email protected]>
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jan 8, 2026

@LukasTy LukasTy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. 👍
Adding comments to adjust the test, such that it doesn't break on React <19.

@atomiks
atomiks merged commit 1fee870 into mui:master Jan 13, 2026
atomiks pushed a commit to atomiks/base-ui that referenced this pull request Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: switch Changes related to the switch component. type: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[switch] Accept value prop

5 participants