Skip to content

Commit

Permalink
fix(form): address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
DukeFerdinand committed Feb 11, 2025
1 parent 5289f2b commit 7740c71
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/form/src/auro-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@ export class AuroForm extends LitElement {
this._attachEventListeners();
}

/**
* Slot change event listener. This is the main entry point for the form element.
* @param {Event} event - The slot change event.
* @returns {void}
*/
onSlotChange(event) {
this.initializeState();
// Safe to call as we remove and re-add event listeners
Expand Down
30 changes: 30 additions & 0 deletions components/form/test/auro-form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,36 @@ describe('auro-form', () => {
});
});

describe('when elements are removed from the DOM after initial render', () => {
it('should update internal state and formState when an element is removed', async () => {
const el = await fixture(html`
<auro-form>
</auro-form>
`);

// Create the input element
const inputEl = document.createElement('auro-input');

inputEl.setAttribute('name', 'testInput');
inputEl.setAttribute('required', '');
el.appendChild(inputEl);

await elementUpdated(el);

// Validate the element is added
await expect(el._elements).to.have.length(1);
await expect(el.formState).to.have.keys('testInput');

// Remove the element
el.removeChild(inputEl);
await elementUpdated(el);

// Validate that the element removal is reflected correctly in the state
await expect(el._elements).to.have.length(0);
await expect(el.formState).to.not.have.keys('testInput');
});
});

describe('when auro-buttons are present', () => {
it('picks up type=submit buttons automatically', async () => {
const el = await fixture(html`
Expand Down

0 comments on commit 7740c71

Please sign in to comment.