-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Navigation.Item] Fix onClick not being called on small screens #603
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
Conversation
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.
🎩 looks good.
side note: is it me or it's a little tricky to wrap your head around what is really going on here? I understand whats happening but I had to really follow it through.
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.
🎩 LGTM too, though I am similarly confused as to the nature of this issue.
Would you mind annotating your test additions to help others understand how you're simulating a small screen size?
describe('small screens', () => { | ||
let matchMedia: jest.SpyInstance; | ||
beforeEach(() => { | ||
matchMedia = jest.spyOn(window, 'matchMedia'); |
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.
matchMedia is a window function used to match media queries in javascript. Item uses it in ->
if (onClick && !navigationBarCollapsed().matches) { |
matchMedia = jest.spyOn(window, 'matchMedia'); | ||
matchMedia.mockImplementation(() => { | ||
return { | ||
matches: 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.
Always returning a screen match
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.
Paired with the utilities navigationBarCollapsed()
, it'll always be true.
I recall @beefchimi being annoyed at matchmedia not being supported by jsdom recently. I wonder if creating a standard mock implementation in jest-dom-mocks would be useful for everybody. |
@AndrewMusgrave when is this planned to release? Can we use it before the release? |
Great idea! @RishabhTayal We're planning on doing a patch release ~2pm EST |
@AndrewMusgrave I tested this in 3.0.1 version. The |
I'm pretty sure this is still an issue with nested items={[
{
label: "Crafting",
url: "/skills/crafting/engineering/pathway",
subNavigationItems: [
{
url: "/skills/crafting/engineering/pathway",
label: "Engineering",
subNavigationItems: [
{
url: "/skills/crafting/engineering/pathway",
label: "Pathway",
onClick: handleNavClick,
},
{
url: "/skills/crafting/engineering/items",
label: "Items",
onClick: handleNavClick,
},
],
},
],
}, Using this This is on 10.16.1 |
Hi @brydom I took a look at the types for the navigation component and it seems nested |
WHY are these changes introduced?
Fixes #598
WHAT is this pull request doing?
When on a small screens and onNavigationDismiss is undefined onClick is never called
How to 🎩
Make sure onClick is being called when on small screens
Copy-paste this code in
playground/Playground.tsx
: