-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
fix(KeyComboTag): Better rendering on non-Mac operating systems #7025
Conversation
Generate changelog in
|
fix(KeyComboTag): Better rendering on non-Mac operating systemsBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
const keys = combo.replace(/\s/g, "").split("+"); | ||
return keys.map(key => { | ||
const keyName = CONFIG_ALIASES[key] != null ? CONFIG_ALIASES[key] : key; | ||
return keyName === "meta" ? (isMac(platformOverride) ? "cmd" : "ctrl") : keyName; | ||
}); | ||
}; | ||
|
||
function isMac(platformOverride?: string) { | ||
export function isMac(platformOverride: string | undefined) { |
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.
This function is duplicative with another in the codebase, will be looking into refactoring that in a future change.
Add generated changelog entriesBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
FixesBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
describe -> itBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
Fix tests for realBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
|
||
describe("KeyCombo", () => { | ||
it("renders key combo", () => { | ||
render(<KeyComboTag combo="cmd+C" />); | ||
render(<KeyComboTagInternal combo="cmd+C" platformOverride="Mac" />); |
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.
Are we using this platformOverride
flag solely for testing purposes? If so, that feels a slight bit icky to me. Is there a way we could potentially mock the return of the isMac
function instead? This would potentially save us from having to wire this override flag in multiple places.
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.
Agreed its ugly. However, I took a look around and wasn't able to find a good way to mock isMac
, but let me know if I missed something here. I did make the argument required on these functions so that we wouldn't forget to pass it and miss a spot.
private renderMinimalKey = (key: string, index: number, isLastKey: boolean) => { | ||
const icon = this.getKeyIcon(key); | ||
if (icon == null) { | ||
return isLastKey ? key : <React.Fragment key={`key-${index}`}>{key} + </React.Fragment>; |
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.
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.
Following that, I wonder if we could insert the plus signs an alternative way, perhaps either via a CSS ::before
pseudo-element or by inserting them after construction of the array, e.g.
const normalizedKeys = normalizeKeyCombo(combo, platformOverride);
const upperKeys = normalizedKeys.map(key => (key.length === 1 ? key.toUpperCase() : key));
const keys = upperKeys.map(this.renderKey);
const minimalKeys = upperKeys
.map(this.renderMinimalKey)
.flatMap((value, index, array) =>
array.length - 1 !== index ? [value, <span key={index}>+</span>] : value,
);
return <span className={classNames(Classes.KEY_COMBO, className)}>{minimal ? minimalKeys : keys}</span>;
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.
I wanted to mirror the ways these different platforms display key combos. Namely on Windows/Linux, will show the plus signs and on Macs they will not. Agreed on the extra space, will fix that.
In terms of putting in the plus signs, I attempted to use the pseudo elements earlier but getting the styles to work on those turned out to be unwieldy. Its not clear to me that the code above is particularly better than what we have currently.
Fixes #6211
Checklist
Changes proposed in this pull request:
In this PR we update the
KeyComboTag
component to render properly in non-Mac environments. Namely, all modifier keys no longer show their icons (which are mac specific). In addition the minimal state has been updated to show a more windows friendly UI. Finally, the arrow keys were broken and not showing their icons, they do now.Reviewers should focus on:
I implemented a
KeyComboTagInternal
component for testing purposes. What do we think of this pattern?Screenshot
Previously, this is how the
mod+shift+x
key combo looked like on all platforms. This is still how it looks on Mac. (Minimal state on bottom)This is how it looks non-Mac platforms now: