Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tidy-wasps-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Fixed IndexTable not rendering bulk actions on resize
4 changes: 2 additions & 2 deletions polaris-react/src/components/IndexTable/IndexTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ function IndexTableBase({
}, [handleCanScrollRight]);

const handleIsSmallScreen = useCallback(() => {
setSmallScreen(smallScreen);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we were just setting state to what it already was

}, [smallScreen]);
setSmallScreen(isBreakpointsXS());
}, []);

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

Expand Down
67 changes: 67 additions & 0 deletions polaris-react/src/components/IndexTable/tests/IndexTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@ describe('<IndexTable>', () => {
});

describe('BulkActions', () => {
const originalInnerWidth = window.innerWidth;

afterEach(() => {
Object.defineProperty(window, 'innerWidth', {
value: originalInnerWidth,
});
});

it('toggles all resources selected when paginatedSelectionAllAction is triggered', () => {
const onSelectionChangeSpy = jest.fn();
const index = mountWithApp(
Expand Down Expand Up @@ -452,6 +460,65 @@ describe('<IndexTable>', () => {
true,
);
});

it('passes smallScreen to bulk actions', () => {
const promotedActions = [{content: 'PromotedAction'}];

const indexTable = mountWithApp(
<IndexTable
{...defaultProps}
selectable
selectedItemsCount={1}
itemCount={2}
promotedBulkActions={promotedActions}
>
{mockTableItems.map(mockRenderCondensedRow)}
</IndexTable>,
);

indexTable.find(BulkActions)!.trigger('onToggleAll');

expect(indexTable).toContainReactComponent(BulkActions, {
smallScreen: expect.any(Boolean),
});
});

it('passes an updated smallScreen value to bulk actions after resize', () => {
Object.defineProperty(window, 'innerWidth', {
value: 1000,
});

const promotedActions = [{content: 'PromotedAction'}];

const indexTable = mountWithApp(
<IndexTable
{...defaultProps}
selectable
selectedItemsCount={1}
itemCount={2}
promotedBulkActions={promotedActions}
>
{mockTableItems.map(mockRenderCondensedRow)}
</IndexTable>,
);

indexTable.find(BulkActions)!.trigger('onToggleAll');

expect(indexTable).toContainReactComponent(BulkActions, {
smallScreen: false,
});

indexTable.act(() => {
Object.defineProperty(window, 'innerWidth', {
value: 300,
});
window.dispatchEvent(new Event('resize'));
});

expect(indexTable).toContainReactComponent(BulkActions, {
smallScreen: true,
});
});
});

describe('condensed', () => {
Expand Down