trap.spec.js 914 B

123456789101112131415161718192021222324252627282930
  1. import { haveText, test, html, haveFocus } from '../../utils'
  2. test('can trap focus',
  3. [html`
  4. <div x-data="{ open: false }">
  5. <input type="text" id="1">
  6. <button id="2" @click="open = true">open</button>
  7. <div>
  8. <div x-trap="open">
  9. <input type="text" id="3">
  10. <button @click="open = false" id="4">close</button>
  11. </div>
  12. </div>
  13. </div>
  14. `],
  15. ({ get }, reload) => {
  16. get('#1').click()
  17. get('#1').should(haveFocus())
  18. get('#2').click()
  19. get('#3').should(haveFocus())
  20. cy.focused().tab()
  21. get('#4').should(haveFocus())
  22. cy.focused().tab()
  23. get('#3').should(haveFocus())
  24. cy.focused().tab({shift: true})
  25. get('#4').should(haveFocus())
  26. cy.focused().click()
  27. get('#2').should(haveFocus())
  28. },
  29. )