Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
[terra-table] Added the ability to specify a screen reader message fo…
Browse files Browse the repository at this point in the history
…r masked cells.
  • Loading branch information
cm9361 committed Oct 25, 2023
1 parent 3cfb6af commit b9247fb
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/terra-framework-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Added
* Added example for Flowsheet Data Grid containing "No Result" cells.

* Updated
* Updates `terra-table` example to show providing custom masked cell message label.

## 1.42.0 - (October 20, 2023)

* Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const tableData = {
{ content: '' },
{ content: 'Quinzell, Harleen' },
{ content: '' },
{ isMasked: true },
{ isMasked: true, maskedLabel: 'Age Hidden' },
{ isMasked: true },
{ content: 'Admitting Physician' },
],
Expand Down
3 changes: 3 additions & 0 deletions packages/terra-table/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Added
* Added ability for consumers to specify a custom screen reader message for masked cells.

## 5.1.0-alpha.0 - (October 20, 2023)

* Added
Expand Down
8 changes: 8 additions & 0 deletions packages/terra-table/src/proptypes/cellShape.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ const cellShape = PropTypes.shape({
* Content that will be rendered within the Cell.
*/
content: PropTypes.node,

/**
* Boolean indicating if cell contents are masked.
*/
isMasked: PropTypes.bool,

/**
* Provides a custom string for masked cells to be read by screen readers. This value is only applied if the cell is masked.
*/
maskedLabel: PropTypes.string,

/**
* @private
* Boolean value indicating whether or not the column header is selectable.
*/
isSelectable: PropTypes.bool,

/**
* @private
* Boolean value indicating whether or not the cell should render as selected.
Expand Down
8 changes: 7 additions & 1 deletion packages/terra-table/src/subcomponents/Cell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const propTypes = {
*/
isMasked: PropTypes.bool,

/**
* Provides a custom string for masked cells to be read by screen readers. This value is only applied if the cell is masked.
*/
maskedLabel: PropTypes.string,

/**
* Boolean value indicating whether or not the column header is selectable.
*/
Expand Down Expand Up @@ -106,6 +111,7 @@ function Cell(props) {
columnIndex,
ariaLabel,
isMasked,
maskedLabel,
isRowHeader,
isSelectable,
isSelected,
Expand Down Expand Up @@ -205,7 +211,7 @@ function Cell(props) {
if (isMasked) {
cellContent = (
<span className={cx('no-data-cell', theme.className)}>
{intl.formatMessage({ id: 'Terra.table.maskedCell' })}
{maskedLabel || intl.formatMessage({ id: 'Terra.table.maskedCell' })}
</span>
);
} else if (!children) {
Expand Down
1 change: 1 addition & 0 deletions packages/terra-table/src/subcomponents/Row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function Row(props) {
key={`${id}_${displayedColumns[cellColumnIndex].id}`}
isSelected={!hasRowSelection && cellData.isSelected}
isMasked={cellData.isMasked}
maskedLabel={cellData.maskedLabel}
isSelectable={cellData.isSelectable}
isRowHeader={cellColumnIndex === rowHeaderIndex}
isHighlighted={isHovered || isSelected}
Expand Down
29 changes: 29 additions & 0 deletions packages/terra-table/tests/jest/Cell.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,35 @@ describe('Cell', () => {
expect(wrapper).toMatchSnapshot();
});

it('verifies that a cell has renders that masked label text, when provided', () => {
const wrapper = shallowWithIntl(
<IntlProvider locale="en">
<Cell
rowId="RowID"
columnId="ColumnId"
ariaLabel="Some Label Here"
rowIndex={1}
columnIndex={2}
key="key"
isMasked
maskedLabel="MaskedLabel"
onCellSelect={jest.fn}
>
Data in cell
</Cell>
</IntlProvider>,
).dive().dive();

const maskedCell = wrapper.find('td.masked');
expect(maskedCell).toHaveLength(1);

const cellContent = maskedCell.find('div');
expect(cellContent.text()).toBe('MaskedLabel');
expect(cellContent).toHaveLength(1);

expect(wrapper).toMatchSnapshot();
});

it('verifies mask takes precedence when cell is masked, selectable and selected', () => {
const wrapper = shallowWithIntl(
<IntlProvider locale="en">
Expand Down
27 changes: 27 additions & 0 deletions packages/terra-table/tests/jest/__snapshots__/Cell.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,33 @@ exports[`Cell verifies mask takes precedence when cell is masked, selectable and
</td>
`;

exports[`Cell verifies that a cell has renders that masked label text, when provided 1`] = `
<td
aria-label="Some Label Here"
className="cell masked"
style={
Object {
"left": null,
}
}
>
<div
className="cell-content"
style={
Object {
"height": undefined,
}
}
>
<span
className="no-data-cell"
>
MaskedLabel
</span>
</div>
</td>
`;

exports[`Cell verifies that a cell has the correct styles and no content when isMasked prop is true 1`] = `
<td
aria-label="Some Label Here"
Expand Down

0 comments on commit b9247fb

Please sign in to comment.