diff --git a/src/DataTable/selection/BaseSelectionStatus.jsx b/src/DataTable/selection/BaseSelectionStatus.jsx index 6d8a43610c..806d220585 100644 --- a/src/DataTable/selection/BaseSelectionStatus.jsx +++ b/src/DataTable/selection/BaseSelectionStatus.jsx @@ -20,9 +20,13 @@ function BaseSelectionStatus({ allSelectedText, selectedText, }) { - const { itemCount, isPaginated, state } = useContext(DataTableContext); + const { + itemCount, filteredRows, isPaginated, state, + } = useContext(DataTableContext); const hasAppliedFilters = state?.filters?.length > 0; const isAllRowsSelected = numSelectedRows === itemCount; + const filteredItems = filteredRows?.length || itemCount; + const intlAllSelectedText = allSelectedText || ( )} diff --git a/src/DataTable/selection/tests/SelectionStatus.test.jsx b/src/DataTable/selection/tests/SelectionStatus.test.jsx index 5d655ba1e0..f1b1a6e3ec 100644 --- a/src/DataTable/selection/tests/SelectionStatus.test.jsx +++ b/src/DataTable/selection/tests/SelectionStatus.test.jsx @@ -15,6 +15,7 @@ const instance = { page: [1, 2, 3, 4], toggleAllRowsSelected: () => {}, itemCount: 101, + filteredRows: [...new Array(27)], state: { selectedRowIds: { 1: true, @@ -70,6 +71,16 @@ describe('', () => { expect(toggleAllRowsSpy).toHaveBeenCalledTimes(1); expect(toggleAllRowsSpy).toHaveBeenCalledWith(true); }); + it('updates select all button text after applying filters', () => { + const wrapper = mount(); + const button = wrapper.find(`button.${SELECT_ALL_TEST_ID}`); + expect(button.text()).toContain('Select all 27'); + }); + it('updates select all text if filters value is empty', () => { + const wrapper = mount(); + const button = wrapper.find(`button.${SELECT_ALL_TEST_ID}`); + expect(button.text()).toContain('Select all 101'); + }); it('does not render the clear selection button if there are no selected rows', () => { const value = { ...instance,