fix(shortcuts): resolve keyboard accessibility and contenteditable issues

This commit is contained in:
yiling
2026-07-16 10:23:47 +08:00
parent 490c6a3da6
commit ecfbfc2bac
4 changed files with 50 additions and 11 deletions
@@ -156,12 +156,28 @@ export function CompareViewer({
activeEl &&
(activeEl.tagName === 'INPUT' ||
activeEl.tagName === 'TEXTAREA' ||
activeEl.hasAttribute('contenteditable') ||
activeEl.getAttribute('contenteditable') === 'true')
(activeEl instanceof HTMLElement && activeEl.isContentEditable))
) {
return
}
const isSpace = e.key === ' '
const isInteractive =
activeEl &&
(activeEl.tagName === 'BUTTON' ||
activeEl.tagName === 'A' ||
activeEl.tagName === 'SELECT' ||
activeEl.tagName === 'OPTION' ||
activeEl.getAttribute('role') === 'button' ||
activeEl.getAttribute('role') === 'link' ||
activeEl.getAttribute('role') === 'checkbox' ||
activeEl.getAttribute('role') === 'radio' ||
activeEl.getAttribute('role') === 'menuitem')
if (isSpace && isInteractive) {
return
}
if (e.key === ' ' || e.key.toLowerCase() === 'k') {
e.preventDefault()
handleTogglePlay()