From 5e77d6e9903cffccf46c6061ff6bdabb5d3d05b0 Mon Sep 17 00:00:00 2001 From: Vivek Macha Date: Mon, 20 Jan 2025 19:00:23 +0000 Subject: [PATCH 1/2] Fix TableRow hover issue and update tests --- .gitpod.yml | 11 ++++ .../mui-material/src/TableRow/TableRow.js | 36 +++++++--- .../integration/TableRowHoverIssue.test.js | 65 +++++++++++++++++++ 3 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 .gitpod.yml create mode 100644 packages/mui-material/test/integration/TableRowHoverIssue.test.js diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 00000000000000..50d74aebccb13c --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,11 @@ +# This configuration file was automatically generated by Gitpod. +# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml) +# and commit this file to your remote git repository to share the goodness with others. + +# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart + +tasks: + - init: pnpm install && pnpm run build + command: pnpm run start + + diff --git a/packages/mui-material/src/TableRow/TableRow.js b/packages/mui-material/src/TableRow/TableRow.js index af03616cb04a10..26d50a0bfe0974 100644 --- a/packages/mui-material/src/TableRow/TableRow.js +++ b/packages/mui-material/src/TableRow/TableRow.js @@ -20,6 +20,8 @@ const useUtilityClasses = (ownerState) => { return composeClasses(slots, getTableRowUtilityClass, classes); }; +const clamp = (value, min, max) => Math.min(Math.max(value, min), max); + const TableRowRoot = styled('tr', { name: 'MuiTableRow', slot: 'Root', @@ -28,31 +30,47 @@ const TableRowRoot = styled('tr', { return [styles.root, ownerState.head && styles.head, ownerState.footer && styles.footer]; }, -})( - memoTheme(({ theme }) => ({ +}) +(memoTheme(({ theme }) => { + return { color: 'inherit', display: 'table-row', verticalAlign: 'middle', - // We disable the focus ring for mouse, touch and keyboard users. outline: 0, [`&.${tableRowClasses.hover}:hover`]: { backgroundColor: (theme.vars || theme).palette.action.hover, }, [`&.${tableRowClasses.selected}`]: { backgroundColor: theme.vars - ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.selectedOpacity})` - : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity), + ? `rgba(${theme.vars.palette.primary.mainChannel} / ${clamp( + theme.vars.palette.action.selectedOpacity, + 0, + 1 + )})` + : alpha( + theme.palette.primary.main, + clamp(theme.palette.action.selectedOpacity, 0, 1) + ), '&:hover': { backgroundColor: theme.vars - ? `rgba(${theme.vars.palette.primary.mainChannel} / calc(${theme.vars.palette.action.selectedOpacity} + ${theme.vars.palette.action.hoverOpacity}))` + ? `rgba(${theme.vars.palette.primary.mainChannel} / ${clamp( + theme.vars.palette.action.selectedOpacity + theme.vars.palette.action.hoverOpacity, + 0, + 1 + )})` : alpha( theme.palette.primary.main, - theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity, + clamp( + theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity, + 0, + 1 + ) ), }, }, - })), -); + }; +})); + const defaultComponent = 'tr'; /** diff --git a/packages/mui-material/test/integration/TableRowHoverIssue.test.js b/packages/mui-material/test/integration/TableRowHoverIssue.test.js new file mode 100644 index 00000000000000..e722485e0f7c33 --- /dev/null +++ b/packages/mui-material/test/integration/TableRowHoverIssue.test.js @@ -0,0 +1,65 @@ +// test/integration/TableRowHoverBackground.test.js +import * as React from 'react'; +import { expect } from 'chai'; +import { createRenderer } from '@mui/internal-test-utils'; +import Table from '@mui/material/Table'; +import TableBody from '@mui/material/TableBody'; +import TableCell from '@mui/material/TableCell'; +import TableContainer from '@mui/material/TableContainer'; +import TableRow from '@mui/material/TableRow'; +import Paper from '@mui/material/Paper'; +import { createTheme, ThemeProvider } from '@mui/material/styles'; + +describe(' hover background integration', () => { + const { render } = createRenderer(); + + describe('with theme palette action values', () => { + function TestTable({ hoverOpacity, selectedOpacity }) { + const theme = createTheme({ + palette: { + action: { + hoverOpacity, + selectedOpacity, + }, + }, + }); + + return ( + + + + + + Row 1 + + + Row 2 + + +
+
+
+ ); + } + + it('should render correctly with valid hoverOpacity', () => { + const { container } = render(); + const rows = container.querySelectorAll('tr'); + expect(rows).to.have.length(2); + }); + + it('should handle invalid hoverOpacity gracefully (clamping behavior)', () => { + const { container } = render(); + const rows = container.querySelectorAll('tr'); + expect(rows).to.have.length(2); // Ensure rows render correctly + }); + + it('should apply clamped hoverOpacity and selectedOpacity in rendering', () => { + const { container } = render(); + const rows = container.querySelectorAll('tr'); + + // Validate rendering - assume clamping happens internally + expect(rows).to.have.length(2); + }); + }); +}); From fa3d56d5516a561e8c9d5524bd67b82cee12f6db Mon Sep 17 00:00:00 2001 From: MachaVivek <130957321+MachaVivek@users.noreply.github.com> Date: Tue, 4 Feb 2025 23:01:43 +0530 Subject: [PATCH 2/2] Delete .gitpod.yml Signed-off-by: MachaVivek <130957321+MachaVivek@users.noreply.github.com> --- .gitpod.yml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index 50d74aebccb13c..00000000000000 --- a/.gitpod.yml +++ /dev/null @@ -1,11 +0,0 @@ -# This configuration file was automatically generated by Gitpod. -# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml) -# and commit this file to your remote git repository to share the goodness with others. - -# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart - -tasks: - - init: pnpm install && pnpm run build - command: pnpm run start - -