From ca7cce3b6333913cdab2014f6c7c77d6ec435727 Mon Sep 17 00:00:00 2001 From: sai6855 <60743144+sai6855@users.noreply.github.com> Date: Wed, 21 Dec 2022 15:35:03 +0530 Subject: [PATCH 1/5] scope bug fix --- packages/mui-material/src/TableCell/TableCell.js | 5 +---- .../mui-material/src/TableCell/TableCell.test.js | 12 ++++++++++++ .../mui-material/test/integration/TableCell.test.js | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/mui-material/src/TableCell/TableCell.js b/packages/mui-material/src/TableCell/TableCell.js index 8d7f828cd958f8..ed27f67f415970 100644 --- a/packages/mui-material/src/TableCell/TableCell.js +++ b/packages/mui-material/src/TableCell/TableCell.js @@ -139,10 +139,7 @@ const TableCell = React.forwardRef(function TableCell(inProps, ref) { component = isHeadCell ? 'th' : 'td'; } - let scope = scopeProp; - if (!scope && isHeadCell) { - scope = 'col'; - } + const scope = scopeProp; const variant = variantProp || (tablelvl2 && tablelvl2.variant); diff --git a/packages/mui-material/src/TableCell/TableCell.test.js b/packages/mui-material/src/TableCell/TableCell.test.js index 99ee30b686a351..67304f9260ba4f 100644 --- a/packages/mui-material/src/TableCell/TableCell.test.js +++ b/packages/mui-material/src/TableCell/TableCell.test.js @@ -93,4 +93,16 @@ describe('', () => { const { container } = renderInTable(); expect(container.querySelector('th')).not.to.have.attribute('role'); }); + it('should allow scope to be undefined value even when table cell is within table head', () => { + const { container } = render( + + + + + + +
, + ); + expect(container.querySelector('td')).not.to.have.attribute('scope'); + }); }); diff --git a/packages/mui-material/test/integration/TableCell.test.js b/packages/mui-material/test/integration/TableCell.test.js index 6d1007ed6cceb7..a1c06e06fff611 100644 --- a/packages/mui-material/test/integration/TableCell.test.js +++ b/packages/mui-material/test/integration/TableCell.test.js @@ -21,7 +21,7 @@ describe(' integration', () => { } it('should render a th with the head class when in the context of a table head', () => { - const { getByTestId } = renderInTable(, TableHead); + const { getByTestId } = renderInTable(, TableHead); expect(getByTestId('cell')).to.have.tagName('th'); expect(getByTestId('cell')).to.have.class(classes.root); expect(getByTestId('cell')).to.have.class(classes.head); From 1bc2a4ae4bcbf4373e6c442f05df8e97f5fdcbc3 Mon Sep 17 00:00:00 2001 From: sai6855 <60743144+sai6855@users.noreply.github.com> Date: Wed, 21 Dec 2022 15:54:27 +0530 Subject: [PATCH 2/5] logic fix --- packages/mui-material/src/TableCell/TableCell.js | 8 +++++++- .../mui-material/src/TableCell/TableCell.test.js | 12 ++---------- .../mui-material/test/integration/TableCell.test.js | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/mui-material/src/TableCell/TableCell.js b/packages/mui-material/src/TableCell/TableCell.js index ed27f67f415970..02c268978ccbed 100644 --- a/packages/mui-material/src/TableCell/TableCell.js +++ b/packages/mui-material/src/TableCell/TableCell.js @@ -139,7 +139,13 @@ const TableCell = React.forwardRef(function TableCell(inProps, ref) { component = isHeadCell ? 'th' : 'td'; } - const scope = scopeProp; + let scope = scopeProp; + // https://github.com/mui/material-ui/issues/35031#issuecomment-1359346668 + if (component === 'td') { + scope = undefined; + } else if (!scope && isHeadCell) { + scope = 'col'; + } const variant = variantProp || (tablelvl2 && tablelvl2.variant); diff --git a/packages/mui-material/src/TableCell/TableCell.test.js b/packages/mui-material/src/TableCell/TableCell.test.js index 67304f9260ba4f..2df2e950b4bf98 100644 --- a/packages/mui-material/src/TableCell/TableCell.test.js +++ b/packages/mui-material/src/TableCell/TableCell.test.js @@ -93,16 +93,8 @@ describe('', () => { const { container } = renderInTable(); expect(container.querySelector('th')).not.to.have.attribute('role'); }); - it('should allow scope to be undefined value even when table cell is within table head', () => { - const { container } = render( - - - - - - -
, - ); + it('scope should be undefined in table cell when component is td', () => { + const { container } = renderInTable(); expect(container.querySelector('td')).not.to.have.attribute('scope'); }); }); diff --git a/packages/mui-material/test/integration/TableCell.test.js b/packages/mui-material/test/integration/TableCell.test.js index a1c06e06fff611..6d1007ed6cceb7 100644 --- a/packages/mui-material/test/integration/TableCell.test.js +++ b/packages/mui-material/test/integration/TableCell.test.js @@ -21,7 +21,7 @@ describe(' integration', () => { } it('should render a th with the head class when in the context of a table head', () => { - const { getByTestId } = renderInTable(, TableHead); + const { getByTestId } = renderInTable(, TableHead); expect(getByTestId('cell')).to.have.tagName('th'); expect(getByTestId('cell')).to.have.class(classes.root); expect(getByTestId('cell')).to.have.class(classes.head); From ea415993ea94dba35abea89b17ccc4d0cd66e319 Mon Sep 17 00:00:00 2001 From: sai6855 <60743144+sai6855@users.noreply.github.com> Date: Wed, 21 Dec 2022 16:12:23 +0530 Subject: [PATCH 3/5] added resources and logic fix --- packages/mui-material/src/TableCell/TableCell.js | 2 ++ .../mui-material/src/TableCell/TableCell.test.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/mui-material/src/TableCell/TableCell.js b/packages/mui-material/src/TableCell/TableCell.js index 02c268978ccbed..9dcdf827b04226 100644 --- a/packages/mui-material/src/TableCell/TableCell.js +++ b/packages/mui-material/src/TableCell/TableCell.js @@ -141,6 +141,8 @@ const TableCell = React.forwardRef(function TableCell(inProps, ref) { let scope = scopeProp; // https://github.com/mui/material-ui/issues/35031#issuecomment-1359346668 + // scope is not a valid attribute for elements. + // source: https://html.spec.whatwg.org/multipage/tables.html#the-td-element if (component === 'td') { scope = undefined; } else if (!scope && isHeadCell) { diff --git a/packages/mui-material/src/TableCell/TableCell.test.js b/packages/mui-material/src/TableCell/TableCell.test.js index 2df2e950b4bf98..02496a0f744e6f 100644 --- a/packages/mui-material/src/TableCell/TableCell.test.js +++ b/packages/mui-material/src/TableCell/TableCell.test.js @@ -93,8 +93,16 @@ describe('', () => { const { container } = renderInTable(); expect(container.querySelector('th')).not.to.have.attribute('role'); }); - it('scope should be undefined in table cell when component is td', () => { - const { container } = renderInTable(); + it('scope should be undefined in table cell when component is td even when table cell is rendered with in table head', () => { + const { container } = render( + + + + + + +
, + ); expect(container.querySelector('td')).not.to.have.attribute('scope'); }); }); From d8d9a1b470b78c70b6542b3657a2919a3305a56d Mon Sep 17 00:00:00 2001 From: sai6855 <60743144+sai6855@users.noreply.github.com> Date: Wed, 21 Dec 2022 17:54:04 +0530 Subject: [PATCH 4/5] test logic fix --- .../mui-material/src/TableCell/TableCell.test.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/mui-material/src/TableCell/TableCell.test.js b/packages/mui-material/src/TableCell/TableCell.test.js index 02496a0f744e6f..39d03dcdc6b6bb 100644 --- a/packages/mui-material/src/TableCell/TableCell.test.js +++ b/packages/mui-material/src/TableCell/TableCell.test.js @@ -2,6 +2,9 @@ import * as React from 'react'; import { expect } from 'chai'; import { createRenderer, describeConformance } from 'test/utils'; import TableCell, { tableCellClasses as classes } from '@mui/material/TableCell'; +import TableHead from '@mui/material/TableHead'; +import TableRow from '@mui/material/TableRow'; +import Table from '@mui/material/Table'; describe('', () => { const { render } = createRenderer(); @@ -95,13 +98,13 @@ describe('', () => { }); it('scope should be undefined in table cell when component is td even when table cell is rendered with in table head', () => { const { container } = render( - - - +
+ + - - -
, +
+ + , ); expect(container.querySelector('td')).not.to.have.attribute('scope'); }); From cb9591dc5ec5a59c453d31040304d49adbff065d Mon Sep 17 00:00:00 2001 From: sai6855 <60743144+sai6855@users.noreply.github.com> Date: Wed, 21 Dec 2022 20:46:28 +0530 Subject: [PATCH 5/5] fixes --- packages/mui-material/src/TableCell/TableCell.js | 1 - packages/mui-material/src/TableCell/TableCell.test.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/mui-material/src/TableCell/TableCell.js b/packages/mui-material/src/TableCell/TableCell.js index 9dcdf827b04226..3c4233061c8959 100644 --- a/packages/mui-material/src/TableCell/TableCell.js +++ b/packages/mui-material/src/TableCell/TableCell.js @@ -140,7 +140,6 @@ const TableCell = React.forwardRef(function TableCell(inProps, ref) { } let scope = scopeProp; - // https://github.com/mui/material-ui/issues/35031#issuecomment-1359346668 // scope is not a valid attribute for elements. // source: https://html.spec.whatwg.org/multipage/tables.html#the-td-element if (component === 'td') { diff --git a/packages/mui-material/src/TableCell/TableCell.test.js b/packages/mui-material/src/TableCell/TableCell.test.js index 39d03dcdc6b6bb..776ed9241ff7c6 100644 --- a/packages/mui-material/src/TableCell/TableCell.test.js +++ b/packages/mui-material/src/TableCell/TableCell.test.js @@ -96,7 +96,7 @@ describe('', () => { const { container } = renderInTable(); expect(container.querySelector('th')).not.to.have.attribute('role'); }); - it('scope should be undefined in table cell when component is td even when table cell is rendered with in table head', () => { + it('should not set scope attribute when TableCell is rendered as within table head', () => { const { container } = render(