diff --git a/CHANGELOG.md b/CHANGELOG.md index 59cbd7b0950..e048ae4e797 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Added `external` prop to `EuiLink` ([#2442](https://github.com/elastic/eui/pull/2442)) - Added disabled state to `EuiBadge` ([#2440](https://github.com/elastic/eui/pull/2440)) +**Bug fixes** + +- Reenabled `width` property for `EuiTable` cell components ([#2452](https://github.com/elastic/eui/pull/2452)) + ## [`14.6.0`](https://github.com/elastic/eui/tree/v14.6.0) - Added new updated `infraApp` and `logsApp` icons. ([#2430](https://github.com/elastic/eui/pull/2430)) diff --git a/src/components/basic_table/__snapshots__/in_memory_table.test.js.snap b/src/components/basic_table/__snapshots__/in_memory_table.test.js.snap index fd3b2b209d8..4ed2ccd557e 100644 --- a/src/components/basic_table/__snapshots__/in_memory_table.test.js.snap +++ b/src/components/basic_table/__snapshots__/in_memory_table.test.js.snap @@ -156,6 +156,11 @@ exports[`EuiInMemoryTable behavior pagination 1`] = ` data-test-subj="tableHeaderCell_name_0" role="columnheader" scope="col" + style={ + Object { + "width": undefined, + } + } >
`; + +exports[`EuiTableFooterCell width and style accepts style attribute 1`] = ` + +
+ + Test + +
+ +`; + +exports[`EuiTableFooterCell width and style accepts width attribute 1`] = ` + +
+ + Test + +
+ +`; + +exports[`EuiTableFooterCell width and style accepts width attribute as number 1`] = ` + +
+ + Test + +
+ +`; + +exports[`EuiTableFooterCell width and style resolves style and width attribute 1`] = ` + +
+ + Test + +
+ +`; diff --git a/src/components/table/__snapshots__/table_header_cell.test.tsx.snap b/src/components/table/__snapshots__/table_header_cell.test.tsx.snap index 076815b2f1b..b6a4321e000 100644 --- a/src/components/table/__snapshots__/table_header_cell.test.tsx.snap +++ b/src/components/table/__snapshots__/table_header_cell.test.tsx.snap @@ -67,3 +67,79 @@ exports[`renders EuiTableHeaderCell 1`] = `
`; + +exports[`width and style accepts style attribute 1`] = ` + +
+ + Test + +
+ +`; + +exports[`width and style accepts width attribute 1`] = ` + +
+ + Test + +
+ +`; + +exports[`width and style accepts width attribute as number 1`] = ` + +
+ + Test + +
+ +`; + +exports[`width and style resolves style and width attribute 1`] = ` + +
+ + Test + +
+ +`; diff --git a/src/components/table/__snapshots__/table_header_cell_checkbox.test.tsx.snap b/src/components/table/__snapshots__/table_header_cell_checkbox.test.tsx.snap index 4e921b9ccd6..5c52d69b4e5 100644 --- a/src/components/table/__snapshots__/table_header_cell_checkbox.test.tsx.snap +++ b/src/components/table/__snapshots__/table_header_cell_checkbox.test.tsx.snap @@ -12,3 +12,59 @@ exports[`EuiTableHeaderCellCheckbox is rendered 1`] = ` /> `; + +exports[`EuiTableHeaderCellCheckbox width and style accepts style attribute 1`] = ` + +
+ Test +
+ +`; + +exports[`EuiTableHeaderCellCheckbox width and style accepts width attribute 1`] = ` + +
+ Test +
+ +`; + +exports[`EuiTableHeaderCellCheckbox width and style accepts width attribute as number 1`] = ` + +
+ Test +
+ +`; + +exports[`EuiTableHeaderCellCheckbox width and style resolves style and width attribute 1`] = ` + +
+ Test +
+ +`; diff --git a/src/components/table/__snapshots__/table_row_cell.test.tsx.snap b/src/components/table/__snapshots__/table_row_cell.test.tsx.snap index e7b5428c554..b79740fa556 100644 --- a/src/components/table/__snapshots__/table_row_cell.test.tsx.snap +++ b/src/components/table/__snapshots__/table_row_cell.test.tsx.snap @@ -125,3 +125,71 @@ exports[`truncateText is rendered when specified 1`] = `
`; + +exports[`width and style accepts style attribute 1`] = ` + +
+ + Test + +
+ +`; + +exports[`width and style accepts width attribute 1`] = ` + +
+ + Test + +
+ +`; + +exports[`width and style accepts width attribute as number 1`] = ` + +
+ + Test + +
+ +`; + +exports[`width and style resolves style and width attribute 1`] = ` + +
+ + Test + +
+ +`; diff --git a/src/components/table/table_footer_cell.test.tsx b/src/components/table/table_footer_cell.test.tsx index 1e8034dd5dd..e3cfba2ec74 100644 --- a/src/components/table/table_footer_cell.test.tsx +++ b/src/components/table/table_footer_cell.test.tsx @@ -34,4 +34,40 @@ describe('EuiTableFooterCell', () => { expect(render(component)).toMatchSnapshot(); }); }); + + describe('width and style', () => { + test('accepts style attribute', () => { + const component = ( + Test + ); + + expect(render(component)).toMatchSnapshot(); + }); + + test('accepts width attribute', () => { + const component = ( + Test + ); + + expect(render(component)).toMatchSnapshot(); + }); + + test('accepts width attribute as number', () => { + const component = ( + Test + ); + + expect(render(component)).toMatchSnapshot(); + }); + + test('resolves style and width attribute', () => { + const component = ( + + Test + + ); + + expect(render(component)).toMatchSnapshot(); + }); + }); }); diff --git a/src/components/table/table_footer_cell.tsx b/src/components/table/table_footer_cell.tsx index 3917efb8243..ef090e7ea29 100644 --- a/src/components/table/table_footer_cell.tsx +++ b/src/components/table/table_footer_cell.tsx @@ -9,16 +9,20 @@ import { CENTER_ALIGNMENT, } from '../../services'; +import { resolveWidthAsStyle } from './utils'; + type Props = CommonProps & TdHTMLAttributes & { align?: HorizontalAlignment; + width?: string | number; }; export const EuiTableFooterCell: FunctionComponent = ({ children, align = LEFT_ALIGNMENT, - colSpan, className, + width, + style, ...rest }) => { const classes = classNames('euiTableFooterCell', className); @@ -26,9 +30,10 @@ export const EuiTableFooterCell: FunctionComponent = ({ 'euiTableCellContent--alignRight': align === RIGHT_ALIGNMENT, 'euiTableCellContent--alignCenter': align === CENTER_ALIGNMENT, }); + const styleObj = resolveWidthAsStyle(style, width); return ( - +
{children}
diff --git a/src/components/table/table_header_cell.test.tsx b/src/components/table/table_header_cell.test.tsx index 34e8a366dc4..e5431519c35 100644 --- a/src/components/table/table_header_cell.test.tsx +++ b/src/components/table/table_header_cell.test.tsx @@ -33,3 +33,35 @@ describe('align', () => { expect(render(component)).toMatchSnapshot(); }); }); + +describe('width and style', () => { + test('accepts style attribute', () => { + const component = ( + Test + ); + + expect(render(component)).toMatchSnapshot(); + }); + + test('accepts width attribute', () => { + const component = Test; + + expect(render(component)).toMatchSnapshot(); + }); + + test('accepts width attribute as number', () => { + const component = Test; + + expect(render(component)).toMatchSnapshot(); + }); + + test('resolves style and width attribute', () => { + const component = ( + + Test + + ); + + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/src/components/table/table_header_cell.tsx b/src/components/table/table_header_cell.tsx index e743907d028..330cbc9bc61 100644 --- a/src/components/table/table_header_cell.tsx +++ b/src/components/table/table_header_cell.tsx @@ -8,6 +8,7 @@ import classNames from 'classnames'; import { EuiScreenReaderOnly } from '../accessibility'; import { CommonProps, NoArgCallback } from '../common'; import { EuiIcon } from '../icon'; +import { resolveWidthAsStyle } from './utils'; import { HorizontalAlignment, @@ -56,6 +57,7 @@ type Props = CommonProps & }; onSort?: NoArgCallback; scope?: TableHeaderCellScope; + width?: string | number; }; export const EuiTableHeaderCell: FunctionComponent = ({ @@ -73,6 +75,8 @@ export const EuiTableHeaderCell: FunctionComponent = ({ // Soon to be deprecated for {...mobileOptions} isMobileHeader, hideForMobile, + style, + width, ...rest }) => { const classes = classNames('euiTableHeaderCell', className, { @@ -85,6 +89,8 @@ export const EuiTableHeaderCell: FunctionComponent = ({ 'euiTableCellContent--alignCenter': align === CENTER_ALIGNMENT, }); + const styleObj = resolveWidthAsStyle(style, width); + if (onSort) { const buttonClasses = classNames('euiTableHeaderButton', { 'euiTableHeaderButton-isSorted': isSorted, @@ -114,6 +120,7 @@ export const EuiTableHeaderCell: FunctionComponent = ({ role="columnheader" aria-sort={ariaSortValue} aria-live="polite" + style={styleObj} {...rest}>