Skip to content

Commit 3191d13

Browse files
Fixed IndexTable bulk header not working (#7453)
### WHY are these changes introduced? There was a [change](#6583) that updated how index table behaves on small screens. However, the variable setting small screen state is not correctly updated on resize causing the not to be incorrect when moving from large -> small or small -> large. ### WHAT is this pull request doing? Updating the value on resize ### How to 🎩 Load `indextable--small-screen-with-all-of-its-elements` on a large screen then resize to small. [Spin link](https://admin.web.am-test-it-ba.andrew-musgrave.us.spin.dev/store/shop1/orders?inContextTimeframe=none) ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [ ] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
1 parent 90487fd commit 3191d13

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

.changeset/tidy-wasps-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Fixed IndexTable not rendering bulk actions on resize

polaris-react/src/components/IndexTable/IndexTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ function IndexTableBase({
299299
}, [handleCanScrollRight]);
300300

301301
const handleIsSmallScreen = useCallback(() => {
302-
setSmallScreen(smallScreen);
303-
}, [smallScreen]);
302+
setSmallScreen(isBreakpointsXS());
303+
}, []);
304304

305305
const [canFitStickyColumn, setCanFitStickyColumn] = useState(true);
306306

polaris-react/src/components/IndexTable/tests/IndexTable.test.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,14 @@ describe('<IndexTable>', () => {
383383
});
384384

385385
describe('BulkActions', () => {
386+
const originalInnerWidth = window.innerWidth;
387+
388+
afterEach(() => {
389+
Object.defineProperty(window, 'innerWidth', {
390+
value: originalInnerWidth,
391+
});
392+
});
393+
386394
it('toggles all resources selected when paginatedSelectionAllAction is triggered', () => {
387395
const onSelectionChangeSpy = jest.fn();
388396
const index = mountWithApp(
@@ -452,6 +460,65 @@ describe('<IndexTable>', () => {
452460
true,
453461
);
454462
});
463+
464+
it('passes smallScreen to bulk actions', () => {
465+
const promotedActions = [{content: 'PromotedAction'}];
466+
467+
const indexTable = mountWithApp(
468+
<IndexTable
469+
{...defaultProps}
470+
selectable
471+
selectedItemsCount={1}
472+
itemCount={2}
473+
promotedBulkActions={promotedActions}
474+
>
475+
{mockTableItems.map(mockRenderCondensedRow)}
476+
</IndexTable>,
477+
);
478+
479+
indexTable.find(BulkActions)!.trigger('onToggleAll');
480+
481+
expect(indexTable).toContainReactComponent(BulkActions, {
482+
smallScreen: expect.any(Boolean),
483+
});
484+
});
485+
486+
it('passes an updated smallScreen value to bulk actions after resize', () => {
487+
Object.defineProperty(window, 'innerWidth', {
488+
value: 1000,
489+
});
490+
491+
const promotedActions = [{content: 'PromotedAction'}];
492+
493+
const indexTable = mountWithApp(
494+
<IndexTable
495+
{...defaultProps}
496+
selectable
497+
selectedItemsCount={1}
498+
itemCount={2}
499+
promotedBulkActions={promotedActions}
500+
>
501+
{mockTableItems.map(mockRenderCondensedRow)}
502+
</IndexTable>,
503+
);
504+
505+
indexTable.find(BulkActions)!.trigger('onToggleAll');
506+
507+
expect(indexTable).toContainReactComponent(BulkActions, {
508+
smallScreen: false,
509+
});
510+
511+
indexTable.act(() => {
512+
Object.defineProperty(window, 'innerWidth', {
513+
value: 300,
514+
});
515+
window.dispatchEvent(new Event('resize'));
516+
});
517+
518+
expect(indexTable).toContainReactComponent(BulkActions, {
519+
smallScreen: true,
520+
});
521+
});
455522
});
456523

457524
describe('condensed', () => {

0 commit comments

Comments
 (0)