-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
autofocus
and x-autofocus
support
- Loading branch information
Showing
3 changed files
with
74 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,71 @@ | ||
import { test, html } from './utils' | ||
|
||
test('focus is set with [x-focus] string', | ||
html`<form x-init x-target id="replace" method="post" x-focus="toggle_button"><button aria-pressed="false">Like</button></form>`, | ||
test('focus is maintained when merged content is morphed', | ||
html`<form x-init x-target id="replace" method="post" x-merge="morph"><button aria-pressed="false">Like</button></form>`, | ||
({ intercept, get, wait }) => { | ||
intercept('POST', '/tests', { | ||
statusCode: 200, | ||
body: '<form x-target id="replace" method="post"><button id="toggle_button" aria-pressed="true">Unlike</button></form>' | ||
body: '<form x-target id="replace" method="post"><button aria-pressed="true">Unlike</button></form>' | ||
}).as('response') | ||
get('button').focus().click() | ||
wait('@response').then(() => { | ||
get('button').should('have.focus') | ||
}) | ||
} | ||
) | ||
|
||
test('focus is set with [autofocus]', | ||
html`<form x-init x-target id="replace" method="post"><button>First</button><a href="#">Second</a></form>`, | ||
({ intercept, get, wait }) => { | ||
intercept('POST', '/tests', { | ||
statusCode: 200, | ||
body: '<form x-init x-target id="replace" method="post"><button>First</button><a href="#" autofocus>Second</a></form>' | ||
}).as('response') | ||
get('button').focus().click() | ||
wait('@response').then(() => { | ||
get('a').should('have.focus') | ||
}) | ||
} | ||
) | ||
|
||
test('focus is ignored with the nofocus modifier', | ||
html`<form x-init x-target.nofocus id="replace" method="post"><button>First</button><a href="#">Second</a></form>`, | ||
({ intercept, get, wait }) => { | ||
intercept('POST', '/tests', { | ||
statusCode: 200, | ||
body: '<form x-init x-target id="replace" method="post"><button>First</button><a href="#" autofocus>Second</a></form>' | ||
}).as('response') | ||
get('button').focus().click() | ||
wait('@response').then(() => { | ||
get('a').should('not.have.focus') | ||
}) | ||
} | ||
) | ||
|
||
test('first listed target is focused when multiple [autofocus] are merged', | ||
html`<a href="#" autofocus id="replace2">Second</a><a href="#" autofocus id="replace1">First</a><form x-init x-target="replace1 replace2" method="post"><button></button></form>`, | ||
({ intercept, get, wait }) => { | ||
intercept('POST', '/tests', { | ||
statusCode: 200, | ||
body: '<a href="#" autofocus id="replace2">Second Replaced</a><a href="#" autofocus id="replace1">First Replaced</a>' | ||
}).as('response') | ||
get('button').click() | ||
wait('@response').then(() => { | ||
get('#replace1').should('have.focus') | ||
}) | ||
} | ||
) | ||
|
||
test('[x-autofocus] overrides [autofocus]', | ||
html`<form x-init x-target id="replace" method="post"><button>First</button><a href="#">Second</a></form>`, | ||
({ intercept, get, wait }) => { | ||
intercept('POST', '/tests', { | ||
statusCode: 200, | ||
body: '<form x-init x-target id="replace" method="post"><button autofocus>First</button><a href="#" x-autofocus>Second</a></form>' | ||
}).as('response') | ||
get('button').focus().click() | ||
wait('@response').then(() => { | ||
get('a').should('have.focus') | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters