Skip to content
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
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### Bug fixes

- Fixed `Navigation.Item` not calling `onClick` on small screens when `onNavigationDismiss` is undefined ([#603](https://github.com/Shopify/polaris-react/pull/603))
- Fixed `Autocomplete` empty state example Markdown not parsing correctly ([#592](https://github.com/Shopify/polaris-react/pull/592))

### Documentation
Expand Down
2 changes: 1 addition & 1 deletion src/components/Navigation/components/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export class BaseItem extends React.Component<CombinedProps, State> {
return;
}

if (onClick && !navigationBarCollapsed().matches) {
if (onClick) {
onClick();
}
};
Expand Down
49 changes: 49 additions & 0 deletions src/components/Navigation/components/Item/tests/Item.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,55 @@ describe('<Nav.Item />', () => {
.exists(),
).toBe(true);
});

describe('small screens', () => {
let matchMedia: jest.SpyInstance;
beforeEach(() => {
matchMedia = jest.spyOn(window, 'matchMedia');
Copy link
Member Author

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) {
to determine screen size

matchMedia.mockImplementation(() => {
return {
matches: true,
Copy link
Member Author

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

Copy link
Member Author

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.

addListener() {},
removeListener() {},
};
});
});

afterEach(() => {
matchMedia.mockRestore();
});

describe('onClick', () => {
it('will fire once on small screens when onNavigationDismiss is defined', () => {
const item = mountWithAppProvider(
<Item label="some label" disabled={false} onClick={jest.fn()} />,
{
context: {
location: 'bar',
onNavigationDismiss: noop,
},
},
);

item.find('button').simulate('click');
expect(item.prop('onClick')).toHaveBeenCalledTimes(1);
});

it('will fire once on small screens when onNavigationDismiss is undefined', () => {
const item = mountWithAppProvider(
<Item label="some label" disabled={false} onClick={jest.fn()} />,
{
context: {
location: 'bar',
},
},
);

item.find('button').simulate('click');
expect(item.prop('onClick')).toHaveBeenCalledTimes(1);
});
});
});
});

function itemForLocation(location: string, overrides: Partial<ItemProps> = {}) {
Expand Down