Skip to content

Commit da143dd

Browse files
chapterjasonclaude
andcommitted
Universal preview bubble + natural-sized alts popover
- Preview popover on every char key press, exactly anchor-key-wide - Alts popover transforms from the preview on long-press (same DOM node). #positionPopover clears opposite-mode inline size each run so a stale preview width doesn't pin the alts box at key width while its buttons lay out their natural sum and overflow - Alts popover uses natural flex sizing (no JS minWidth, no per-alt width overrides); .popover justify-content: center keeps content centered even when it's narrower than the anchor - Simple preview path is gated to key.action.kind === "char" so space, return, backspace, shift, layer, and globe keys no longer surface a redundant preview Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2cf448e commit da143dd

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/keyboard/element.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,14 @@ export class VirtualKeyboard extends HTMLElement {
494494
const hasAlts = !!(key.alternates && key.alternates.length > 0);
495495
if (hasAlts) {
496496
this.#onPointerDown(e, key, btn);
497-
} else if (isRepeatableKey(key)) {
497+
return;
498+
}
499+
if (key.action.kind === "char") {
498500
this.#showSimplePreview(key, btn, e.pointerId);
501+
}
502+
if (isRepeatableKey(key)) {
499503
this.#startRepeat(key, e.pointerId);
500504
} else {
501-
this.#showSimplePreview(key, btn, e.pointerId);
502505
this.#handle(key);
503506
}
504507
}
@@ -750,6 +753,11 @@ export class VirtualKeyboard extends HTMLElement {
750753

751754
#positionPopover(popover: HTMLElement, anchor: HTMLButtonElement): void {
752755
const anchorRect = anchor.getBoundingClientRect();
756+
if (popover.classList.contains("preview")) {
757+
popover.style.width = `${anchorRect.width}px`;
758+
} else {
759+
popover.style.width = "";
760+
}
753761

754762
const margin = 4;
755763
const vw = document.documentElement.clientWidth;

src/keyboard/virtual-keyboard.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
position: fixed;
131131
z-index: 10;
132132
display: flex;
133+
justify-content: center;
133134
gap: 4px;
134135
padding: 6px;
135136
background: var(--vk-key-bg);
@@ -138,7 +139,9 @@
138139
pointer-events: none;
139140

140141
&.preview {
141-
padding: 6px 10px;
142+
padding: 0;
143+
box-sizing: border-box;
144+
overflow: hidden;
142145
}
143146
}
144147

@@ -164,11 +167,11 @@
164167
}
165168

166169
.preview-key {
167-
display: inline-flex;
170+
display: flex;
168171
align-items: center;
169172
justify-content: center;
173+
width: 100%;
170174
height: var(--vk-key-height);
171-
padding: 0 14px;
172175
font-family: inherit;
173176
font-size: 28px;
174177
font-weight: 500;

0 commit comments

Comments
 (0)