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

format mac hints according to guidelines #5

Merged
merged 5 commits into from
Feb 23, 2024
Merged

Conversation

myandrienko
Copy link
Contributor

@myandrienko myandrienko commented Feb 23, 2024

MacOS has specific guidelines regarding how hotkey shortcuts should be represented. Most importantly, they should be listed in a specific order (Ctrl, Alt, Shift, Meta), and the plus sign is not used a delimiter:

image

This PR implements those recommendations.

index.js Outdated
if (window.navigator.platform.indexOf('Mac') === 0) {
return pretty
return sortMacKeys(prettyParts)
.join(' ')
Copy link
Owner

Choose a reason for hiding this comment

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

Should we add a space? The screenshot didn’t have them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, the hint looks too loose with spaces:

image

Without spaces it looks better:

image

And you always have an option to use letter-spacing CSS property to control the spacing.

BTW, hints in the native Mac menus have a more complex layout, each key and modifier is aligned within its own column - so it won't look exactly right anyway.

Copy link
Owner

Choose a reason for hiding this comment

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

You can also use short-space symbol " "

@ai
Copy link
Owner

ai commented Feb 23, 2024

You will need to update package→size-limit (and maybe try some experiments to make size a little smaller. 40 bytes is too much for simple change.


test('makes mac hotkey hint prettier', () => {
equal(getHotKeyHint(MAC_WINDOW, 'alt+b'), '⌥ B')
equal(getHotKeyHint(MAC_WINDOW, 'meta+ctrl+shift+alt+b'), '⌃ ⌥ ⇧ ⌘ B')
Copy link
Owner

Choose a reason for hiding this comment

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

Can you also check that Win order is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test for windows.

Copy link
Owner

Choose a reason for hiding this comment

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

I mean not a test, but to find what order is canonical on Windows.

@myandrienko
Copy link
Contributor Author

You will need to update package→size-limit (and maybe try some experiments to make size a little smaller. 40 bytes is too much for simple change.

Tried a new approach (regex instead of sort) and actually managed to reduce the bundle size by 4B.

@ai
Copy link
Owner

ai commented Feb 23, 2024

Last things to do:

  1. Resolve conflict.
  2. Think about using short space for Mac
  3. Fix modifier order for Windows too 😈

@myandrienko
Copy link
Contributor Author

3. Fix modifier order for Windows too 😈

@ai For Windows, the modifier order is Meta (Win), Ctrl, Alt, Shift. Would you be OK with this as the canonical order of modifiers for aria-keyshortcuts, or is too much of a breaking change?

@ai
Copy link
Owner

ai commented Feb 23, 2024

For Windows, the modifier order is Meta (Win), Ctrl, Alt, Shift. Would you be OK with this as the canonical order of modifiers for aria-keyshortcuts, or is too much of a breaking change?

Yes, we just need to check that hotkeys.js expect the modifiers in that canonical order.

We don’t need to change this helper function, just change docs if needed.

@myandrienko
Copy link
Contributor Author

@ai All right, some changes are required in hotkey.js to make Meta (Win), Ctrl, Alt, Shift the canonical order - let's do it in a separate PR :)

@ai
Copy link
Owner

ai commented Feb 23, 2024

All right, some changes are required in hotkey.js to make Meta (Win), Ctrl, Alt, Shift the canonical order - let's do it in a separate PR :)

Agree.

In this case only two steps.

@myandrienko myandrienko requested a review from ai February 23, 2024 13:44
@ai ai merged commit 334b781 into ai:main Feb 23, 2024
4 checks passed
@ai
Copy link
Owner

ai commented Feb 24, 2024

Thanks. Released in 0.3.

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.

2 participants