diff --git a/src/components/table/_table_cell_content.tsx b/src/components/table/_table_cell_content.tsx index 2abc04b5f48..228736e0ad1 100644 --- a/src/components/table/_table_cell_content.tsx +++ b/src/components/table/_table_cell_content.tsx @@ -40,7 +40,7 @@ export const EuiTableCellContent: FunctionComponent< const styles = useEuiMemoizedStyles(euiTableCellContentStyles); const cssStyles = [ styles.euiTableCellContent, - !isResponsive && styles[align], // On mobile, always align cells to the left + styles[align], truncateText === true && styles.truncateText, truncateText === false && styles.wrapText, ...(hasActions diff --git a/src/components/table/table.styles.ts b/src/components/table/table.styles.ts index f4a34bc2502..7a54b1cda2b 100644 --- a/src/components/table/table.styles.ts +++ b/src/components/table/table.styles.ts @@ -91,19 +91,10 @@ export const euiTableStyles = (euiThemeContext: UseEuiTheme) => { `, /** * Responsive/mobile vs desktop styles + * Individual row/cells handle their own desktop vs mobile styles */ - desktop: css` - .euiTableHeaderCell--hideForDesktop, - .euiTableRowCell--hideForDesktop, - .euiTableRowCell__mobileHeader { - display: none; - } - `, + desktop: css``, mobile: css` - .euiTableRowCell--hideForMobile { - display: none; - } - thead { display: none; /* Use mobile versions of selecting and filtering instead */ } diff --git a/src/components/table/table_header_cell.tsx b/src/components/table/table_header_cell.tsx index 90d4fc4ab43..4c4af5251cb 100644 --- a/src/components/table/table_header_cell.tsx +++ b/src/components/table/table_header_cell.tsx @@ -25,6 +25,7 @@ import { EuiIcon } from '../icon'; import { EuiInnerText } from '../inner_text'; import { resolveWidthAsStyle } from './utils'; +import { useEuiTableIsResponsive } from './mobile/responsive_context'; import { EuiTableCellContent } from './_table_cell_content'; import { euiTableHeaderFooterCellStyles } from './table_cells_shared.styles'; @@ -137,11 +138,12 @@ export const EuiTableHeaderCell: FunctionComponent = ({ }) => { const styles = useEuiMemoizedStyles(euiTableHeaderFooterCellStyles); - const classes = classNames('euiTableHeaderCell', className, { - 'euiTableHeaderCell--hideForDesktop': mobileOptions.only, - 'euiTableHeaderCell--hideForMobile': !mobileOptions.show, - }); + const isResponsive = useEuiTableIsResponsive(); + const hideForDesktop = !isResponsive && mobileOptions?.only; + const hideForMobile = isResponsive && !mobileOptions?.show; + if (hideForDesktop || hideForMobile) return null; + const classes = classNames('euiTableHeaderCell', className); const inlineStyles = resolveWidthAsStyle(style, width); const CellComponent = children ? 'th' : 'td'; diff --git a/src/components/table/table_row_cell.tsx b/src/components/table/table_row_cell.tsx index 4dc739b4af3..feaee4cfe89 100644 --- a/src/components/table/table_row_cell.tsx +++ b/src/components/table/table_row_cell.tsx @@ -146,7 +146,6 @@ export const EuiTableRowCell: FunctionComponent = ({ const cellClasses = classNames('euiTableRowCell', className, { 'euiTableRowCell--hasActions': hasActions, 'euiTableRowCell--isExpander': isExpander, - 'euiTableRowCell--hideForDesktop': mobileOptions.only, }); const widthValue = isResponsive @@ -157,9 +156,6 @@ export const EuiTableRowCell: FunctionComponent = ({ const styleObj = resolveWidthAsStyle(style, widthValue); - const hideForMobileClasses = 'euiTableRowCell--hideForMobile'; - const showForMobileClasses = 'euiTableRowCell--hideForDesktop'; - const Element = setScopeRow ? 'th' : 'td'; const sharedProps = { scope: setScopeRow ? 'row' : undefined, @@ -174,54 +170,42 @@ export const EuiTableRowCell: FunctionComponent = ({ hasActions: hasActions || isExpander, }; - if (mobileOptions.show === false) { - return ( - - - {children} - - - ); - } else { - return ( - - {/* Mobile-only header */} - {mobileOptions.header && ( -
- {mobileOptions.header} -
- )} - - {/* Content depending on mobile render existing */} - {mobileOptions.render ? ( - <> - + {mobileOptions.header && ( +
- {mobileOptions.render} - - - {children} - - - ) : ( + {mobileOptions.header} +
+ )} + + {mobileOptions.render || children} + +
+ ); + } + } else { + if (mobileOptions.only) { + return null; + } else { + return ( + {children} - )} - - ); + + ); + } } };