Skip to content

Commit 563c6ad

Browse files
authored
fix(typography): improve Kbd font (#2044)
1 parent 8300d15 commit 563c6ad

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/typography/demo/kbd.stories.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import README from '../README.md';
1212
# Demo
1313

1414
<Canvas>
15-
<Story name="Kbd" args={{ children: '⌃ ⌥ /', size: 'inherit' }}>
15+
<Story name="Kbd" args={{ children: '⌃ ⌥ /', size: 'inherit' }}>
1616
{args => <KbdStory {...args} />}
1717
</Story>
1818
</Canvas>

packages/typography/src/styled/StyledKbd.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,28 @@ interface IStyledKbdProps extends ThemeProps<DefaultTheme> {
1818
}
1919

2020
const sizeStyles = ({ theme, $size }: IStyledKbdProps) => {
21+
let minWidth;
2122
let paddingHorizontal;
2223
let paddingVertical = '0';
2324

2425
switch ($size) {
2526
case 'small':
27+
minWidth = math(`${theme.lineHeights.sm} - 1px`);
2628
paddingHorizontal = `${theme.space.base}px`;
2729
break;
2830

2931
case 'medium':
32+
minWidth = math(`${theme.lineHeights.md} - 1px`);
3033
paddingHorizontal = `${theme.space.base * 1.5}px`;
3134
break;
3235

3336
case 'large':
37+
minWidth = math(`${theme.lineHeights.lg} - 1px`);
3438
paddingHorizontal = `${theme.space.base * 1.75}px`;
3539
break;
3640

3741
default:
42+
minWidth = 'calc(1.2em + 3px)'; // "normal" line-height + vertical padding
3843
paddingHorizontal = `${stripUnit(math(`${theme.space.base * 1.5} / (${theme.fontSizes.md} - 1px)`))}em`;
3944
paddingVertical = '1.5px';
4045
break;
@@ -44,13 +49,17 @@ const sizeStyles = ({ theme, $size }: IStyledKbdProps) => {
4449

4550
return css`
4651
&& {
52+
box-sizing: border-box;
4753
padding: ${padding};
54+
min-width: ${minWidth};
4855
}
4956
`;
5057
};
5158

5259
/*
5360
* 1. Force left-to-right text direction
61+
* 2. Prevent the monospace stack fallback, which doesn't render individual
62+
* keyboard characters well
5463
*/
5564
export const StyledKbd = styled(StyledCode as 'kbd').attrs({
5665
'data-garden-id': COMPONENT_ID,
@@ -59,6 +68,8 @@ export const StyledKbd = styled(StyledCode as 'kbd').attrs({
5968
})<IStyledKbdProps>`
6069
display: inline-block; /* [1] */
6170
direction: ltr; /* [1] */
71+
text-align: center;
72+
font-family: sans-serif; /* [2] */
6273
6374
${sizeStyles};
6475

0 commit comments

Comments
 (0)