Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions packages/block-library/src/table/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ function TableEdit( {
useEffect( () => {
if ( hasTableCreated ) {
tableRef?.current
?.querySelector( 'td[contentEditable="true"]' )
?.querySelector( 'td div[contentEditable="true"]' )
?.focus();
setHasTableCreated( false );
}
Expand Down Expand Up @@ -414,31 +414,33 @@ function TableEdit( {
},
columnIndex
) => (
<RichText
tagName={ CellTag }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this anymore. It renders in <div> by default.

<CellTag
key={ columnIndex }
scope={ CellTag === 'th' ? scope : undefined }
colSpan={ colspan }
rowSpan={ rowspan }
className={ classnames(
{
[ `has-text-align-${ align }` ]: align,
},
'wp-block-table__cell-content'
) }
scope={ CellTag === 'th' ? scope : undefined }
colSpan={ colspan }
rowSpan={ rowspan }
value={ content }
onChange={ onChange }
onFocus={ () => {
setSelectedCell( {
sectionName: name,
rowIndex,
columnIndex,
type: 'cell',
} );
} }
aria-label={ cellAriaLabel[ name ] }
placeholder={ placeholder[ name ] }
/>
>
<RichText
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will likely break visuals but it works due to the cell itself remaining a table cell. The editable content is now done within the cell. This will also likely cause a slightly different back-end vs. the front-end but it isn't up for debate. It simply does not work when you convert a table cell to an editable field. The entire table loses semantic meaning with screen readers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need role=textbox if it breaks things? Isn't contenteditable enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellatrix With my changes, it comes with 2 bonuses.

  1. The table semantics are respected.
  2. The editable areas inside the table cells have better text input semantics.

All in all, a big win.

value={ content }
onChange={ onChange }
onFocus={ () => {
setSelectedCell( {
sectionName: name,
rowIndex,
columnIndex,
type: 'cell',
} );
} }
aria-label={ cellAriaLabel[ name ] }
placeholder={ placeholder[ name ] }
/>
</CellTag>
)
) }
</tr>
Expand Down