Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compose: Add types to useReducedMotion and useMediaQuery #31941

Merged
merged 2 commits into from
May 21, 2021
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
2 changes: 1 addition & 1 deletion packages/compose/src/hooks/use-media-query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ export default function useMediaQuery( query ) {
};
}, [ query ] );

return query && match;
return !! query && match;
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be breaking some existing tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, you're right. I wonder if we should update the test or keep the existing behavior and use a wider return type 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've gone ahead and updated the test.

}
3 changes: 2 additions & 1 deletion packages/compose/src/hooks/use-media-query/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ describe( 'useMediaQuery', () => {
await act( async () => {
root = create( <TestComponent /> );
} );
expect( root.toJSON() ).toBe( 'useMediaQuery: undefined' );
// query will be case to a boolean to simplify the return type.
expect( root.toJSON() ).toBe( 'useMediaQuery: false' );

await act( async () => {
root.update( <TestComponent query={ false } /> );
Expand Down
3 changes: 3 additions & 0 deletions packages/compose/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"rootDir": "src",
"declarationDir": "build-types",
"types": [ "gutenberg-env" ],
},
"references": [
{ "path": "../element" },
Expand All @@ -20,6 +21,8 @@
"src/hooks/use-instance-id/**/*",
"src/hooks/use-focus-return/**/*",
"src/hooks/use-previous/**/*",
"src/hooks/use-media-query/**/*",
"src/hooks/use-reduced-motion/**/*",
"src/utils/**/*"
]
}
1 change: 1 addition & 0 deletions typings/gutenberg-env/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface Environment {
NODE_ENV: unknown;
COMPONENT_SYSTEM_PHASE: number | undefined;
FORCE_REDUCED_MOTION: boolean | undefined;
}
interface Process {
env: Environment;
Expand Down