trap.spec.js 787 B

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