-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Fixes table editable cell styles and simplifies it #3061
Changes from 3 commits
4c9b8a8
e04b439
c0e7ae6
da64213
9836e89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,10 @@ $edit-button-padding-right: calc(#{awsui.$space-xs} + #{awsui.$space-xxs}); | |
// Cell vertical padding + xxs space that would normally come from the button. | ||
$success-icon-padding-right: calc(#{$edit-button-padding-right} + #{$icon-width-with-spacing}); | ||
$interactive-column-padding-inline-end: calc(#{$cell-horizontal-padding} + #{awsui.$space-l}); | ||
$editing-cell-padding-inline: awsui.$space-xxs; | ||
$editing-cell-padding-block: awsui.$space-scaled-xxxs; | ||
$cell-offset: calc(#{awsui.$space-m} + #{awsui.$space-xs}); | ||
|
||
// Ensuring enough space for absolute-positioned focus outlines of focus-able cell content elements. | ||
$cell-negative-space-vertical: 2px; | ||
|
||
@mixin cell-focus-outline { | ||
@include styles.focus-highlight(calc(-1 * #{awsui.$space-scaled-xxs})); | ||
|
||
|
@@ -99,20 +98,17 @@ $cell-negative-space-vertical: 2px; | |
} | ||
@mixin cell-padding-block($padding) { | ||
> .body-cell-content { | ||
padding-block: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width} + #{$cell-negative-space-vertical}); | ||
margin-block: calc(-1 * #{$cell-negative-space-vertical}); | ||
padding-block: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width}); | ||
} | ||
} | ||
@mixin cell-padding-block-start($padding) { | ||
> .body-cell-content { | ||
padding-block-start: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width} + #{$cell-negative-space-vertical}); | ||
margin-block-start: calc(-1 * #{$cell-negative-space-vertical}); | ||
padding-block-start: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width}); | ||
} | ||
} | ||
@mixin cell-padding-block-end($padding) { | ||
> .body-cell-content { | ||
padding-block-end: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width} + #{$cell-negative-space-vertical}); | ||
margin-block-end: calc(-1 * #{$cell-negative-space-vertical}); | ||
padding-block-end: calc(#{$padding} - 1 * #{awsui.$border-divider-list-width}); | ||
} | ||
} | ||
|
||
|
@@ -131,11 +127,18 @@ $cell-negative-space-vertical: 2px; | |
|
||
&-content { | ||
box-sizing: border-box; | ||
} | ||
&:not(.body-cell-wrap) > .body-cell-content { | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
block-size: 100%; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making cell content span to the entire cell height. |
||
align-content: center; | ||
|
||
&.body-cell-align-top { | ||
align-content: baseline; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now the cell content takes the entire cell size so the alignment must be attached to it instead of the cell. |
||
} | ||
|
||
&:not(.body-cell-wrap) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
} | ||
&:first-child { | ||
border-inline-start: $border-placeholder; | ||
|
@@ -177,20 +180,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}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This negative space shenanigans are no longer needed because there is plenty of space for the focus outline. |
||
} | ||
} | ||
&: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 +373,6 @@ $cell-negative-space-vertical: 2px; | |
color: awsui.$color-text-button-normal-active; | ||
} | ||
|
||
&-form { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For editing cells we used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update: the overflow visible is still needed for editable content that includes dropdowns. I will contribute a new screenshot test to capture that. |
||
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; | ||
|
@@ -428,9 +408,9 @@ $cell-negative-space-vertical: 2px; | |
} | ||
|
||
&.body-cell-edit-active { | ||
> .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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<HTMLTableCellElement, TableTdElementProps>( | ||
( | ||
{ | ||
style, | ||
children, | ||
wrapLines, | ||
isRowHeader, | ||
|
@@ -90,6 +90,7 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem | |
collapseButtonLabel, | ||
verticalAlign, | ||
resizableColumns, | ||
resizableStyle, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
isEditable, | ||
isEditing, | ||
isEditingDisabled, | ||
|
@@ -101,6 +102,8 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem | |
const Element = isRowHeader ? 'th' : 'td'; | ||
const isVisualRefresh = useVisualRefresh(); | ||
|
||
resizableStyle = resizableColumns ? {} : resizableStyle; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this condition looks counterintuitive. you apply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is taken as is from the current impl: https://github.com/cloudscape-design/components/blob/main/src/table/internal.tsx#L627 When resizable columns is on, the styles are assigned directly to cell nodes in I think there are further opportunities for refactoring and maybe this condition can be just removed but I'd not include this into the current PR. |
||
|
||
nativeAttributes = { ...nativeAttributes, ...getTableCellRoleProps({ tableRole, isRowHeader, colIndex }) }; | ||
|
||
const stickyStyles = useStickyCellStyles({ | ||
|
@@ -115,10 +118,9 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem | |
|
||
return ( | ||
<Element | ||
style={{ ...style, ...stickyStyles.style }} | ||
style={{ ...resizableStyle, ...stickyStyles.style }} | ||
className={clsx( | ||
styles['body-cell'], | ||
wrapLines && styles['body-cell-wrap'], | ||
isFirstRow && styles['body-cell-first-row'], | ||
isLastRow && styles['body-cell-last-row'], | ||
isSelected && styles['body-cell-selected'], | ||
|
@@ -137,7 +139,6 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem | |
hasSuccessIcon && styles['body-cell-has-success'], | ||
level !== undefined && styles['body-cell-expandable'], | ||
level !== undefined && styles[`expandable-level-${getLevelClassSuffix(level)}`], | ||
verticalAlign === 'top' && styles['body-cell-align-top'], | ||
stickyStyles.className | ||
)} | ||
onClick={onClick} | ||
|
@@ -159,7 +160,15 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem | |
</div> | ||
)} | ||
|
||
<div className={styles['body-cell-content']}>{children}</div> | ||
<div | ||
className={clsx( | ||
styles['body-cell-content'], | ||
verticalAlign === 'top' && styles['body-cell-align-top'], | ||
wrapLines && styles['body-cell-wrap'] | ||
)} | ||
> | ||
{children} | ||
</div> | ||
</Element> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This negative space was used to virtually enlarge the cell-content element. That is because the element has
overflow: hidden
but when there are interactive elements inside such a link or a button dropdown - the focus outline is being cut off.The negative space is no longer needed because now the cell content size matches cell size. This way the outline can use the available cell space while the content is still truncated correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: the negative space is still needed at least for the compact mode.