Skip to content

Commit

Permalink
fix(tabletoolbar): provide aria-label to CarbonTableToolbar
Browse files Browse the repository at this point in the history
Previously, aria-label could not be specified on TableToolbar, letting Carbon's TableToolbar default it to 'data table toolbar'
This the label should be unqiue, but with multiple Tables with toolbars, it would only ever be 'data table toolbar'
This change allows aria-label be be specified via the i18n prop as toolbarLabelAria
If secondaryTitle is used and no i18n.toolbarLabelAria is specified, it will default to using secondaryTitle within aria-label (appending ' Toolbar')
If no secondaryTitle nor i18n.toolbarLabelAria is specified, it will fallback to Carbon's TableToolbar default as it does now.

BREAKING CHANGE: TableToolbar with secondaryTitle will now default to using secondaryTitle in the aria-label.
To mitigate this change: set i18n.toolbarLabelAria to "data table toolbar"
  • Loading branch information
Evan Sharp authored and Evan Sharp committed Sep 22, 2021
1 parent 6e6dc0a commit 831ff23
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/C
}
>
<section
aria-label="data table toolbar"
aria-label="Custom Card Title Toolbar"
className="bx--table-toolbar"
data-testid="my table-table-toolbar"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/
data-testid="table-for-card-alert-table1-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-alert-table1-table-toolbar"
>
Expand Down Expand Up @@ -4544,7 +4544,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/
data-testid="table-for-card-alert-table1-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-alert-table1-table-toolbar"
>
Expand Down Expand Up @@ -7519,7 +7519,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/
data-testid="table-for-card-alert-table1-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-alert-table1-table-toolbar"
>
Expand Down Expand Up @@ -9578,7 +9578,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/
data-testid="table-for-card-expandedcard-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Expanded card Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-expandedcard-table-toolbar"
>
Expand Down Expand Up @@ -13095,7 +13095,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/
data-testid="table-for-card-alert-table1-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-alert-table1-table-toolbar"
>
Expand Down Expand Up @@ -30741,7 +30741,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/
data-testid="table-for-card-alert-table1-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-alert-table1-table-toolbar"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/D
data-testid="table-for-card-tableCard-table-container"
>
<section
aria-label="data table toolbar"
aria-label="TableCard - LARGE Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-tableCard-table-toolbar"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 2 - Watson IoT E
data-testid="table-for-card-Table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Table card Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-Table-table-toolbar"
>
Expand Down Expand Up @@ -19905,7 +19905,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 2 - Watson IoT E
data-testid="table-for-card-Table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Table card Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-Table-table-toolbar"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 2 - Watson IoT E
data-testid="edit-table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Editor access Toolbar"
className="bx--table-toolbar"
data-testid="edit-table-table-toolbar"
>
Expand Down Expand Up @@ -1362,7 +1362,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 2 - Watson IoT E
data-testid="read-table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Read only access Toolbar"
className="bx--table-toolbar"
data-testid="read-table-table-toolbar"
>
Expand Down Expand Up @@ -5463,7 +5463,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 2 - Watson IoT E
data-testid="edit-table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Editor access Toolbar"
className="bx--table-toolbar"
data-testid="edit-table-table-toolbar"
>
Expand Down Expand Up @@ -5742,7 +5742,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 2 - Watson IoT E
data-testid="read-table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Read only access Toolbar"
className="bx--table-toolbar"
data-testid="read-table-table-toolbar"
>
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/components/Table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ export const defaultProps = (baseProps) => ({
itemSelected: (selectedCount) => `${selectedCount} item selected`,
rowCountInHeader: (totalRowCount) => `Results: ${totalRowCount}`,
toggleAggregations: 'Toggle aggregations',
toolbarLabelAria: undefined,
/** empty state */
emptyMessage: 'There is no data',
emptyMessageBody: '',
Expand Down Expand Up @@ -727,6 +728,7 @@ const Table = (props) => {
downloadIconDescription: i18n.downloadIconDescription,
rowCountInHeader: i18n.rowCountInHeader,
toggleAggregations: i18n.toggleAggregations,
toolbarLabelAria: i18n.toolbarLabelAria,
}}
actions={{
...pick(
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Table/TablePropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const I18NPropTypes = PropTypes.shape({
closeMenuAria: PropTypes.string,
clearSelectionAria: PropTypes.string,
batchCancel: PropTypes.string,
toolbarLabelAria: PropTypes.string,
/** String 'items selected' or function receiving the selectedCount as param:
* (selectedCount) => `${selectedCount} items selected` */
itemsSelected: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const propTypes = {
filterAscending: PropTypes.string,
filterDescending: PropTypes.string,
toggleAggregations: PropTypes.string,
toolbarLabelAria: PropTypes.string,
}),
/**
* Action callbacks to update tableState
Expand Down Expand Up @@ -215,6 +216,7 @@ const TableToolbar = ({
// TODO: remove deprecated 'testID' in v3
data-testid={testID || testId}
className={classnames(`${iotPrefix}--table-toolbar`, className)}
aria-label={i18n.toolbarLabelAria || secondaryTitle ? `${secondaryTitle} Toolbar` : undefined}
>
<TableBatchActions
// TODO: remove deprecated 'testID' in v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23186,7 +23186,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Row count: 100 Toolbar"
className="bx--table-toolbar"
data-testid="table-table-toolbar"
>
Expand Down Expand Up @@ -44086,7 +44086,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Table with user view management Toolbar"
className="bx--table-toolbar"
data-testid="table-table-toolbar"
>
Expand Down Expand Up @@ -49223,7 +49223,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Row count: 100 Toolbar"
className="bx--table-toolbar"
data-testid="table-table-toolbar"
>
Expand Down Expand Up @@ -72446,7 +72446,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Row count: 100 Toolbar"
className="bx--table-toolbar"
data-testid="table-table-toolbar"
>
Expand Down Expand Up @@ -81543,7 +81543,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
}
>
<section
aria-label="data table toolbar"
aria-label="Row count: 100 Toolbar"
className="bx--table-toolbar"
data-testid="table-table-toolbar"
>
Expand Down Expand Up @@ -82425,7 +82425,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Row count: 100 Toolbar"
className="bx--table-toolbar"
data-testid="table-table-toolbar"
>
Expand Down Expand Up @@ -86653,7 +86653,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Row count: 100 Toolbar"
className="bx--table-toolbar"
data-testid="table-table-toolbar"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Basic \`dumb\` table Toolbar"
className="bx--table-toolbar"
data-testid="table-table-toolbar"
>
Expand Down Expand Up @@ -24435,7 +24435,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Table with user view management Toolbar"
className="bx--table-toolbar"
data-testid="table-table-toolbar"
>
Expand Down Expand Up @@ -33201,7 +33201,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="My editable table Toolbar"
className="bx--table-toolbar"
data-testid="table-table-toolbar"
>
Expand Down Expand Up @@ -78659,7 +78659,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Row count: 100 Toolbar"
className="bx--table-toolbar"
data-testid="table-table-toolbar"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-for-card-table-list-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Open Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-table-list-table-toolbar"
>
Expand Down Expand Up @@ -1463,7 +1463,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-for-card-table-list-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Open Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-table-list-table-toolbar"
>
Expand Down Expand Up @@ -2934,7 +2934,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-for-card-table-list-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Open Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-table-list-table-toolbar"
>
Expand Down Expand Up @@ -4633,7 +4633,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-for-card-undefined-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Open Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-undefined-table-toolbar"
>
Expand Down Expand Up @@ -5534,7 +5534,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-for-card-table-list-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Open Alerts 11112 Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-table-list-table-toolbar"
>
Expand Down Expand Up @@ -6764,7 +6764,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-for-card-table-list-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Open Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-table-list-table-toolbar"
>
Expand Down Expand Up @@ -9216,7 +9216,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-for-card-table-list-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Open Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-table-list-table-toolbar"
>
Expand Down Expand Up @@ -11502,7 +11502,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-for-card-table-list-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Open Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-table-list-table-toolbar"
>
Expand Down Expand Up @@ -13308,7 +13308,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-for-card-table-list-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Open Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-table-list-table-toolbar"
>
Expand Down Expand Up @@ -15453,7 +15453,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/T
data-testid="table-for-card-table-list-table-container"
>
<section
aria-label="data table toolbar"
aria-label="Open Alerts Toolbar"
className="bx--table-toolbar"
data-testid="table-for-card-table-list-table-toolbar"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ Map {
"selectRowAria": "Select row",
"tableErrorStateTitle": "Unable to load the page",
"toggleAggregations": "Toggle aggregations",
"toolbarLabelAria": "",
},
"id": null,
"lightweight": false,
Expand Down Expand Up @@ -1121,6 +1122,9 @@ Map {
"toggleAggregations": Object {
"type": "string",
},
"toolbarLabelAria": Object {
"type": "string",
},
},
],
"type": "shape",
Expand Down Expand Up @@ -2156,6 +2160,9 @@ Map {
"toggleAggregations": Object {
"type": "string",
},
"toolbarLabelAria": Object {
"type": "string",
},
},
],
"type": "shape",
Expand Down Expand Up @@ -3768,6 +3775,9 @@ Map {
"toggleAggregations": Object {
"type": "string",
},
"toolbarLabelAria": Object {
"type": "string",
},
},
],
"type": "shape",
Expand Down

0 comments on commit 831ff23

Please sign in to comment.