Skip to content
Open
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
10 changes: 5 additions & 5 deletions playwright-tests/features/responsive/responsive.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from "@playwright/experimental-ct-react";
import Responsive from "./responsive.story";

test.use({ viewport: { width: 1200, height: 500 } });
test.use({ viewport: { width: 1000, height: 500 } });

async function activeSlidesCount(component) {
return await component.locator(".slick-slide.slick-active").count();
Expand All @@ -10,11 +10,11 @@ async function activeSlidesCount(component) {
test("Responsive settings", async ({ mount, page }) => {
const component = await mount(<Responsive />);

await expect(await activeSlidesCount(component)).toEqual(4);
await expect(await activeSlidesCount(component)).toEqual(3);

await page.setViewportSize({ width: 1000, height: 500 });
await page.setViewportSize({ width: 1200, height: 500 });
await page.waitForTimeout(100);
await expect(await activeSlidesCount(component)).toEqual(3);
await expect(await activeSlidesCount(component)).toEqual(4);

await page.setViewportSize({ width: 600, height: 500 });
await page.waitForTimeout(100);
Expand All @@ -35,4 +35,4 @@ test("Responsive settings", async ({ mount, page }) => {
await page.setViewportSize({ width: 1500, height: 500 });
await page.waitForTimeout(100);
await expect(await activeSlidesCount(component)).toEqual(4);
});
});
6 changes: 6 additions & 0 deletions src/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export default class Slider extends React.Component {
}
};
mql.addListener(listener);

// Manually check if the query currently matches on initial load
if (mql.matches) {
handler();
}

this._responsiveMediaHandlers.push({ mql, query, listener });
}

Expand Down