Skip to content
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

Using Safe triangle to improve submenu navigation #3536

Merged
merged 13 commits into from
Aug 26, 2024

Conversation

ddouglasz
Copy link
Contributor

@ddouglasz ddouglasz commented May 23, 2024

Summary

Using the Safe triangle pattern to improve submenu navigation

Description

Improve the submenu navigation by adding a safe area for users to smoothly navigate diagonally between the main menu and the submenu items, without awkwardly going out of focus.

Background:
https://x.com/shadeed9/status/1745707615517032449?t=XnNt9gNwPHLyfrMfHEnFuA&s=03

Before:
2024-05-23 08 16 23

After (The visible triangle is only for the demo. It is not included in the PR):
2024-05-23 08 13 35

@ddouglasz ddouglasz requested a review from a team as a code owner May 23, 2024 06:17
Copy link

vercel bot commented May 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mc-app-kit-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 26, 2024 0:59am
merchant-center-application-kit-components-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 26, 2024 0:59am

Copy link

changeset-bot bot commented May 23, 2024

🦋 Changeset detected

Latest commit: ac8c35c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
@commercetools-frontend/application-shell Minor
@commercetools-frontend/cypress Minor
@commercetools-applications/merchant-center-template-starter-typescript Minor
@commercetools-applications/merchant-center-template-starter Minor
@commercetools-applications/merchant-center-custom-view-template-starter-typescript Minor
@commercetools-applications/merchant-center-custom-view-template-starter Minor
@commercetools-local/playground Minor
@commercetools-local/visual-testing-app Minor
@commercetools-backend/eslint-config-node Minor
@commercetools-backend/express Minor
@commercetools-backend/loggers Minor
@commercetools-frontend/actions-global Minor
@commercetools-frontend/application-components Minor
@commercetools-frontend/application-config Minor
@commercetools-frontend/application-shell-connectors Minor
@commercetools-frontend/assets Minor
@commercetools-frontend/babel-preset-mc-app Minor
@commercetools-frontend/browser-history Minor
@commercetools-frontend/codemod Minor
@commercetools-frontend/constants Minor
@commercetools-frontend/create-mc-app Minor
@commercetools-frontend/eslint-config-mc-app Minor
@commercetools-frontend/i18n Minor
@commercetools-frontend/jest-preset-mc-app Minor
@commercetools-frontend/jest-stylelint-runner Minor
@commercetools-frontend/l10n Minor
@commercetools-frontend/mc-dev-authentication Minor
@commercetools-frontend/mc-html-template Minor
@commercetools-frontend/mc-scripts Minor
@commercetools-frontend/notifications Minor
@commercetools-frontend/permissions Minor
@commercetools-frontend/react-notifications Minor
@commercetools-frontend/sdk Minor
@commercetools-frontend/sentry Minor
@commercetools-frontend/url-utils Minor
@commercetools-website/components-playground Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kark
Copy link
Contributor

kark commented May 23, 2024

Thank you @ddouglasz for working on this ❤️
I've briefly checked it in the playground and for the most part it works fine, when the cursor motion is steady.
However, if I stop in the middle / change the pace of the movement, then the submenu hides.

I've noticed in the screencast from the description that the safe triangle only changes when cursor moves within the menu item boundaries. If it goes beyond the menu item, the triangle is set for good.
Screenshot 2024-05-23 at 14 41 01
In case of the implementation the triangle shrinks whenever cursor moves towards the submenu, so maybe this makes the behaviour not consistent
2024-05-23 14 31 11

@ddouglasz
Copy link
Contributor Author

Thank you Kacper 🙏🏾
I will look into it and push a fix.

@ddouglasz
Copy link
Contributor Author

ddouglasz commented Jun 6, 2024

I've noticed in the screencast from the description that the safe triangle only changes when cursor moves within the menu item boundaries. If it goes beyond the menu item, the triangle is set for good.

@kark thanks for your feedback again, after a couple of findings, I discovered a flaw with this implementation:
When a user begins to navigate diagonally and then stops halfway to move to the next item, vertically, they are blocked because the triangle is set for good until we close the submenu.
2024-06-06 09 09 19

Perhaps the current implementation that allows the the safe-start point of the triangle to move is what I see is consistent with most implementations:
If the users delays in the diagonal navigation, then it closes the submenu and focuses on the next item the cursor is hovering on.
2024-06-06 09 14 32

Would be nice to know what @FilPob also thinks about this 🙏🏾

@kark
Copy link
Contributor

kark commented Jun 6, 2024

I've noticed in the screencast from the description that the safe triangle only changes when cursor moves within the menu item boundaries. If it goes beyond the menu item, the triangle is set for good.

@kark thanks for your feedback again, after a couple of findings, I discovered a flaw with this implementation: When a user begins to navigate diagonally and then stops halfway to move to the next item, vertically, they are blocked because the triangle is set for good until we close the submenu.

Thanks! Perhaps we should consider adding a timeout for the triangle, similar to what we can see in your MacOS screencast. 🤔

@ddouglasz
Copy link
Contributor Author

ddouglasz commented Jun 6, 2024

I've noticed in the screencast from the description that the safe triangle only changes when cursor moves within the menu item boundaries. If it goes beyond the menu item, the triangle is set for good.

@kark thanks for your feedback again, after a couple of findings, I discovered a flaw with this implementation: When a user begins to navigate diagonally and then stops halfway to move to the next item, vertically, they are blocked because the triangle is set for good until we close the submenu.

Thanks! Perhaps we should consider adding a timeout for the triangle, similar to what we can see in your MacOS screencast. 🤔

Updated here: 25c5b47
Thank you.

Copy link

gitstream-cm bot commented Jun 17, 2024

This PR is missing a Jira ticket reference in the title or description.
Please add a Jira ticket reference to the title or description of this PR.

Copy link

gitstream-cm bot commented Jun 17, 2024

🥷 Code experts: emmenko

emmenko has most 🧠 knowledge in the files.

See details

packages/application-shell/src/components/navbar/menu-items.styles.ts

Knowledge based on git-blame:

packages/application-shell/src/components/navbar/menu-items.tsx

Knowledge based on git-blame:
emmenko: 58%

packages/application-shell/src/components/navbar/navbar.tsx

Knowledge based on git-blame:
emmenko: 1%

packages/application-shell/src/components/navbar/use-navbar-state-manager.ts

Knowledge based on git-blame:
emmenko: 63%

To learn more about /:\ gitStream - Visit our Docs

Copy link

@misama-ct misama-ct left a comment

Choose a reason for hiding this comment

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

Thanks for being persistent and making it work 👏 .
I have only some suggestions, nothing that would block approval.

Copy link
Contributor

@kark kark left a comment

Choose a reason for hiding this comment

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

Thank you, Douglas! That's a great improvement 👏. I have to admit, I'm still trying to nail down where the mouse movement speed threshold is set so that the safe triangle is applied, but overall, this looks great!

top: 0;
bottom: 0;
right: 100%;
width: calc(100% - 16px);
Copy link
Contributor

@kark kark Aug 26, 2024

Choose a reason for hiding this comment

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

I wonder, where does this 16px subtraction come from?

Copy link
Contributor Author

@ddouglasz ddouglasz Aug 26, 2024

Choose a reason for hiding this comment

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

This 16 px will always be the padding-left of the navbar area, also the start of the navbar item, whether expanded or collapsed. That is where we want our safe-area to end. So technically, our safe area width is the width of the navbar area, less of the padding left (which is 16px)
Screenshot 2024-08-26 at 12 45 15

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks got it 👍 Could we also add a comment here explaining that we account for the scrollable menu's padding and use the spacing30 design token?

Copy link
Contributor

@kark kark left a comment

Choose a reason for hiding this comment

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

🙌

top: 0;
bottom: 0;
right: 100%;
width: calc(100% - 16px);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks got it 👍 Could we also add a comment here explaining that we account for the scrollable menu's padding and use the spacing30 design token?

@@ -256,6 +266,18 @@ const useNavbarStateManager = (props: HookProps) => {
[state.activeItemIndex]
);

const handleMouseMove = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: just noticed that we have two functions named handleMouseMove that do different things. Could we rename this one to be more descriptive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated here: ac8c35c

const safeAreaWidth = submenuSafeAreaRefBoundingClientRect?.width || 0;
const safeAreaHeight = submenuSafeAreaRefBoundingClientRect?.height || 0;

const handleMouseMove = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, let's rename this one too. To e.g. calculateSafeAreaStartPositon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated here: ac8c35c

Thank you 🙌🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants