From 93fdbe0d9ac5ad52e069c45131e8f0ca200602ac Mon Sep 17 00:00:00 2001 From: Lucas Hilgert <77863078+lhilgert9@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:47:15 +0100 Subject: [PATCH] [material-next][ButtonGroup] Change `ButtonGroup` files to ts (#39794) --- .../mui-material-next/src/Button/Button.tsx | 7 +- ...ttonGroup.test.js => ButtonGroup.test.tsx} | 38 +++---- .../{ButtonGroup.js => ButtonGroup.tsx} | 98 +++++++++++-------- ...{ButtonGroup.d.ts => ButtonGroup.types.ts} | 28 +++--- .../ButtonGroup/ButtonGroupButtonContext.ts | 4 +- .../src/ButtonGroup/ButtonGroupContext.ts | 6 +- .../src/ButtonGroup/index.d.ts | 4 - .../src/ButtonGroup/{index.js => index.ts} | 2 + 8 files changed, 102 insertions(+), 85 deletions(-) rename packages/mui-material-next/src/ButtonGroup/{ButtonGroup.test.js => ButtonGroup.test.tsx} (89%) rename packages/mui-material-next/src/ButtonGroup/{ButtonGroup.js => ButtonGroup.tsx} (83%) rename packages/mui-material-next/src/ButtonGroup/{ButtonGroup.d.ts => ButtonGroup.types.ts} (87%) delete mode 100644 packages/mui-material-next/src/ButtonGroup/index.d.ts rename packages/mui-material-next/src/ButtonGroup/{index.js => index.ts} (51%) diff --git a/packages/mui-material-next/src/Button/Button.tsx b/packages/mui-material-next/src/Button/Button.tsx index abd855b542db19..42757a3d1d994a 100644 --- a/packages/mui-material-next/src/Button/Button.tsx +++ b/packages/mui-material-next/src/Button/Button.tsx @@ -374,7 +374,10 @@ const Button = React.forwardRef(function Button< >(inProps: ButtonProps, ref: React.ForwardedRef) { const contextProps = React.useContext(ButtonGroupContext); const buttonGroupButtonContextPositionClassName = React.useContext(ButtonGroupButtonContext); - const resolvedProps = resolveProps(contextProps as ButtonProps, inProps); + const resolvedProps = resolveProps( + (contextProps ?? {}) as ButtonProps, + inProps, + ); const props = useThemeProps({ props: resolvedProps, name: 'MuiButton' }); const { children, @@ -412,7 +415,7 @@ const Button = React.forwardRef(function Button< ref, }, ownerState, - className: clsx(contextProps.className, positionClassName), + className: clsx(contextProps?.className, positionClassName), }); const startIcon = startIconProp && ( diff --git a/packages/mui-material-next/src/ButtonGroup/ButtonGroup.test.js b/packages/mui-material-next/src/ButtonGroup/ButtonGroup.test.tsx similarity index 89% rename from packages/mui-material-next/src/ButtonGroup/ButtonGroup.test.js rename to packages/mui-material-next/src/ButtonGroup/ButtonGroup.test.tsx index 74c70dabaeabe6..520593c6e52180 100644 --- a/packages/mui-material-next/src/ButtonGroup/ButtonGroup.test.js +++ b/packages/mui-material-next/src/ButtonGroup/ButtonGroup.test.tsx @@ -4,19 +4,20 @@ import { createRenderer, describeConformance, screen } from '@mui-internal/test- import ButtonGroup, { buttonGroupClasses as classes } from '@mui/material-next/ButtonGroup'; import { CssVarsProvider, extendTheme } from '@mui/material-next/styles'; import Button, { buttonClasses } from '@mui/material-next/Button'; -import ButtonGroupContext from './ButtonGroupContext'; +import ButtonGroupContext, { ButtonGroupContextType } from './ButtonGroupContext'; describe('', () => { const { render } = createRenderer(); - let originalMatchmedia; + let originalMatchmedia: typeof window.matchMedia; beforeEach(() => { originalMatchmedia = window.matchMedia; - window.matchMedia = () => ({ - addListener: () => {}, - removeListener: () => {}, - }); + window.matchMedia = () => + ({ + addListener: () => {}, + removeListener: () => {}, + } as unknown as MediaQueryList); }); afterEach(() => { window.matchMedia = originalMatchmedia; @@ -119,9 +120,10 @@ describe('', () => { }); it('should have a ripple by default', () => { + const props = { TouchRippleProps: { classes: { root: 'touchRipple' } } }; const { container } = render( - + , ); expect(container.querySelector('.touchRipple')).not.to.equal(null); @@ -138,9 +140,10 @@ describe('', () => { }); it('can disable the ripple', () => { + const props = { TouchRippleProps: { classes: { root: 'touchRipple' } } }; const { container } = render( - + , ); expect(container.querySelector('.touchRipple')).to.equal(null); @@ -181,24 +184,25 @@ describe('', () => { }); it('should forward the context to children', () => { - let context; + let context: ButtonGroupContextType | null; render( {(value) => { context = value; + return