Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Converted `EuiFilterSelectItem` to TypeScript ([#2761](https://github.com/elastic/eui/pull/2761))
- Converted `EuiFieldSearch` to TypeScript ([#2775](https://github.com/elastic/eui/pull/2775))
- Added `data-test-subj` to the `EuiContextMenuItem` in `EuiTablePagination` ([#2778](https://github.com/elastic/eui/pull/2778))
- Improved `EuiBasicTable` <caption> ([#2782](https://github.com/elastic/eui/pull/2782))

**Bug fixes**

Expand Down
58 changes: 35 additions & 23 deletions src/components/basic_table/__snapshots__/basic_table.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports[`EuiBasicTable cellProps renders cells with custom props from a callback
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows."
token="euiBasicTable.tableDescription"
values={
Object {
Expand Down Expand Up @@ -157,7 +157,7 @@ exports[`EuiBasicTable cellProps renders rows with custom props from an object 1
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows."
token="euiBasicTable.tableDescription"
values={
Object {
Expand Down Expand Up @@ -282,7 +282,7 @@ exports[`EuiBasicTable empty is rendered 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows."
token="euiBasicTable.tableDescription"
values={
Object {
Expand Down Expand Up @@ -352,7 +352,7 @@ exports[`EuiBasicTable empty renders a node as a custom message 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows."
token="euiBasicTable.tableDescription"
values={
Object {
Expand Down Expand Up @@ -430,7 +430,7 @@ exports[`EuiBasicTable empty renders a string as a custom message 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows."
token="euiBasicTable.tableDescription"
values={
Object {
Expand Down Expand Up @@ -500,7 +500,7 @@ exports[`EuiBasicTable footers do not render without a column footer definition
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows."
token="euiBasicTable.tableDescription"
values={
Object {
Expand Down Expand Up @@ -727,11 +727,12 @@ exports[`EuiBasicTable footers render with pagination, selection, sorting, and f
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 3,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -1018,7 +1019,7 @@ exports[`EuiBasicTable itemIdToExpandedRowMap renders an expanded row 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows."
token="euiBasicTable.tableDescription"
values={
Object {
Expand Down Expand Up @@ -1146,7 +1147,7 @@ exports[`EuiBasicTable rowProps renders rows with custom props from a callback 1
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows."
token="euiBasicTable.tableDescription"
values={
Object {
Expand Down Expand Up @@ -1275,7 +1276,7 @@ exports[`EuiBasicTable rowProps renders rows with custom props from an object 1`
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows."
token="euiBasicTable.tableDescription"
values={
Object {
Expand Down Expand Up @@ -1404,11 +1405,12 @@ exports[`EuiBasicTable with pagination - 2nd page 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 2,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -1512,11 +1514,12 @@ exports[`EuiBasicTable with pagination 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 3,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -1637,11 +1640,12 @@ exports[`EuiBasicTable with pagination and error 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 3,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -1719,11 +1723,12 @@ exports[`EuiBasicTable with pagination and selection 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 3,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -1887,11 +1892,12 @@ exports[`EuiBasicTable with pagination, hiding the per page options 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 3,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -2034,11 +2040,12 @@ exports[`EuiBasicTable with pagination, selection and sorting 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 3,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -2226,11 +2233,12 @@ exports[`EuiBasicTable with pagination, selection, sorting and a single record a
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 3,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -2511,11 +2519,12 @@ exports[`EuiBasicTable with pagination, selection, sorting and column dataType 1
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 3,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -2703,11 +2712,12 @@ exports[`EuiBasicTable with pagination, selection, sorting and column renderer 1
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 3,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -2895,11 +2905,12 @@ exports[`EuiBasicTable with pagination, selection, sorting and multiple record a
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 3,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -3198,11 +3209,12 @@ exports[`EuiBasicTable with pagination, selection, sorting, column renderer and
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
token="euiBasicTable.tableDescription"
values={
Object {
"itemCount": 3,
"totalItemCount": 5,
}
}
/>
Expand Down Expand Up @@ -3369,7 +3381,7 @@ exports[`EuiBasicTable with sortable columns and sorting disabled 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows."
token="euiBasicTable.tableDescription"
values={
Object {
Expand Down Expand Up @@ -3497,7 +3509,7 @@ exports[`EuiBasicTable with sorting 1`] = `
delay={500}
>
<EuiI18n
default="Below is a table of {itemCount} items."
default="Below is a table containing {itemCount} rows."
token="euiBasicTable.tableDescription"
values={
Object {
Expand Down
33 changes: 25 additions & 8 deletions src/components/basic_table/basic_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,21 +534,38 @@ export class EuiBasicTable<T = any> extends Component<

renderTableCaption() {
const { items } = this.props;

const { pagination } = this.props;
let paginationElement;
if (pagination && pagination.totalItemCount > 0) {
paginationElement = (
<EuiI18n
token="euiBasicTable.tableDescription"
default="Below is a table containing {itemCount} rows out of {totalItemCount}."
values={{
totalItemCount: pagination.totalItemCount,
itemCount: items.length,
}}
/>
);
} else {
paginationElement = (
<EuiI18n
token="euiBasicTable.tableDescription"
default="Below is a table containing {itemCount} rows."
values={{
itemCount: items.length,
}}
/>
);
}
return (
<EuiScreenReaderOnly>
<caption
className="euiTableCaption"
role="status"
aria-relevant="text"
aria-live="polite">
Comment thread
myasonik marked this conversation as resolved.
Outdated
<EuiDelayRender>
<EuiI18n
token="euiBasicTable.tableDescription"
default="Below is a table of {itemCount} items."
values={{ itemCount: items.length }}
/>
</EuiDelayRender>
<EuiDelayRender>{paginationElement}</EuiDelayRender>
</caption>
</EuiScreenReaderOnly>
);
Expand Down