@@ -18,23 +18,28 @@ interface IStyledKbdProps extends ThemeProps<DefaultTheme> {
18
18
}
19
19
20
20
const sizeStyles = ( { theme, $size } : IStyledKbdProps ) => {
21
+ let minWidth ;
21
22
let paddingHorizontal ;
22
23
let paddingVertical = '0' ;
23
24
24
25
switch ( $size ) {
25
26
case 'small' :
27
+ minWidth = math ( `${ theme . lineHeights . sm } - 1px` ) ;
26
28
paddingHorizontal = `${ theme . space . base } px` ;
27
29
break ;
28
30
29
31
case 'medium' :
32
+ minWidth = math ( `${ theme . lineHeights . md } - 1px` ) ;
30
33
paddingHorizontal = `${ theme . space . base * 1.5 } px` ;
31
34
break ;
32
35
33
36
case 'large' :
37
+ minWidth = math ( `${ theme . lineHeights . lg } - 1px` ) ;
34
38
paddingHorizontal = `${ theme . space . base * 1.75 } px` ;
35
39
break ;
36
40
37
41
default :
42
+ minWidth = 'calc(1.2em + 3px)' ; // "normal" line-height + vertical padding
38
43
paddingHorizontal = `${ stripUnit ( math ( `${ theme . space . base * 1.5 } / (${ theme . fontSizes . md } - 1px)` ) ) } em` ;
39
44
paddingVertical = '1.5px' ;
40
45
break ;
@@ -44,13 +49,17 @@ const sizeStyles = ({ theme, $size }: IStyledKbdProps) => {
44
49
45
50
return css `
46
51
& & {
52
+ box-sizing : border-box;
47
53
padding : ${ padding } ;
54
+ min-width : ${ minWidth } ;
48
55
}
49
56
` ;
50
57
} ;
51
58
52
59
/*
53
60
* 1. Force left-to-right text direction
61
+ * 2. Prevent the monospace stack fallback, which doesn't render individual
62
+ * keyboard characters well
54
63
*/
55
64
export const StyledKbd = styled ( StyledCode as 'kbd' ) . attrs ( {
56
65
'data-garden-id' : COMPONENT_ID ,
@@ -59,6 +68,8 @@ export const StyledKbd = styled(StyledCode as 'kbd').attrs({
59
68
} ) < IStyledKbdProps > `
60
69
display: inline-block; /* [1] */
61
70
direction: ltr; /* [1] */
71
+ text-align: center;
72
+ font-family: sans-serif; /* [2] */
62
73
63
74
${ sizeStyles } ;
64
75
0 commit comments