Skip to content

Commit ccc4e48

Browse files
committed
Revert "Add haptic feedback on key press"
This reverts commit 135928b.
1 parent 80b0581 commit ccc4e48

1 file changed

Lines changed: 3 additions & 47 deletions

File tree

src/keyboard/virtual-keyboard.ts

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ export class VirtualKeyboard extends HTMLElement {
9393
"long-press-ms",
9494
"repeat-initial-ms",
9595
"repeat-interval-ms",
96-
"haptic",
9796
];
9897

9998
#state: State = {
@@ -112,8 +111,6 @@ export class VirtualKeyboard extends HTMLElement {
112111
#longPressMs = DEFAULT_LONG_PRESS_MS;
113112
#repeatInitialMs = DEFAULT_REPEAT_INITIAL_MS;
114113
#repeatIntervalMs = DEFAULT_REPEAT_INTERVAL_MS;
115-
#hapticEnabled = true;
116-
#hapticSwitch: HTMLLabelElement | null = null;
117114

118115
constructor() {
119116
super();
@@ -142,10 +139,6 @@ export class VirtualKeyboard extends HTMLElement {
142139
if (this.isConnected) this.#render();
143140
return;
144141
}
145-
if (name === "haptic") {
146-
this.#hapticEnabled = value !== "off" && value !== "false";
147-
return;
148-
}
149142
const parsed = value === null ? NaN : Number(value);
150143
const ms = Number.isFinite(parsed) && parsed > 0 ? parsed : null;
151144
switch (name) {
@@ -192,21 +185,14 @@ export class VirtualKeyboard extends HTMLElement {
192185

193186
this.#controller = new AbortController();
194187
const { signal } = this.#controller;
195-
this.#setupHaptics();
196-
const onHostPointerDown = (e: Event): void => {
197-
const target = e.target as HTMLElement | null;
198-
if (target?.closest(".key, .tb-key")) this.#haptic();
199-
if (target?.closest(".topbar")) return;
200-
e.preventDefault();
201-
};
202-
const swallowFocus = (e: Event): void => {
188+
const swallowFocusUnlessTopbar = (e: Event): void => {
203189
const target = e.target as HTMLElement | null;
204190
if (target?.closest(".topbar")) return;
205191
e.preventDefault();
206192
};
207193
const host = this.#root.querySelector(".vk");
208-
host?.addEventListener("pointerdown", onHostPointerDown, { signal });
209-
host?.addEventListener("mousedown", swallowFocus, { signal });
194+
host?.addEventListener("pointerdown", swallowFocusUnlessTopbar, { signal });
195+
host?.addEventListener("mousedown", swallowFocusUnlessTopbar, { signal });
210196
this.#renderTopbar();
211197
this.#attachDragScroll(this.#root.querySelector(".topbar") as HTMLElement);
212198
this.#render();
@@ -216,36 +202,6 @@ export class VirtualKeyboard extends HTMLElement {
216202
this.#controller?.abort();
217203
this.#controller = null;
218204
this.#cancelPress();
219-
this.#hapticSwitch?.remove();
220-
this.#hapticSwitch = null;
221-
}
222-
223-
#setupHaptics(): void {
224-
if ("vibrate" in navigator) return;
225-
const input = document.createElement("input");
226-
input.type = "checkbox";
227-
input.setAttribute("switch", "");
228-
input.tabIndex = -1;
229-
const label = document.createElement("label");
230-
label.setAttribute("aria-hidden", "true");
231-
label.style.cssText =
232-
"position:absolute;left:-9999px;width:1px;height:1px;pointer-events:none;opacity:0;";
233-
label.appendChild(input);
234-
this.#root.appendChild(label);
235-
this.#hapticSwitch = label;
236-
}
237-
238-
#haptic(): void {
239-
if (!this.#hapticEnabled) return;
240-
try {
241-
if ("vibrate" in navigator) {
242-
navigator.vibrate(8);
243-
return;
244-
}
245-
this.#hapticSwitch?.click();
246-
} catch {
247-
// haptics are a best-effort affordance; any failure is silent.
248-
}
249205
}
250206

251207
#renderTopbar(): void {

0 commit comments

Comments
 (0)