Skip to content

Commit e2f6727

Browse files
fix: fixed incorrect label in Select All button (#2020)
* fix: fixed incorrect label in Select All button * refactor: added tests * refactor: added second test
1 parent 5944854 commit e2f6727

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/DataTable/selection/BaseSelectionStatus.jsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ function BaseSelectionStatus({
2020
allSelectedText,
2121
selectedText,
2222
}) {
23-
const { itemCount, isPaginated, state } = useContext(DataTableContext);
23+
const {
24+
itemCount, filteredRows, isPaginated, state,
25+
} = useContext(DataTableContext);
2426
const hasAppliedFilters = state?.filters?.length > 0;
2527
const isAllRowsSelected = numSelectedRows === itemCount;
28+
const filteredItems = filteredRows?.length || itemCount;
29+
2630
const intlAllSelectedText = allSelectedText || (
2731
<FormattedMessage
2832
id="pgn.DataTable.BaseSelectionStatus.allSelectedText"
@@ -65,7 +69,7 @@ function BaseSelectionStatus({
6569
id="pgn.DataTable.BaseSelectionStatus.selectAllText"
6670
defaultMessage="Select all {itemCount}"
6771
description="A label for select all button."
68-
values={{ itemCount }}
72+
values={{ itemCount: filteredItems }}
6973
/>
7074
)}
7175
</Button>

src/DataTable/selection/tests/SelectionStatus.test.jsx

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const instance = {
1515
page: [1, 2, 3, 4],
1616
toggleAllRowsSelected: () => {},
1717
itemCount: 101,
18+
filteredRows: [...new Array(27)],
1819
state: {
1920
selectedRowIds: {
2021
1: true,
@@ -70,6 +71,16 @@ describe('<SelectionStatus />', () => {
7071
expect(toggleAllRowsSpy).toHaveBeenCalledTimes(1);
7172
expect(toggleAllRowsSpy).toHaveBeenCalledWith(true);
7273
});
74+
it('updates select all button text after applying filters', () => {
75+
const wrapper = mount(<SelectionStatusWrapper value={{ ...instance }} />);
76+
const button = wrapper.find(`button.${SELECT_ALL_TEST_ID}`);
77+
expect(button.text()).toContain('Select all 27');
78+
});
79+
it('updates select all text if filters value is empty', () => {
80+
const wrapper = mount(<SelectionStatusWrapper value={{ ...instance, filteredRows: 0 }} />);
81+
const button = wrapper.find(`button.${SELECT_ALL_TEST_ID}`);
82+
expect(button.text()).toContain('Select all 101');
83+
});
7384
it('does not render the clear selection button if there are no selected rows', () => {
7485
const value = {
7586
...instance,

0 commit comments

Comments
 (0)