Skip to content

Commit 8346b2f

Browse files
authored
fix: anchor element focus order on form submission reversed compared to Chrome (#24)
1 parent dbb3c1a commit 8346b2f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: src/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const formSubmitCallback = (event: Event) => {
102102
const nodes = Array.from(elements);
103103
/** Check the internals.checkValidity() of all nodes */
104104
const validityList = nodes
105+
.reverse()
105106
.map(node => {
106107
const internals = internalsMap.get(node);
107108
return internals.reportValidity();

Diff for: test/ElementInternals.test.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ describe('The ElementInternals polyfill', () => {
352352

353353
it('saves a reference to all shadow roots', () => {
354354
expect(internals.shadowRoot).to.equal(el.shadowRoot);
355-
});;
355+
});
356356

357357
it('will focus the element if validated with anchor', async () => {
358358
internals.setValidity({
@@ -362,6 +362,17 @@ describe('The ElementInternals polyfill', () => {
362362
expect(document.activeElement).to.equal(el);
363363
});
364364

365+
it('will focus anchor elements in document order on form submission failure', () => {
366+
internals.setValidity({
367+
customError: true
368+
}, 'Error message', el.input);
369+
noname.internals.setValidity({
370+
customError: true
371+
}, 'Error message', noname.input);
372+
button.click();
373+
expect(document.activeElement).to.equal(el);
374+
});
375+
365376
it('will accept non strings', async () => {
366377
internals.setFormValue(['a', 'b']);
367378
expect(

0 commit comments

Comments
 (0)