Skip to content

Commit ec7c394

Browse files
lideencalebdwilliams
authored andcommitted
fix(findParentForm): fixed inconsistency with how Chrome finds forms outside of closed custom elements
1 parent 658b085 commit ec7c394

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Diff for: src/utils.ts

-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ export const findParentForm = (elem) => {
242242
let parent = elem.parentNode;
243243
if (parent && parent.tagName !== 'FORM') {
244244
parent = findParentForm(parent);
245-
} else if (!parent && elem.toString() === '[object ShadowRoot]') {
246-
parent = findParentForm(elem.host);
247245
}
248246
return parent;
249247
};

Diff for: test/ElementInternals.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,24 @@ describe('The ElementInternals polyfill', () => {
531531
expect(submitCount).to.equal(1);
532532
});
533533
});
534+
535+
describe('forms outside closed custom elements', () => {
536+
it('will not find forms outside of closed custom element', async () => {
537+
class ClosedElementWithCustomFormElement extends HTMLElement {
538+
constructor() {
539+
super();
540+
this.renderRoot = this.attachShadow({ mode: 'closed' });
541+
this.renderRoot.innerHTML = `<test-el name="foo" id="foo"></test-el>`;
542+
}
543+
}
544+
customElements.define('closed-element-with-custom-form-element', ClosedElementWithCustomFormElement);
545+
546+
const form = await fixture(html`<form>
547+
<closed-element-with-custom-form-element></closed-element-with-custom-form-element>
548+
</form>`);
549+
const shadowElement = form.querySelector('closed-element-with-custom-form-element');
550+
const testEl = shadowElement.renderRoot.querySelector("test-el")
551+
expect(testEl.internals.form).to.be.null;
552+
});
553+
});
534554
});

0 commit comments

Comments
 (0)