Skip to content

Commit

Permalink
fix(mq): use addListener and removeListener (#402)
Browse files Browse the repository at this point in the history
* fix(mq): use addListener and removeListener

* fix(select): ie arrow
  • Loading branch information
reme3d2y committed Dec 2, 2020
1 parent c0c1723 commit 9918383
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/mq/src/Component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { Mq } from './Component';
jest.mock('./utils', () => ({
isPointerEventsSupported: jest.fn(() => true),
getMatchMedia: jest.fn(() => ({
addEventListener: jest.fn,
removeEventListener: jest.fn,
addListener: jest.fn,
removeListener: jest.fn,
matches: false,
})),
releaseMatchMedia: jest.fn,
}));

function mockGetMatchMedia(result: boolean) {
(getMatchMedia as jest.Mock).mockReturnValueOnce({
addEventListener: jest.fn,
removeEventListener: jest.fn,
addListener: jest.fn,
removeListener: jest.fn,
matches: result,
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/mq/src/useMatchMedia.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jest.mock('./utils');

function mockGetMatchMedia(matches: boolean) {
(getMatchMedia as jest.Mock).mockReturnValue({
addEventListener: jest.fn,
removeEventListener: jest.fn,
addListener: jest.fn,
removeListener: jest.fn,
matches,
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/mq/src/useMatchMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export const useMatchMedia = (query: string) => {

const handleMatchChange = () => setMatches(mql.matches);

mql.addEventListener('change', handleMatchChange);
mql.addListener(handleMatchChange);
handleMatchChange();

return () => {
mql.removeEventListener('change', handleMatchChange);
mql.removeListener(handleMatchChange);
releaseMatchMedia(query);
};
}, [query]);
Expand Down
1 change: 1 addition & 0 deletions packages/select/src/components/arrow/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

background: var(--select-arrow-background);
background-size: cover;
background-position: center;
transition: opacity 0.2s ease;
}

Expand Down

0 comments on commit 9918383

Please sign in to comment.