• Robert Knight's avatar
    Install shortcut listener on document element · d9de7bde
    Robert Knight authored
    Listen for key events for keyboard shortcuts on the document element rather than
    body element, to make them work in XHTML documents.
    
    When no interactive element (eg. an input field) is focused in an HTML document,
    keyboard events are sent to the body element. In an XHTML document however
    keyboard events are sent to the document element instead in Safari and Chrome
    (in Firefox they are still sent to the body). The key event listeners used for
    the adder's shortcuts were installed on the body element, so they didn't work in
    XHTML documents in Safari and Chrome.
    
    My guess is that the reason for this behavioral quirk is that HTML documents are
    guaranteed to have a body element - an empty one will be generated if none
    is present in the markup, whereas XHTML documents are not.
    
    Fixes https://github.com/hypothesis/client/issues/4364
    d9de7bde
shortcut-test.js 5.4 KB