Skip to content

Commit c1c33d0

Browse files
v6: Vertically center the KeycapHint glyph (#4400)
## Summary - The glyph inside a `KeycapHint` key (`⌘`, `⌃`, `⌥`, `⇧`, `⏎`, letters) sat slightly above center. Centering the line box wasn't enough by itself, since these glyphs carry more ink above the baseline than below it. - The glyph now renders in its own span with a small `translateY` nudge, measured against each glyph's actual ink bounds rather than guessed. `⌃` needed the most help; the rest were already close. ## Test plan - [ ] Open GraphiQL, look at a keycap hint in the top bar (e.g. the `⌘` `⏎` run shortcut), and confirm the glyph is vertically centered on the key. - [ ] In Storybook, view `Primitives/KeycapHint` (Single, ChordWithModifier, RunShortcut stories) in both dark and light theme and confirm centering holds across the different glyphs. Refs: #4219
1 parent 77a6a78 commit c1c33d0

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphiql/react': patch
3+
---
4+
5+
Vertically center the glyph inside `KeycapHint` keys.

packages/graphiql-react/src/components/keycap-hint/index.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@
2020
font-weight: 600;
2121
line-height: 1;
2222
}
23+
24+
.graphiql-keycap-glyph {
25+
/* The glyphs' ink sits slightly above the vertical center of their em
26+
box, so centering the line box alone isn't quite enough. */
27+
transform: translateY(0.05em);
28+
}

packages/graphiql-react/src/components/keycap-hint/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const KeycapHint: FC<KeycapHintProps> = ({ keys, ariaLabel }) => {
4545
<span className="graphiql-keycap-hint" aria-label={ariaLabel}>
4646
{keys.map((k, i) => (
4747
<kbd key={`${k}-${i}`} className="graphiql-keycap">
48-
{display[k] ?? k}
48+
<span className="graphiql-keycap-glyph">{display[k] ?? k}</span>
4949
</kbd>
5050
))}
5151
</span>

0 commit comments

Comments
 (0)