fix(form-core): delay rejectRegistrationComplete 1 microtask
Co-authored-by: palash2601 <palash2601@gmail.com>
This commit is contained in:
parent
91f56769fe
commit
0c711f6962
4 changed files with 154 additions and 2 deletions
126
docs/docs/systems/overlays/assets/umbrella-form.js
Normal file
126
docs/docs/systems/overlays/assets/umbrella-form.js
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
import { LitElement, html } from '@lion/core';
|
||||
import { Required, MinLength } from '@lion/form-core';
|
||||
import '@lion/form/define';
|
||||
import '@lion/fieldset/define';
|
||||
import '@lion/input/define';
|
||||
import '@lion/input-date/define';
|
||||
import '@lion/input-datepicker/define';
|
||||
import '@lion/input-amount/define';
|
||||
import '@lion/input-iban/define';
|
||||
import '@lion/input-email/define';
|
||||
import '@lion/checkbox-group/define';
|
||||
import '@lion/radio-group/define';
|
||||
import '@lion/select/define';
|
||||
import '@lion/select-rich/define';
|
||||
import '@lion/input-range/define';
|
||||
import '@lion/textarea/define';
|
||||
import '@lion/button/define';
|
||||
|
||||
export class UmbrellaForm extends LitElement {
|
||||
get _lionFormNode() {
|
||||
return /** @type {import('@lion/form').LionForm} */ (this.shadowRoot?.querySelector(
|
||||
'lion-form',
|
||||
));
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`
|
||||
<lion-form>
|
||||
<form>
|
||||
<lion-fieldset name="full_name">
|
||||
<lion-input
|
||||
name="first_name"
|
||||
label="First Name"
|
||||
.validators="${[new Required()]}"
|
||||
></lion-input>
|
||||
<lion-input
|
||||
name="last_name"
|
||||
label="Last Name"
|
||||
.validators="${[new Required()]}"
|
||||
></lion-input>
|
||||
</lion-fieldset>
|
||||
<lion-input-date
|
||||
name="date"
|
||||
label="Date of application"
|
||||
.modelValue="${new Date('2000/12/12')}"
|
||||
.validators="${[new Required()]}"
|
||||
></lion-input-date>
|
||||
<lion-input-datepicker
|
||||
name="datepicker"
|
||||
label="Date to be picked"
|
||||
.modelValue="${new Date('2020/12/12')}"
|
||||
.validators="${[new Required()]}"
|
||||
></lion-input-datepicker>
|
||||
<lion-textarea
|
||||
name="bio"
|
||||
label="Biography"
|
||||
.validators="${[new Required(), new MinLength(10)]}"
|
||||
help-text="Please enter at least 10 characters"
|
||||
></lion-textarea>
|
||||
<lion-input-amount name="money" label="Money"></lion-input-amount>
|
||||
<lion-input-iban name="iban" label="Iban"></lion-input-iban>
|
||||
<lion-input-email name="email" label="Email"></lion-input-email>
|
||||
<lion-checkbox-group
|
||||
label="What do you like?"
|
||||
name="checkers"
|
||||
.validators="${[new Required()]}"
|
||||
>
|
||||
<lion-checkbox .choiceValue=${'foo'} checked label="I like foo"></lion-checkbox>
|
||||
<lion-checkbox .choiceValue=${'bar'} checked label="I like bar"></lion-checkbox>
|
||||
<lion-checkbox .choiceValue=${'baz'} label="I like baz"></lion-checkbox>
|
||||
</lion-checkbox-group>
|
||||
<lion-radio-group
|
||||
name="dinosaurs"
|
||||
label="Favorite dinosaur"
|
||||
.validators="${[new Required()]}"
|
||||
>
|
||||
<lion-radio .choiceValue=${'allosaurus'} label="allosaurus"></lion-radio>
|
||||
<lion-radio .choiceValue=${'brontosaurus'} checked label="brontosaurus"></lion-radio>
|
||||
<lion-radio .choiceValue=${'diplodocus'} label="diplodocus"></lion-radio>
|
||||
</lion-radio-group>
|
||||
<lion-select-rich name="favoriteColor" label="Favorite color">
|
||||
<lion-options slot="input">
|
||||
<lion-option .choiceValue=${'red'}>Red</lion-option>
|
||||
<lion-option .choiceValue=${'hotpink'} checked>Hotpink</lion-option>
|
||||
<lion-option .choiceValue=${'teal'}>Teal</lion-option>
|
||||
</lion-options>
|
||||
</lion-select-rich>
|
||||
<lion-select label="Lyrics" name="lyrics" .validators="${[new Required()]}">
|
||||
<select slot="input">
|
||||
<option value="1">Fire up that loud</option>
|
||||
<option value="2">Another round of shots...</option>
|
||||
<option value="3">Drop down for what?</option>
|
||||
</select>
|
||||
</lion-select>
|
||||
<lion-input-range
|
||||
name="range"
|
||||
min="1"
|
||||
max="5"
|
||||
.modelValue="${2.3}"
|
||||
unit="%"
|
||||
step="0.1"
|
||||
label="Input range"
|
||||
>
|
||||
</lion-input-range>
|
||||
<lion-checkbox-group name="terms" .validators="${[new Required()]}">
|
||||
<lion-checkbox label="I blindly accept all terms and conditions"></lion-checkbox>
|
||||
</lion-checkbox-group>
|
||||
<lion-textarea name="comments" label="Comments"></lion-textarea>
|
||||
<div class="buttons">
|
||||
<lion-button raised>Submit</lion-button>
|
||||
<lion-button
|
||||
type="button"
|
||||
raised
|
||||
@click=${() => {
|
||||
const lionForm = this._lionFormNode;
|
||||
lionForm.resetGroup();
|
||||
}}
|
||||
>Reset</lion-button
|
||||
>
|
||||
</div>
|
||||
</form>
|
||||
</lion-form>
|
||||
`;
|
||||
}
|
||||
}
|
||||
customElements.define('umbrella-form', UmbrellaForm);
|
||||
|
|
@ -181,7 +181,11 @@ const ChoiceGroupMixinImplementation = superclass =>
|
|||
super.disconnectedCallback();
|
||||
|
||||
if (this.registrationComplete.done === false) {
|
||||
this.__rejectRegistrationComplete();
|
||||
Promise.resolve().then(() => {
|
||||
Promise.resolve().then(() => {
|
||||
this.__rejectRegistrationComplete();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -184,7 +184,9 @@ const FormGroupMixinImplementation = superclass =>
|
|||
this.__hasActiveOutsideClickHandling = false;
|
||||
}
|
||||
if (this.registrationComplete.done === false) {
|
||||
this.__rejectRegistrationComplete();
|
||||
Promise.resolve().then(() => {
|
||||
this.__rejectRegistrationComplete();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
20
packages/form-integrations/test/dialog-integrations.js
Normal file
20
packages/form-integrations/test/dialog-integrations.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { expect, fixture, html } from '@open-wc/testing';
|
||||
import './helpers/umbrella-form.js';
|
||||
import '@lion/dialog/lion-dialog.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('./helpers/umbrella-form.js').UmbrellaForm} UmbrellaForm
|
||||
* @typedef {import('@lion/dialog/').LionDialog} LionDialog
|
||||
*/
|
||||
|
||||
// Test umbrella form inside dialog
|
||||
describe('Form inside dialog Integrations', () => {
|
||||
it('"Successfully spawns all form components inside a dialog', async () => {
|
||||
expect(
|
||||
await fixture(html` <lion-dialog>
|
||||
<button slot="invoker">Open Dialog</button>
|
||||
<umbrella-form slot="content"></umbrella-form>
|
||||
</lion-dialog>`),
|
||||
).to.not.throw();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue