From 468db9e5e4f940ceff4c1289f8800121ca1f9cc5 Mon Sep 17 00:00:00 2001 From: Andrei Zhaleznichenka Date: Mon, 16 Dec 2024 21:06:18 +0100 Subject: [PATCH] fix: Fixes table editable cell styles and simplifies it (#3061) --- src/table/body-cell/inline-editor.tsx | 2 +- src/table/body-cell/styles.scss | 46 ++++++++++----------------- src/table/body-cell/td-element.tsx | 21 ++++++++---- src/table/column-widths-utils.ts | 8 ++++- src/table/header-cell/index.tsx | 7 ++-- src/table/header-cell/th-element.tsx | 7 ++-- src/table/internal.tsx | 14 +++----- src/table/styles.scss | 1 + src/table/thead.tsx | 2 +- src/table/use-column-widths.tsx | 11 +++---- 10 files changed, 59 insertions(+), 60 deletions(-) diff --git a/src/table/body-cell/inline-editor.tsx b/src/table/body-cell/inline-editor.tsx index 4c1cd589f7..5c501b0b3e 100644 --- a/src/table/body-cell/inline-editor.tsx +++ b/src/table/body-cell/inline-editor.tsx @@ -114,7 +114,7 @@ export function InlineEditor({ aria-label={ariaLabels?.activateEditLabel?.(column, item)} onKeyDown={handleEscape} > -
+ .body-cell-content { - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; + block-size: 100%; + align-content: center; + + &.body-cell-align-top { + align-content: baseline; + } + + &:not(.body-cell-wrap) { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } } &:first-child { border-inline-start: $border-placeholder; @@ -177,20 +185,10 @@ $cell-negative-space-vertical: 2px; &:not(.has-selection):not(.body-cell-editable) { border-inline-start: none; } - - // Give extra space on the edge to allow slight content overflow. - // That is to prevent focus outline on cell content from being cut out. - > .body-cell-content { - padding-inline-start: awsui.$border-divider-list-width; - margin-inline-start: calc(-1 * #{awsui.$border-divider-list-width}); - } } &:first-child:not(.is-visual-refresh) { @include cell-padding-inline-start($cell-edge-horizontal-padding); } - &-align-top { - vertical-align: top; - } &-first-row { border-block-start: $border-placeholder; } @@ -380,19 +378,6 @@ $cell-negative-space-vertical: 2px; color: awsui.$color-text-button-normal-active; } - &-form { - margin-block: calc(-1 * #{awsui.$space-xs}); - margin-inline: calc(-1.5 * #{awsui.$space-xs}); - - .is-visual-refresh.body-cell:first-child.has-striped-rows > & { - margin-inline-start: calc(-1 * #{awsui.$space-xxs}); - } - - .is-visual-refresh.body-cell:first-child:not(.has-striped-rows) > & { - margin-inline-start: calc(-1 * #{awsui.$space-xxxs}); - } - } - &-row { display: flex; flex-flow: row nowrap; @@ -431,6 +416,9 @@ $cell-negative-space-vertical: 2px; > .body-cell-content { overflow: visible; } + @include cell-padding-inline-start($editing-cell-padding-inline); + @include cell-padding-inline-end($editing-cell-padding-inline); + @include cell-padding-block($editing-cell-padding-block); } &:not(.body-cell-edit-active) { diff --git a/src/table/body-cell/td-element.tsx b/src/table/body-cell/td-element.tsx index 22a9def552..121f5ca8d1 100644 --- a/src/table/body-cell/td-element.tsx +++ b/src/table/body-cell/td-element.tsx @@ -8,6 +8,7 @@ import { copyAnalyticsMetadataAttribute } from '@cloudscape-design/component-too import { useSingleTabStopNavigation } from '../../internal/context/single-tab-stop-navigation-context'; import { useMergeRefs } from '../../internal/hooks/use-merge-refs'; import { useVisualRefresh } from '../../internal/hooks/use-visual-mode'; +import { ColumnWidthStyle } from '../column-widths-utils'; import { ExpandToggleButton } from '../expandable-rows/expand-toggle-button'; import { TableProps } from '../interfaces.js'; import { StickyColumnsModel, useStickyCellStyles } from '../sticky-columns'; @@ -18,7 +19,6 @@ import tableStyles from '../styles.css.js'; import styles from './styles.css.js'; export interface TableTdElementProps { - style?: React.CSSProperties; wrapLines: boolean | undefined; isRowHeader?: boolean; isFirstRow: boolean; @@ -51,6 +51,7 @@ export interface TableTdElementProps { collapseButtonLabel?: string; verticalAlign?: TableProps.VerticalAlign; resizableColumns?: boolean; + resizableStyle?: ColumnWidthStyle; isEditable: boolean; isEditing: boolean; isEditingDisabled?: boolean; @@ -60,7 +61,6 @@ export interface TableTdElementProps { export const TableTdElement = React.forwardRef( ( { - style, children, wrapLines, isRowHeader, @@ -90,6 +90,7 @@ export const TableTdElement = React.forwardRef )} -
{children}
+
+ {children} +
); } diff --git a/src/table/column-widths-utils.ts b/src/table/column-widths-utils.ts index 088e576e3a..fc7b5a5083 100644 --- a/src/table/column-widths-utils.ts +++ b/src/table/column-widths-utils.ts @@ -5,6 +5,12 @@ import { warnOnce } from '@cloudscape-design/component-toolkit/internal'; import { TableProps } from './interfaces'; +export interface ColumnWidthStyle { + width?: string | number; + minWidth?: string | number; + maxWidth?: string | number; +} + export function checkColumnWidths(columnDefinitions: ReadonlyArray>) { for (const column of columnDefinitions) { checkProperty(column, 'minWidth'); @@ -12,7 +18,7 @@ export function checkColumnWidths(columnDefinitions: ReadonlyArray { - style?: React.CSSProperties; tabIndex: number; column: TableProps.ColumnDefinition; activeSortingColumn?: TableProps.SortingColumn; @@ -40,6 +40,7 @@ export interface TableHeaderCellProps { colIndex: number; updateColumn: (columnId: PropertyKey, newWidth: number) => void; resizableColumns?: boolean; + resizableStyle?: ColumnWidthStyle; isEditable?: boolean; columnId: PropertyKey; stickyState: StickyColumnsModel; @@ -53,7 +54,6 @@ export interface TableHeaderCellProps { } export function TableHeaderCell({ - style, tabIndex, column, activeSortingColumn, @@ -69,6 +69,7 @@ export function TableHeaderCell({ colIndex, updateColumn, resizableColumns, + resizableStyle, onResizeFinish, isEditable, columnId, @@ -120,7 +121,7 @@ export function TableHeaderCell({ return ( onResizeFinish(columnWidths)} resizableColumns={resizableColumns} + resizableStyle={getColumnStyles(sticky, columnId)} onClick={detail => { setLastUserAction('sorting'); fireNonCancelableEvent(onSortingChange, detail); diff --git a/src/table/use-column-widths.tsx b/src/table/use-column-widths.tsx index 3e50e64974..db41a79c8c 100644 --- a/src/table/use-column-widths.tsx +++ b/src/table/use-column-widths.tsx @@ -5,15 +5,12 @@ import React, { createContext, useContext, useEffect, useRef, useState } from 'r import { useResizeObserver, useStableCallback } from '@cloudscape-design/component-toolkit/internal'; import { getLogicalBoundingClientRect } from '@cloudscape-design/component-toolkit/internal'; -import { setElementWidths } from './column-widths-utils'; +import { ColumnWidthStyle, setElementWidths } from './column-widths-utils'; export const DEFAULT_COLUMN_WIDTH = 120; -export interface ColumnWidthDefinition { +export interface ColumnWidthDefinition extends ColumnWidthStyle { id: PropertyKey; - minWidth?: string | number; - maxWidth?: string | number; - width?: string | number; } function readWidths( @@ -61,7 +58,7 @@ function updateWidths( } interface WidthsContext { - getColumnStyles(sticky: boolean, columnId: PropertyKey): React.CSSProperties; + getColumnStyles(sticky: boolean, columnId: PropertyKey): ColumnWidthStyle; columnWidths: Map; updateColumn: (columnId: PropertyKey, newWidth: number) => void; setCell: (sticky: boolean, columnId: PropertyKey, node: null | HTMLElement) => void; @@ -98,7 +95,7 @@ export function ColumnWidthsProvider({ visibleColumns, resizableColumns, contain } }; - const getColumnStyles = (sticky: boolean, columnId: PropertyKey): React.CSSProperties => { + const getColumnStyles = (sticky: boolean, columnId: PropertyKey): ColumnWidthStyle => { const column = visibleColumns.find(column => column.id === columnId); if (!column) { return {};