@@ -18,23 +18,28 @@ interface IStyledKbdProps extends ThemeProps<DefaultTheme> {
1818}
1919
2020const 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 */
5564export 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