-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
ScrollLock: Covert component to TypeScript #42303
Conversation
Size Change: +1 B (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
component: ScrollLock, | ||
title: 'Components/ScrollLock', | ||
parameters: { | ||
controls: { hideNoControlsWarning: true }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
<StripedBackground> | ||
<div>Start scrolling down...</div> | ||
<ToggleContainer> | ||
<Button variant="primary" onClick={ toggleLock }> | ||
Toggle Scroll Lock | ||
</Button> | ||
{ isScrollLocked && <ScrollLock /> } | ||
<p> | ||
Scroll locked:{ ' ' } | ||
<strong>{ isScrollLocked ? 'Yes' : 'No' }</strong> | ||
</p> | ||
</ToggleContainer> | ||
</StripedBackground> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the point of this component would be better demonstrated (especially in Docs view) if we wrapped it in some divs that represent the "page body" and the "modal". I'll propose that in a follow-up PR once this is merged.
it( 'locks when mounted', () => { | ||
expect( document.documentElement ).not.toHaveClass( lockingClassName ); | ||
render( <ScrollLock /> ); | ||
expect( document.documentElement ).toHaveClass( lockingClassName ); | ||
} ); | ||
|
||
it( 'unlocks when unmounted', () => { | ||
const { unmount } = render( <ScrollLock /> ); | ||
expect( document.documentElement ).toHaveClass( lockingClassName ); | ||
unmount(); | ||
expect( document.documentElement ).not.toHaveClass( lockingClassName ); | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if using toMatchStyleDIffSnapshot
here would make for a better test — basically checking that the difference between locked and unlocked state on document.body
only produces an overflow: hidden
style diff.
Otherwise, we could completely change the styles associated with the lockscroll
CSS class and tests wouldn't break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to use toMatchStyleDIffSnapshot
on the body here 🤔 I tried, but failed to get the style. Are you able to take a look at it @ciampo? Either in this PR or as a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the implementation of toMatchStyleDiffSnapshot
, it may not be able to get inline styles.
Let's get this PR merged nonetheless - thank you for looking into it though!
What?
Converts the
ScrollLock
component to TypeScript.Why?
Part of the @wordpress/components's TypeScript migration (#35744).
How?
ScrollLock
to TypeScript.@testing-library/react
and TypeScriptTesting Instructions
ScrollLock
continues to function as expected