-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[ButtonBase][material-next] Add ButtonBase component #38319
Conversation
Netlify deploy previewhttps://deploy-preview-38319--material-ui.netlify.app/ @mui/material-next: parsed: +0.24% , gzip: +0.15% Bundle size reportDetails of bundle changes (Toolpad) |
bb835d6
to
e387775
Compare
e387775
to
b236c84
Compare
Co-authored-by: Albert Yu <[email protected]> Signed-off-by: Diego Andai <[email protected]>
Co-authored-by: Albert Yu <[email protected]> Signed-off-by: Diego Andai <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, left few comments for consideration before merging
@@ -1,43 +1,22 @@ | |||
'use client'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering we are now using Base UI, we have support for whether the button should be focusable when disabled which should allow developers to setup the button anyway that works for them. |
Summary
This PR adds the
ButtonBase
component tomaterial-next
and refactors the existingButton
accordingly.Why bring back ButtonBase
Base UI’s
useButton
extracts most of the logic for whichButtonBase
was used in v5, but some things are material-specific or style-specific that it doesn't:focusVisible
imperative handle (reference)button
's element default styles (reference)href
(orto
) is provided (reference)These four things will be shared by the “button-like” components:
Button
,FAB
,IconButton
,Tabs
, and clickableChip
. This is why I propose bringing back theButtonBase
component.Keeping
ButtonBase
has two additional beneficial effects:ButtonBase
.It’s essential to keep in mind that it shouldn’t be overused. For example, if a component only needs the ripple, it should use the ripple hooks and components directly, not
ButtonBase
. This way, we will keepButtonBase
's scope controlled.Changes
ButtonBase
component, based on Base UI’suseButton
:ButtonBase
v5focusRipple
and ripple’s pulsate tests as Material You no longer used a ripple for the focused state (benchmark).ButtonBase
would have atabIndex = -1
by default. This is not maintained in theuseButton
hook (test change)onKeyUp
default,muiPreventDefault
is used (change here)Button
component to useButtonBase
Button
folder to theButtonBase
folder.Important note for reviewers
The first commit copies files from v5, so if you want to review actual changes, exclude that commit when looking at the files. For some reason, the only file this isn't working for is
ButtonBase.tsx
; sorry for that.Questions for reviewers
touchRippleRef
prop was deleted when theButton
was added tomaterial-next
. When addingButtonBase
, I kept it. Do you think we should remove it?tabIndex = -1
not added when the button is disabled be a breaking change? I don’t think it is, but maybe I’m missing something.muiPreventDefault
breaking change explanation correct?