Skip to content

Commit

Permalink
Fix pressing 2 buttons in the same moment
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Apr 2, 2024
1 parent d8a7c5f commit dab3a72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions press.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function pressKeyUX(pressedClass) {

function click(event) {
if (event.clientX === 0 && event.clientY === 0) {
keyUp()
event.target.classList.add(...classes)
pressedElement = event.target
}
Expand Down
28 changes: 28 additions & 0 deletions test/press.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,31 @@ test('stops event tracking', () => {
equal(button.classList.contains('is-pressed'), false)
equal(button.classList.contains('is-hover'), false)
})

test('is ready to pressing 2 buttons', () => {
let window = new JSDOM().window
startKeyUX(window, [pressKeyUX('is-pressed'), hotkeyKeyUX()])

window.document.body.innerHTML =
'<button aria-keyshortcuts="a" class=""></button>' +
'<button aria-keyshortcuts="b" class=""></button>'

window.dispatchEvent(
new window.KeyboardEvent('keydown', { bubbles: true, key: 'b' })
)
window.dispatchEvent(
new window.KeyboardEvent('keydown', { bubbles: true, key: 'a' })
)
window.dispatchEvent(
new window.KeyboardEvent('keyup', { bubbles: true, key: 'a' })
)
window.dispatchEvent(
new window.KeyboardEvent('keyup', { bubbles: true, key: 'b' })
)

equal(
window.document.body.innerHTML,
'<button aria-keyshortcuts="a" class=""></button>' +
'<button aria-keyshortcuts="b" class=""></button>'
)
})

0 comments on commit dab3a72

Please sign in to comment.