-
Notifications
You must be signed in to change notification settings - Fork 87
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
Feat: Add Mobile styles to FooterNav #181
Conversation
|
||
describe('isMobile', () => { | ||
it.todo( | ||
'renders mobile view when client window width is less than threshold' |
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 can't figure out how to test window resize with running into typescript read-only
limitations on reassigning window
objects during a test. Ideally, I was going to use jest beforeAll
to adjust the window size to mobile before running all the tests in this describe block.
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.
could you use the resizeTo
method instead of reassigning the dimensions? https://developer.mozilla.org/en-US/docs/Web/API/Window/resizeTo
imo this would be a great test to have!
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.
Tried out resizeTo
but its not implemented. jest incorporates JSDOM to override window
- and JSDOM doesn't support all the same methods. Ended up overriding tyepscript and then eslint warnings about overriding typescript 😆 I hadn't realized I could just do that and move on.
src/components/Footer/FooterExtendedNavList/FooterExtendedNavList.stories.tsx
Outdated
Show resolved
Hide resolved
src/components/Footer/FooterExtendedNavList/FooterExtendedNavList.tsx
Outdated
Show resolved
Hide resolved
src/components/Footer/FooterExtendedNavList/FooterExtendedNavList.tsx
Outdated
Show resolved
Hide resolved
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 just had a couple of questions. Nice work :)
- refactor out FooterExtendedNavList - add more tests
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 left some comments but they are pretty minor. This is looking really good!
src/components/Footer/FooterExtendedNavList/FooterExtendedNavList.stories.tsx
Outdated
Show resolved
Hide resolved
|
||
describe('isMobile', () => { | ||
it.todo( | ||
'renders mobile view when client window width is less than threshold' |
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.
could you use the resizeTo
method instead of reassigning the dimensions? https://developer.mozilla.org/en-US/docs/Web/API/Window/resizeTo
imo this would be a great test to have!
src/components/Footer/FooterExtendedNavList/FooterExtendedNavList.tsx
Outdated
Show resolved
Hide resolved
|
||
function handleResize(): void { | ||
const isMobileWidth = window.innerWidth < 480 | ||
setIsMobile(isMobileWidth) |
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.
my only suggestion here would be to only call setIsMobile
if the value has changed, to avoid extraneous state updates
src/components/Footer/FooterExtendedNavList/FooterExtendedNavList.tsx
Outdated
Show resolved
Hide resolved
React.HTMLAttributes<HTMLElement>): React.ReactElement => { | ||
const classes = classnames('grid-row grid-gap-4', className) | ||
|
||
const [isMobile, setIsMobile] = React.useState(false) |
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.
This is super minor but I noticed there is a brief flash of the desktop nav at mobile sizes on render. I think that could be resolved by doing the initial window size check here to default the state to the correct value (instead of false
) and then that would remove the need to trigger handleResize()
in the effect hook
- add back useEffect for window resize - make isMobile be possibly undefined - adjust tests and remove unncessary story - prevent unncessary state renders
@suzubara I incorporated the changes you suggested. Tried to rename variables a bit to help clarify the difference between |
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.
left a couple comments but only one is blocking
// Mobile width is less than 480 | ||
//eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
//@ts-ignore | ||
window.innerWidth = 479 |
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.
non-blocking: just curious, did you try using window.resizeTo
instead of assigning innerWidth
? then I don't think we'd run into the TS problem
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.
FYI #181 (comment) Also just double checked it this is the exact error in the console Error: Not implemented: window.resizeTo
on running jest.
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.
Ooh I see, got it! 👍
if (!isClient) return | ||
|
||
function handleResize(): void { | ||
if (isMobileWidth !== isMobileFallback) { |
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 isMobileWidth
needs to be re-checked on resize? It doesn't look like this changes when you size up/down
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 catch I wasn't seeing any issues with my testing and this made me look at again. Definitely need to called window.innerWidth
each time in handleResize
to get the right behaviors when lots of resizing of the window is happening.
const useMobile = isMobile || (isMobile === undefined && isMobileFallback) | ||
|
||
useEffect(() => { | ||
if (!isClient) return |
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.
non-blocking: just for performance, couldn't we also do an early return
if isMobile
is defined? since then the fallback isn't used at all and we wouldn't need to attach the event listener.
- refactor out FooterExtendedNavList - add more tests
<FooterNav>
andFooterExtendedNavList>
Completed
FooterExtendedNavList
Testing
View
Footer
,FooterNav
,FooterExtendedNavList
components in mobile styles.