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

[base] Improve API consistency #36970

Merged
merged 16 commits into from Apr 26, 2023
Merged

Conversation

michaldudak
Copy link
Member

@michaldudak michaldudak commented Apr 23, 2023

This PR brings consistency to Base UI components and hooks' parameters and return values:

  1. Whenever a hook needs a ref, it's now called <slot_name>Ref, which matches the get<slot_name>Props` in the return value.
  2. All hooks that accept external refs now return merged refs, so combining multiple hooks on one element is easier. This was proven necessary in several compound components (like menuItem being both a button and a list item). The type of this value is React.RefCallback as using the more general React.Ref caused variance issues.
  3. Type of accepted refs was standardized to React.Ref<Element>
  4. Naming and typing of the forwarded ref in unstyled components were standardized - it's forwardedRef: React.ForwardedRef<Element> (unless a more specific type is needed).
  5. The shape of the definition of unstyled components was standardized - it's React.forwardRef(function Component(props: Props, forwardedRef: React.Ref<Element>) { ... });. Specifically, the generic parameters of forwardRef were removed as they are specified in function arguments.
  6. The disabled value was removed from useButton's returned object. It's not calculated inside the button, so it was pointless to have it.
  7. All unstyled components now receive the generic props (over RootComponentType).
  8. Many generic parameters in unstyled components were given more descriptive names.

@michaldudak michaldudak added the package: base-ui Specific to @mui/base label Apr 23, 2023
@michaldudak michaldudak self-assigned this Apr 23, 2023
@mui-bot
Copy link

mui-bot commented Apr 23, 2023

Netlify deploy preview

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

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against 12ef4d6

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 24, 2023
@michaldudak michaldudak added this to the MUI Base stable release milestone Apr 25, 2023
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 25, 2023
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

The changes make sense 👍

@michaldudak michaldudak added the enhancement This is not a bug, nor a new feature label Apr 25, 2023
@michaldudak michaldudak merged commit 2284631 into mui:master Apr 26, 2023
22 checks passed
@michaldudak michaldudak deleted the hooks-api-consistency branch April 26, 2023 07:17
binh1298 pushed a commit to binh1298/material-ui that referenced this pull request May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is not a bug, nor a new feature package: base-ui Specific to @mui/base
Projects
Status: Recently completed
Development

Successfully merging this pull request may close these issues.

None yet

3 participants