Skip to content

Commit 00a7b36

Browse files
committed
Also support print media
1 parent 99fa629 commit 00a7b36

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class HyperResponsiveTable extends Component {
7070
let narrow = false;
7171
const { breakpoint } = props;
7272
if (matchMedia) {
73-
mql = window.matchMedia(typeof breakpoint === 'string' ? breakpoint : `screen and (min-width: ${breakpoint}px)`);
73+
mql = window.matchMedia(typeof breakpoint === 'string' ? breakpoint : `(min-width: ${breakpoint}px)`);
7474
mql.addListener(this.handleMatch);
7575
narrow = !mql.matches;
7676
}

src/index.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,54 @@ describe('Component', () => {
195195
expect(tr[0].getAttribute('class')).toEqual('row-A 1');
196196
});
197197
});
198+
199+
it('print wide', (done) => {
200+
const breakpoint = 1000;
201+
const tableStyling = (opts) => (opts.narrow ? 'narrow' : 'wide');
202+
const props = {
203+
headers,
204+
rows,
205+
keyGetter,
206+
breakpoint,
207+
tableStyling,
208+
};
209+
210+
render(<Component {...props} />, node, () => {
211+
const table = node.querySelector('table');
212+
expect(table.getAttribute('class')).toEqual('wide');
213+
214+
matchMedia.setConfig({ type: 'print', width: 1001 });
215+
216+
// Wait a bit before React notices the screen size update.
217+
setTimeout(() => {
218+
expect(table.getAttribute('class')).toEqual('wide');
219+
done();
220+
}, 50);
221+
});
222+
});
223+
224+
it('print narrow', (done) => {
225+
const breakpoint = 1000;
226+
const tableStyling = (opts) => (opts.narrow ? 'narrow' : 'wide');
227+
const props = {
228+
headers,
229+
rows,
230+
keyGetter,
231+
breakpoint,
232+
tableStyling,
233+
};
234+
235+
render(<Component {...props} />, node, () => {
236+
const table = node.querySelector('table');
237+
expect(table.getAttribute('class')).toEqual('wide');
238+
239+
matchMedia.setConfig({ type: 'print', width: 900 });
240+
241+
// Wait a bit before React notices the screen size update.
242+
setTimeout(() => {
243+
expect(table.getAttribute('class')).toEqual('narrow');
244+
done();
245+
}, 50);
246+
});
247+
});
198248
});

0 commit comments

Comments
 (0)