@muonic/muon 0.0.2-experimental-131-9e6a9a4.0 → 0.0.2-experimental-134-086fb68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,12 +47,14 @@ export class Form extends MuonElement {
47
47
  this._nativeForm?.addEventListener('submit', this._submit);
48
48
  this._submitButton?.addEventListener('click', this._submit);
49
49
  this._nativeForm?.addEventListener('reset', this._reset);
50
+ this._resetButton?.addEventListener('click', this._reset);
50
51
  }
51
52
 
52
53
  __teardownEvents() {
53
54
  this._nativeForm?.removeEventListener('submit', this._submit);
54
55
  this._submitButton?.removeEventListener('click', this._submit);
55
56
  this._nativeForm?.removeEventListener('reset', this._reset);
57
+ this._resetButton?.removeEventListener('click', this._reset);
56
58
  }
57
59
 
58
60
  __checkForFormEl() {
@@ -71,6 +73,12 @@ export class Form extends MuonElement {
71
73
  !this._resetButton.loading
72
74
  ) {
73
75
  this._nativeForm.reset();
76
+ Array.from(this._nativeForm.elements).forEach((element) => {
77
+ const componentElement = this._findInputElement(element);
78
+ if (componentElement !== element) {
79
+ componentElement.reset?.();
80
+ }
81
+ });
74
82
  }
75
83
  }
76
84
 
@@ -17,12 +17,15 @@ export default {
17
17
 
18
18
  const innerDetail = (args) => staticHTML`
19
19
  <form>
20
+ ${InputterStories.Select(args.Title)}
20
21
  ${InputterStories.Text(args.Text)}
21
22
  ${InputterStories.Email(args.Email)}
22
23
 
23
- <label for="user-id">User ID<label>
24
+ <label for="user-id">User ID</label>
24
25
  <input type="text" id="user-id" name="user-id" required/>
25
26
 
27
+ ${InputterStories.DateMask(args.DOB)}
28
+
26
29
  ${InputterStories.Checkbox(args.Checkbox)}
27
30
 
28
31
  <input type="reset" />
@@ -31,10 +34,16 @@ const innerDetail = (args) => staticHTML`
31
34
 
32
35
  export const Standard = (args) => details.template(args, innerDetail);
33
36
  Standard.args = {
37
+ Title: {
38
+ ...InputterStories.Select.args,
39
+ name: 'title',
40
+ label: 'Title'
41
+ },
34
42
  Text: {
35
43
  ...InputterStories.Text.args,
36
44
  name: 'username',
37
- label: 'Name'
45
+ label: 'Name',
46
+ value: 'text'
38
47
  },
39
48
  Email: {
40
49
  ...InputterStories.Email.args,
@@ -48,6 +57,12 @@ Standard.args = {
48
57
  { label: 'Option B', value: 'b' }
49
58
  ]
50
59
  },
60
+ DOB: {
61
+ ...InputterStories.DateMask.args,
62
+ name: 'dob',
63
+ label: 'Date of birth',
64
+ validation: ['maxDate(\'031/12/2022\')']
65
+ },
51
66
  Submit: {
52
67
  ...SubmitCTA.args,
53
68
  type: 'submit',
@@ -223,7 +223,7 @@ Radio.args = {
223
223
  const selectTemplate = (args) => staticHTML`
224
224
  <label slot="label">${args.label}</label>
225
225
  <select name="${args.name}">
226
- ${args.options?.map((option) => staticHTML`<option value="${option.value}">${option.label}</option>`)}
226
+ ${args.options?.map((option) => staticHTML`<option value="${option.value}" ${unsafeStatic(option.states?.join(' ') ?? '')}>${option.label}</option>`)}
227
227
  </select>
228
228
  `;
229
229
 
@@ -236,7 +236,7 @@ Select.args = {
236
236
  options: [
237
237
  { label: 'Please select', value: '' },
238
238
  { label: 'Value one', value: 'value-01' },
239
- { label: 'Value two', value: 'value-02' },
239
+ { label: 'Value two', value: 'value-02', states: ['selected'] },
240
240
  { label: 'Value three', value: 'value-03' },
241
241
  { label: 'Value four', value: 'value-04' }
242
242
  ]
@@ -138,6 +138,9 @@ export const FormElementMixin = dedupeMixin((superClass) =>
138
138
  });
139
139
  }
140
140
 
141
+ reset() {
142
+ this.value = this._slottedValue; // get values from slotted html form elements
143
+ }
141
144
  /**
142
145
  * A method to sync the value property of the component with value of slotted input elements.
143
146
  *
@@ -204,7 +207,7 @@ export const FormElementMixin = dedupeMixin((superClass) =>
204
207
  }
205
208
 
206
209
  /**
207
- * A method to get slotted element value.
210
+ * A method to get slotted element value.
208
211
  *
209
212
  * @protected
210
213
  * @override
@@ -76,6 +76,12 @@ export const ValidationMixin = dedupeMixin((superClass) =>
76
76
  return this.validate();
77
77
  }
78
78
 
79
+ reset() {
80
+ super.reset();
81
+ this._pristine = true;
82
+ this._validationState = [];
83
+ }
84
+
79
85
  /**
80
86
  * A method to validate the value of the form element.
81
87
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muonic/muon",
3
- "version": "0.0.2-experimental-131-9e6a9a4.0",
3
+ "version": "0.0.2-experimental-134-086fb68.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -107,3 +107,9 @@ snapshots["form form submitting with inputter [validate]"] =
107
107
  `;
108
108
  /* end snapshot form form submitting with inputter [validate] */
109
109
 
110
+ snapshots["form form cta reset with inputter"] =
111
+ `<slot>
112
+ </slot>
113
+ `;
114
+ /* end snapshot form form cta reset with inputter */
115
+
@@ -305,6 +305,32 @@ describe('form', () => {
305
305
 
306
306
  resetBtn.click();
307
307
 
308
- expect(input.value).to.equal('', 'no reset input value');
308
+ expect(input.value).to.equal('foo', 'no reset input value');
309
+ });
310
+
311
+ it('form cta reset with inputter', async () => {
312
+ const submitSpy = sinon.spy();
313
+ const el = await fixture(html`
314
+ <${tag} @submit=${submitSpy}>
315
+ <form>
316
+ <${inputterTag} validation='["isRequired"]' value='test'>
317
+ <label slot="label" for="foo">Bar</label>
318
+ <input id="foo" type="text" />
319
+ </${inputterTag}>
320
+ <${ctaTag} type="reset">Reset</${ctaTag}>
321
+ </form>
322
+ </${tag}>
323
+ `);
324
+ const input = el.querySelector(inputterTagName);
325
+ const resetBtn = el.querySelector(ctaTagName);
326
+
327
+ await defaultChecks(el);
328
+ expect(input.value).to.equal('test', 'default input value');
329
+
330
+ input.value = '';
331
+ expect(input.value).to.equal('', 'changed input value');
332
+
333
+ resetBtn.click();
334
+ expect(input.value).to.equal('test', 'no reset input value');
309
335
  });
310
336
  });