Skip to content

Conversation

@CSilivestru
Copy link
Contributor

WHY are these changes introduced?

Similar to #4374, the sub-navigation items accept an onClick property but do not actually use it. This PR allows a consumer to provide a custom click handler that will be executed when a subnav item is clicked.

WHAT is this pull request doing?

This PR is to enable the subnav item to first execute onNavigationDismiss and then any other provided click handler, similar to the Item click handler

How to 🎩

  • Run this Polaris version in local web
  • Modify a subnavigation item to contain an onClick prop with a function that does something
  • Load web and click on that subnav item. Notice the click handler is executed

🎩 checklist

@CSilivestru CSilivestru requested a review from kyledurand August 12, 2021 19:44
@CSilivestru CSilivestru self-assigned this Aug 12, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Aug 12, 2021

size-limit report

Path Size
cjs 143.96 KB (+0.02% 🔺)
esm 97.84 KB (+0.03% 🔺)
esnext 143.51 KB (+0.02% 🔺)
css 34.53 KB (0%)

@CSilivestru CSilivestru force-pushed the allow.subnav.onclick branch from 1f76d9b to 66921db Compare August 17, 2021 20:38
@CSilivestru CSilivestru changed the base branch from main to v7.0.0-release August 17, 2021 20:59
@CSilivestru CSilivestru requested a review from voiid August 17, 2021 20:59
@CSilivestru
Copy link
Contributor Author

Talked to @BPScott and, even though the removal of MouseEvent in the click handler is a breaking change, we can put this into the 7.0.0 since this brings it back to Polaris Principles of not exposing DOM events :).

Copy link
Member

@kyledurand kyledurand left a comment

Choose a reason for hiding this comment

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

Minor comments on testing but I think they're worthwhile changes

},
});

expect(spy).toHaveBeenCalled();
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth using toHaveBeenCalledTimes(1) here. I think nav item is recursive in rendering itself as a sub nav item.

},
});

expect(spy).toHaveBeenCalled();
Copy link
Member

Choose a reason for hiding this comment

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

My comment here didn't get included in the review but I think it makes sense adding it here as well

I think the onClick checks you added in the component cover this but I'd hate to see that regression

UNRELEASED.md Outdated
- Bring back borders on the `IndexTable` sticky cells ([#4150](https://github.com/Shopify/polaris-react/pull/4150))
- Adjust `IndexTable` sticky z-index to avoid collisions with focused `TextField` ([#4150](https://github.com/Shopify/polaris-react/pull/4150))
- Adjust `IndexTable` rows to have a grey hover state when unselected ([#4359](https://github.com/Shopify/polaris-react/pull/4359))
- Properly support `selected` prop for `Navigation.Item` when `url` prop is not specified ([#4375](https://github.com/Shopify/polaris-react/pull/4375))
Copy link
Member

Choose a reason for hiding this comment

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

Whoops, just noticed this as well. I think it can be removed

Copy link
Contributor

@voiid voiid left a comment

Choose a reason for hiding this comment

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

LGTM. Do you know if there's impact for this change in web?

@CSilivestru
Copy link
Contributor Author

CSilivestru commented Aug 25, 2021

@voiid The subnav items in web do not currently use the onClick prop so there should be no effect :)

@kyledurand sorry for the delay but I will make those changes asap!

@CSilivestru CSilivestru force-pushed the allow.subnav.onclick branch from f87c0bf to 98e755a Compare August 25, 2021 18:43
},
});

expect(spy).toHaveBeenCalledTimes(2);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because of the recursive nature, onNavigationDismiss seems to be called twice (once at the sub nav level and once at the item level). Is that correct, @kyledurand?

Copy link
Member

Choose a reason for hiding this comment

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

Ok cool I think that makes sense 👍

@CSilivestru CSilivestru merged commit d685d6e into v7.0.0-release Aug 26, 2021
@CSilivestru CSilivestru deleted the allow.subnav.onclick branch August 26, 2021 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants