This also needs to be read whenever the input has focus
Same for this
`);
- const el = wrapper.querySelector(`${tagString}`);
+ const el = wrapper.querySelector(tagString);
// wait until the field element is done rendering
await el.updateComplete;
+ await el.updateComplete;
const { inputElement } = el;
- const get = by => inputElement.getAttribute(`aria-${by}`);
// 1. addToAriaLabel()
// Check if the aria attr is filled initially
- expect(get('labelledby')).to.contain(`label-${el._inputId}`);
+ expect(inputElement.getAttribute('aria-labelledby')).to.contain(`label-${el._inputId}`);
el.addToAriaLabel('additionalLabel');
// Now check if ids are added to the end (not overridden)
- expect(get('labelledby')).to.contain(`label-${el._inputId}`);
+ expect(inputElement.getAttribute('aria-labelledby')).to.contain(`label-${el._inputId}`);
// Should be placed in the end
expect(
- get('labelledby').indexOf(`label-${el._inputId}`) <
- get('labelledby').indexOf('additionalLabel'),
+ inputElement.getAttribute('aria-labelledby').indexOf(`label-${el._inputId}`) <
+ inputElement.getAttribute('aria-labelledby').indexOf('additionalLabel'),
);
// 2. addToAriaDescription()
// Check if the aria attr is filled initially
- expect(get('describedby')).to.contain(`feedback-${el._inputId}`);
+ expect(inputElement.getAttribute('aria-describedby')).to.contain(`feedback-${el._inputId}`);
el.addToAriaDescription('additionalDescription');
// Now check if ids are added to the end (not overridden)
- expect(get('describedby')).to.contain(`feedback-${el._inputId}`);
+ expect(inputElement.getAttribute('aria-describedby')).to.contain(`feedback-${el._inputId}`);
// Should be placed in the end
expect(
- get('describedby').indexOf(`feedback-${el._inputId}`) <
- get('describedby').indexOf('additionalDescription'),
+ inputElement.getAttribute('aria-describedby').indexOf(`feedback-${el._inputId}`) <
+ inputElement.getAttribute('aria-describedby').indexOf('additionalDescription'),
);
});
});
@@ -285,7 +281,7 @@ describe('', () => {
function hasX(str) {
return { hasX: str.indexOf('x') > -1 };
}
- const el = await fixture(`<${tagString}>${inputSlotString}${tagString}>`);
+ const el = await fixture(html`<${tag}>${inputSlot}${tag}>`);
const feedbackEl = el._feedbackElement;
el.modelValue = 'a@b.nl';
@@ -355,17 +351,17 @@ describe('', () => {
describe(`Content projection${nameSuffix}`, () => {
it('renders correctly all slot elements in light DOM', async () => {
- const el = await fixture(`
- <${tagString}>
+ const el = await fixture(html`
+ <${tag}>
- ${inputSlotString}
+ ${inputSlot}
[help-text][before][after][prefix][suffix][feedback]
- ${tagString}>
+ ${tag}>
`);
const names = [
@@ -388,9 +384,9 @@ describe('', () => {
});
});
- describe(`Delegation${nameSuffix}`, () => {
+ describe('Delegation', () => {
it('delegates property value', async () => {
- const el = await fixture(`<${tagString}>${inputSlotString}${tagString}>`);
+ const el = await fixture(html`<${tag}>${inputSlot}${tag}>`);
expect(el.inputElement.value).to.equal('');
el.value = 'one';
expect(el.value).to.equal('one');
diff --git a/packages/fieldset/src/LionFieldset.js b/packages/fieldset/src/LionFieldset.js
index c958f11f8..531a092b5 100644
--- a/packages/fieldset/src/LionFieldset.js
+++ b/packages/fieldset/src/LionFieldset.js
@@ -11,7 +11,7 @@ const pascalCase = str => str.charAt(0).toUpperCase() + str.slice(1);
/**
* LionFieldset: fieldset wrapper providing extra features and integration with lion-field elements.
*
- * @customElement
+ * @customElement lion-fieldset
* @extends LionLitElement
*/
export class LionFieldset extends FormRegistrarMixin(
@@ -176,7 +176,14 @@ export class LionFieldset extends FormRegistrarMixin(
}
resetGroup() {
- this.modelValue = this.resetModelValue;
+ this.formElementsArray.forEach(child => {
+ if (typeof child.resetGroup === 'function') {
+ child.resetGroup();
+ } else if (typeof child.reset === 'function') {
+ child.reset();
+ }
+ });
+
this.resetInteractionState();
}
@@ -245,7 +252,7 @@ export class LionFieldset extends FormRegistrarMixin(
}
/**
- * Get's triggered by event 'validatin-done' which enabled us to handle 2 different situations
+ * Gets triggered by event 'validation-done' which enabled us to handle 2 different situations
* - react on modelValue change, which says something about the validity as a whole
* (at least two checkboxes for instance) and nothing about the children's values
* - children validatity states have changed, so fieldset needs to update itself based on that
@@ -348,23 +355,16 @@ export class LionFieldset extends FormRegistrarMixin(
}
/**
- * Updates the resetModelValue of this fieldset and asks it's parent fieldset/group to also
- * update.
- * This is needed as the upgrade order is not guaranteed. We have 3 main cases:
- * 1. if `street-name` gets updated last then `address` and `details` needs to update their
- * resetModelValue to also incorporate the correct value of `street-name`/`address`.
- * 2. If `address` get updated last then it already has the correct `street-name` so it
- * requests an update only for `details`.
- * 3. If `details` get updated last nothing happens here as all data are up to date
- *
- * @example
- *
- *
- *
+ * Gathers initial model values of all children. Used
+ * when resetGroup() is called.
*/
- _updateResetModelValue() {
- this.resetModelValue = this.modelValue;
- this._requestParentFormGroupUpdateOfResetModelValue();
+ get _initialModelValue() {
+ return this._getFromAllFormElements('_initialModelValue');
+ }
+
+ /** @deprecated */
+ get resetModelValue() {
+ return this._initialModelValue;
}
/**
diff --git a/packages/fieldset/test/lion-fieldset.test.js b/packages/fieldset/test/lion-fieldset.test.js
index ae9b25219..c5c436d6e 100644
--- a/packages/fieldset/test/lion-fieldset.test.js
+++ b/packages/fieldset/test/lion-fieldset.test.js
@@ -14,12 +14,14 @@ import '../lion-fieldset.js';
const tagString = 'lion-fieldset';
const tag = unsafeStatic(tagString);
-const inputSlotString = `
-
-
-
-
-
+const childTagString = 'lion-input';
+const childTag = unsafeStatic(childTagString);
+const inputSlots = html`
+ <${childTag} name="gender[]">${childTag}>
+ <${childTag} name="gender[]">${childTag}>
+ <${childTag} name="color">${childTag}>
+ <${childTag} name="hobbies[]">${childTag}>
+ <${childTag} name="hobbies[]">${childTag}>
`;
const nonPrefilledModelValue = '';
const prefilledModelValue = 'prefill';
@@ -30,7 +32,7 @@ beforeEach(() => {
describe('', () => {
it(`${tagString} has an up to date list of every form element in #formElements`, async () => {
- const fieldset = await fixture(`<${tagString}>${inputSlotString}${tagString}>`);
+ const fieldset = await fixture(html`<${tag}>${inputSlots}${tag}>`);
await nextFrame();
expect(Object.keys(fieldset.formElements).length).to.equal(3);
expect(fieldset.formElements['hobbies[]'].length).to.equal(2);
@@ -40,12 +42,12 @@ describe('', () => {
});
it(`supports in html wrapped form elements`, async () => {
- const el = await fixture(`
-
+ const el = await fixture(html`
+ <${tag}>