@lion/ui 0.11.1 → 0.11.3
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.
- package/README.md +2 -2
- package/components/combobox/src/LionCombobox.js +1 -3
- package/components/combobox/test/lion-combobox.test.js +126 -1
- package/components/localize/src/date/parseDate.js +6 -1
- package/components/localize/src/date/utils/checkYearFormat.js +8 -0
- package/components/localize/test/date/parseDate.test.js +6 -0
- package/custom-elements.json +33 -0
- package/dist-types/components/combobox/src/LionCombobox.d.ts.map +1 -1
- package/dist-types/components/localize/src/date/parseDate.d.ts.map +1 -1
- package/dist-types/components/localize/src/date/utils/checkYearFormat.d.ts +7 -0
- package/dist-types/components/localize/src/date/utils/checkYearFormat.d.ts.map +1 -0
- package/dist-types/tsconfig.tsbuildinfo +1 -1
- package/docs/components/accordion/api-table.md +13 -1
- package/docs/components/accordion/index.md +10 -0
- package/docs/components/accordion/overview.md +13 -1
- package/docs/components/accordion/reference.md +13 -1
- package/docs/components/accordion/use-cases.md +13 -1
- package/docs/components/button/api-table.md +13 -1
- package/docs/components/button/examples.md +13 -1
- package/docs/components/button/extensions.md +13 -1
- package/docs/components/button/index.md +11 -1
- package/docs/components/button/overview.md +13 -1
- package/docs/components/button/use-cases.md +13 -1
- package/docs/components/calendar/api-table.md +13 -1
- package/docs/components/calendar/index.md +11 -1
- package/docs/components/calendar/overview.md +13 -1
- package/docs/components/calendar/use-cases.md +13 -1
- package/docs/components/checkbox-group/api-table.md +13 -1
- package/docs/components/checkbox-group/index.md +11 -1
- package/docs/components/checkbox-group/overview.md +15 -3
- package/docs/components/checkbox-group/use-cases.md +13 -1
- package/docs/components/collapsible/api-table.md +13 -1
- package/docs/components/collapsible/examples.md +13 -1
- package/docs/components/collapsible/index.md +11 -1
- package/docs/components/collapsible/overview.md +14 -2
- package/docs/components/collapsible/use-cases.md +13 -1
- package/docs/components/combobox/api-table.md +13 -1
- package/docs/components/combobox/extensions.md +13 -1
- package/docs/components/combobox/index.md +11 -1
- package/docs/components/combobox/overview.md +14 -2
- package/docs/components/combobox/use-cases.md +14 -2
- package/docs/components/dialog/api-table.md +13 -1
- package/docs/components/dialog/index.md +11 -1
- package/docs/components/dialog/overview.md +14 -2
- package/docs/components/dialog/use-cases.md +13 -1
- package/docs/components/drawer/api-table.md +13 -1
- package/docs/components/drawer/index.md +11 -1
- package/docs/components/drawer/overview.md +13 -1
- package/docs/components/drawer/use-cases.md +13 -1
- package/docs/components/fieldset/api-table.md +13 -1
- package/docs/components/fieldset/index.md +11 -1
- package/docs/components/fieldset/overview.md +18 -6
- package/docs/components/fieldset/use-cases.md +13 -1
- package/docs/components/form/api-table.md +12 -1
- package/docs/components/form/index.md +11 -1
- package/docs/components/form/overview.md +16 -4
- package/docs/components/form/use-cases.md +15 -3
- package/docs/components/icon/api-table.md +13 -1
- package/docs/components/icon/index.md +11 -1
- package/docs/components/icon/overview.md +13 -1
- package/docs/components/icon/use-cases.md +14 -2
- package/docs/components/index.md +11 -1
- package/docs/components/input/api-table.md +13 -1
- package/docs/components/input/index.md +11 -1
- package/docs/components/input/overview.md +14 -2
- package/docs/components/input/use-cases.md +13 -1
- package/docs/components/input-amount/api-table.md +13 -1
- package/docs/components/input-amount/index.md +11 -1
- package/docs/components/input-amount/overview.md +16 -4
- package/docs/components/input-amount/use-cases.md +13 -1
- package/docs/components/input-date/api-table.md +13 -1
- package/docs/components/input-date/index.md +11 -1
- package/docs/components/input-date/overview.md +16 -4
- package/docs/components/input-date/use-cases.md +13 -1
- package/docs/components/input-datepicker/api-table.md +13 -1
- package/docs/components/input-datepicker/index.md +11 -1
- package/docs/components/input-datepicker/overview.md +18 -6
- package/docs/components/input-datepicker/use-cases.md +13 -1
- package/docs/components/input-email/api-table.md +13 -1
- package/docs/components/input-email/index.md +11 -1
- package/docs/components/input-email/overview.md +15 -3
- package/docs/components/input-email/use-cases.md +13 -1
- package/docs/components/input-file/api-table.md +13 -1
- package/docs/components/input-file/index.md +11 -1
- package/docs/components/input-file/overview.md +14 -2
- package/docs/components/input-file/use-cases.md +13 -1
- package/docs/components/input-iban/api-table.md +13 -1
- package/docs/components/input-iban/index.md +11 -1
- package/docs/components/input-iban/overview.md +15 -3
- package/docs/components/input-iban/use-cases.md +13 -1
- package/docs/components/input-range/api-table.md +13 -1
- package/docs/components/input-range/index.md +11 -1
- package/docs/components/input-range/overview.md +15 -3
- package/docs/components/input-range/use-cases.md +13 -1
- package/docs/components/input-stepper/api-table.md +13 -1
- package/docs/components/input-stepper/index.md +11 -1
- package/docs/components/input-stepper/overview.md +14 -2
- package/docs/components/input-stepper/use-cases.md +13 -1
- package/docs/components/input-tel/api-table.md +13 -1
- package/docs/components/input-tel/index.md +11 -1
- package/docs/components/input-tel/overview.md +14 -2
- package/docs/components/input-tel/use-cases.md +19 -7
- package/docs/components/input-tel-dropdown/api-table.md +13 -1
- package/docs/components/input-tel-dropdown/extensions.md +13 -1
- package/docs/components/input-tel-dropdown/index.md +11 -1
- package/docs/components/input-tel-dropdown/overview.md +14 -2
- package/docs/components/input-tel-dropdown/use-cases.md +13 -1
- package/docs/components/listbox/api-table.md +13 -1
- package/docs/components/listbox/index.md +11 -1
- package/docs/components/listbox/overview.md +13 -1
- package/docs/components/listbox/use-cases.md +14 -2
- package/docs/components/pagination/api-table.md +13 -1
- package/docs/components/pagination/index.md +11 -1
- package/docs/components/pagination/overview.md +13 -1
- package/docs/components/pagination/use-cases.md +13 -1
- package/docs/components/progress-indicator/api-table.md +13 -1
- package/docs/components/progress-indicator/examples.md +13 -1
- package/docs/components/progress-indicator/index.md +11 -1
- package/docs/components/progress-indicator/overview.md +13 -1
- package/docs/components/radio-group/api-table.md +13 -1
- package/docs/components/radio-group/index.md +11 -1
- package/docs/components/radio-group/overview.md +16 -4
- package/docs/components/radio-group/use-cases.md +13 -1
- package/docs/components/select/api-table.md +13 -1
- package/docs/components/select/index.md +11 -1
- package/docs/components/select/overview.md +13 -1
- package/docs/components/select/use-cases.md +14 -2
- package/docs/components/select-rich/api-table.md +13 -1
- package/docs/components/select-rich/examples.md +13 -1
- package/docs/components/select-rich/index.md +11 -1
- package/docs/components/select-rich/overview.md +13 -1
- package/docs/components/select-rich/use-cases.md +14 -2
- package/docs/components/steps/api-table.md +13 -1
- package/docs/components/steps/index.md +11 -1
- package/docs/components/steps/overview.md +13 -1
- package/docs/components/steps/use-cases.md +13 -1
- package/docs/components/switch/api-table.md +13 -1
- package/docs/components/switch/index.md +11 -1
- package/docs/components/switch/overview.md +13 -1
- package/docs/components/switch/reference.md +13 -1
- package/docs/components/switch/use-cases.md +13 -1
- package/docs/components/tabs/api-table.md +13 -1
- package/docs/components/tabs/examples.md +14 -2
- package/docs/components/tabs/index.md +11 -1
- package/docs/components/tabs/overview.md +13 -1
- package/docs/components/tabs/use-cases.md +13 -1
- package/docs/components/textarea/api-table.md +13 -1
- package/docs/components/textarea/index.md +11 -1
- package/docs/components/textarea/overview.md +13 -1
- package/docs/components/textarea/use-cases.md +13 -1
- package/docs/components/tooltip/api-table.md +13 -1
- package/docs/components/tooltip/examples.md +13 -1
- package/docs/components/tooltip/index.md +11 -1
- package/docs/components/tooltip/overview.md +13 -1
- package/docs/components/tooltip/use-cases.md +13 -1
- package/docs/fundamentals/index.md +4 -4
- package/docs/fundamentals/node-tools/babel-plugin-extend-docs/index.md +12 -0
- package/docs/fundamentals/node-tools/babel-plugin-extend-docs/overview.md +13 -0
- package/docs/fundamentals/node-tools/index.md +10 -0
- package/docs/fundamentals/node-tools/providence-analytics/index.md +12 -0
- package/docs/fundamentals/node-tools/providence-analytics/overview.md +13 -0
- package/docs/fundamentals/node-tools/publish-docs/index.md +12 -0
- package/docs/fundamentals/node-tools/publish-docs/overview.md +16 -3
- package/docs/fundamentals/node-tools/remark-extend/index.md +12 -0
- package/docs/fundamentals/node-tools/remark-extend/overview.md +13 -0
- package/docs/fundamentals/node-tools/rocket-preset-extend-lion-docs/index.md +12 -0
- package/docs/fundamentals/node-tools/rocket-preset-extend-lion-docs/overview.md +15 -2
- package/docs/fundamentals/rationales/TypeScript.md +12 -0
- package/docs/fundamentals/rationales/accessibility.md +13 -1
- package/docs/fundamentals/rationales/index.md +10 -0
- package/docs/fundamentals/rationales/side-effects.md +12 -0
- package/docs/fundamentals/rationales/versioning.md +12 -0
- package/docs/fundamentals/systems/core/SlotMixin.md +14 -1
- package/docs/fundamentals/systems/core/api-table.md +14 -1
- package/docs/fundamentals/systems/core/index.md +12 -0
- package/docs/fundamentals/systems/core/overview.md +14 -1
- package/docs/fundamentals/systems/form/api-table.md +14 -1
- package/docs/fundamentals/systems/form/formatting-and-parsing.md +17 -4
- package/docs/fundamentals/systems/form/index.md +12 -0
- package/docs/fundamentals/systems/form/interaction-states.md +13 -0
- package/docs/fundamentals/systems/form/model-value.md +14 -1
- package/docs/fundamentals/systems/form/overview.md +41 -28
- package/docs/fundamentals/systems/form/styling.md +13 -0
- package/docs/fundamentals/systems/form/use-cases.md +13 -0
- package/docs/fundamentals/systems/form/validate.md +15 -2
- package/docs/fundamentals/systems/icon/index.md +12 -0
- package/docs/fundamentals/systems/icon/overview.md +13 -0
- package/docs/fundamentals/systems/index.md +10 -0
- package/docs/fundamentals/systems/localize/api-table.md +14 -1
- package/docs/fundamentals/systems/localize/dates.md +13 -0
- package/docs/fundamentals/systems/localize/index.md +12 -0
- package/docs/fundamentals/systems/localize/numbers.md +13 -0
- package/docs/fundamentals/systems/localize/overview.md +17 -4
- package/docs/fundamentals/systems/localize/rationale.md +13 -0
- package/docs/fundamentals/systems/localize/text.md +13 -0
- package/docs/fundamentals/systems/localize/use-cases.md +13 -0
- package/docs/fundamentals/systems/overlays/_configuration-positioning.md +11 -0
- package/docs/fundamentals/systems/overlays/_edge-cases.md +10 -0
- package/docs/fundamentals/systems/overlays/api-table.md +14 -1
- package/docs/fundamentals/systems/overlays/configuration.md +15 -2
- package/docs/fundamentals/systems/overlays/index.md +12 -0
- package/docs/fundamentals/systems/overlays/overview.md +18 -5
- package/docs/fundamentals/systems/overlays/rationale.md +13 -0
- package/docs/fundamentals/systems/overlays/use-cases.md +15 -2
- package/docs/fundamentals/tools/ajax/index.md +12 -0
- package/docs/fundamentals/tools/ajax/overview.md +13 -0
- package/docs/fundamentals/tools/ajax/use-cases.md +13 -0
- package/docs/fundamentals/tools/helpers/action-logger.md +13 -0
- package/docs/fundamentals/tools/helpers/index.md +12 -0
- package/docs/fundamentals/tools/helpers/overview.md +14 -1
- package/docs/fundamentals/tools/index.md +10 -0
- package/docs/fundamentals/tools/singleton-manager/example-complex/index.md +13 -0
- package/docs/fundamentals/tools/singleton-manager/example-fail/index.md +13 -0
- package/docs/fundamentals/tools/singleton-manager/example-success/index.md +13 -0
- package/docs/fundamentals/tools/singleton-manager/index.md +12 -0
- package/docs/fundamentals/tools/singleton-manager/overview.md +17 -4
- package/docs/guides/how-to/create-a-custom-field.md +18 -6
- package/docs/guides/how-to/create-a-form.md +17 -5
- package/docs/guides/how-to/extend-a-native-input.md +15 -3
- package/docs/guides/how-to/get-started.md +13 -1
- package/docs/guides/how-to/index.md +11 -1
- package/docs/guides/index.md +19 -9
- package/docs/guides/principles/definitions-and-terms.md +13 -1
- package/docs/guides/principles/index.md +16 -6
- package/docs/guides/principles/scoped-elements.md +13 -1
- package/docs/guides/principles/styling.md +14 -2
- package/docs/guides/principles/subclasser-apis.md +13 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
<a href="https://lion.js.org/blog/">Blog</a>
|
|
38
38
|
</p>
|
|
39
39
|
|
|
40
|
-
**Lion is a set of highly performant, accessible and flexible Web Components
|
|
40
|
+
**Lion is a set of highly performant, accessible, and flexible Web Components.**
|
|
41
41
|
|
|
42
42
|
They provide an unopinionated, white-label layer that can be extended to your own layer of components.
|
|
43
43
|
|
|
44
44
|
- **High Performance:** Focused on great performance in all relevant browsers with a minimal number of dependencies.
|
|
45
45
|
- **Accessibility:** Aimed at compliance with the WCAG 2.2 AA standard to create components that are accessible for everybody.
|
|
46
46
|
- **Flexibility:** Provides solutions through Web Components and JavaScript classes which can be used, adopted and extended to fit all needs.
|
|
47
|
-
- **Modern Code:** Lion is
|
|
47
|
+
- **Modern Code:** Lion is distributed as pure es modules.
|
|
48
48
|
- **Exposes functions/classes and Web Components:** Ships a functionality in its most appropriate form.
|
|
49
49
|
|
|
50
50
|
> Note: Our demo examples might look simple and not very stylish. This is on purpose. They are designed to be basic so you can easily add your own styles to them to match your intended design, without dealing with styles that are already there.
|
|
@@ -1134,7 +1134,7 @@ export class LionCombobox extends LocalizeMixin(OverlayMixin(CustomChoiceGroupMi
|
|
|
1134
1134
|
}
|
|
1135
1135
|
break;
|
|
1136
1136
|
case 'Enter':
|
|
1137
|
-
if (this.
|
|
1137
|
+
if (this.opened) {
|
|
1138
1138
|
ev.preventDefault();
|
|
1139
1139
|
}
|
|
1140
1140
|
|
|
@@ -1145,8 +1145,6 @@ export class LionCombobox extends LocalizeMixin(OverlayMixin(CustomChoiceGroupMi
|
|
|
1145
1145
|
this.formElements[this.activeIndex].hasAttribute('aria-hidden') ||
|
|
1146
1146
|
!this.opened)
|
|
1147
1147
|
) {
|
|
1148
|
-
ev.preventDefault();
|
|
1149
|
-
|
|
1150
1148
|
this.modelValue = this.parser([...this.modelValue, this._inputNode.value]);
|
|
1151
1149
|
this._inputNode.value = '';
|
|
1152
1150
|
this.opened = false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineCE, expect, fixture, html, unsafeStatic } from '@open-wc/testing';
|
|
1
|
+
import { defineCE, expect, fixture, html, unsafeStatic, waitUntil } from '@open-wc/testing';
|
|
2
2
|
import { Required, Unparseable } from '@lion/ui/form-core.js';
|
|
3
3
|
import { sendKeys } from '@web/test-runner-commands';
|
|
4
4
|
import { LionCombobox } from '@lion/ui/combobox.js';
|
|
@@ -48,6 +48,80 @@ async function fruitFixture({ autocomplete, matchMode } = {}) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
describe('lion-combobox', () => {
|
|
51
|
+
describe('Rendering on API change', () => {
|
|
52
|
+
it('renders when options changed', async () => {
|
|
53
|
+
const entries = [
|
|
54
|
+
{
|
|
55
|
+
id: '1',
|
|
56
|
+
label: 'Apple',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: '2',
|
|
60
|
+
label: 'Artichoke',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: '3',
|
|
64
|
+
label: 'Asparagus',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: '4',
|
|
68
|
+
label: 'Banana',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: '5',
|
|
72
|
+
label: 'Pineapple',
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
class Wrapper extends LitElement {
|
|
77
|
+
static properties = {
|
|
78
|
+
...super.properties,
|
|
79
|
+
entries: { type: Array },
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
constructor() {
|
|
83
|
+
super();
|
|
84
|
+
this.entries = entries;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
render() {
|
|
88
|
+
return html`<lion-combobox name="foo">
|
|
89
|
+
${this.entries.map(
|
|
90
|
+
entry => html`<lion-option .choiceValue="${entry.id}">${entry.label}</lion-option>`,
|
|
91
|
+
)}
|
|
92
|
+
</lion-combobox>`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const tagString = defineCE(Wrapper);
|
|
97
|
+
const tag = unsafeStatic(tagString);
|
|
98
|
+
const wrapperElement = /** @type {Wrapper} */ (await fixture(html`<${tag}></${tag}>`));
|
|
99
|
+
await waitUntil(
|
|
100
|
+
() =>
|
|
101
|
+
wrapperElement?.shadowRoot?.querySelector('lion-options')?.querySelectorAll('lion-option')
|
|
102
|
+
.length === entries.length,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
wrapperElement.entries = [
|
|
106
|
+
{
|
|
107
|
+
id: '4',
|
|
108
|
+
label: 'Banana',
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
await waitUntil(
|
|
113
|
+
() =>
|
|
114
|
+
wrapperElement?.shadowRoot?.querySelector('lion-options')?.querySelectorAll('lion-option')
|
|
115
|
+
.length === wrapperElement.entries.length,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const optionElements = wrapperElement.shadowRoot?.querySelectorAll('lion-option');
|
|
119
|
+
expect(optionElements?.length).to.equal(wrapperElement.entries.length);
|
|
120
|
+
const optionElement = optionElements?.item(0);
|
|
121
|
+
expect(optionElement?.textContent).to.equal('Banana');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
51
125
|
describe('Options visibility', () => {
|
|
52
126
|
it('hides options when text in input node is cleared after typing something by default', async () => {
|
|
53
127
|
const el = /** @type {LionCombobox} */ (
|
|
@@ -911,6 +985,57 @@ describe('lion-combobox', () => {
|
|
|
911
985
|
await el.updateComplete;
|
|
912
986
|
expect(el.modelValue).to.eql(['Art']);
|
|
913
987
|
});
|
|
988
|
+
|
|
989
|
+
it('submits form on [Enter] when listbox is closed', async () => {
|
|
990
|
+
const submitSpy = sinon.spy(e => e.preventDefault());
|
|
991
|
+
const el = /** @type {HTMLFormElement} */ (
|
|
992
|
+
await fixture(html`
|
|
993
|
+
<form @submit=${submitSpy}>
|
|
994
|
+
<lion-combobox name="foo">
|
|
995
|
+
<lion-option .choiceValue="${'Artichoke'}">Artichoke</lion-option>
|
|
996
|
+
<lion-option .choiceValue="${'Chard'}">Chard</lion-option>
|
|
997
|
+
<lion-option .choiceValue="${'Chicory'}">Chicory</lion-option>
|
|
998
|
+
<lion-option .choiceValue="${'Victoria Plum'}">Victoria Plum</lion-option>
|
|
999
|
+
</lion-combobox>
|
|
1000
|
+
<button type="submit">submit</button>
|
|
1001
|
+
</form>
|
|
1002
|
+
`)
|
|
1003
|
+
);
|
|
1004
|
+
const combobox = /** @type {LionCombobox} */ (el.querySelector('[name="foo"]'));
|
|
1005
|
+
const { _inputNode } = getComboboxMembers(combobox);
|
|
1006
|
+
await combobox.updateComplete;
|
|
1007
|
+
_inputNode.focus();
|
|
1008
|
+
await sendKeys({
|
|
1009
|
+
press: 'Enter',
|
|
1010
|
+
});
|
|
1011
|
+
expect(submitSpy.callCount).to.equal(1);
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
it('does not submit form on [Enter] when listbox is opened', async () => {
|
|
1015
|
+
const submitSpy = sinon.spy(e => e.preventDefault());
|
|
1016
|
+
const el = /** @type {HTMLFormElement} */ (
|
|
1017
|
+
await fixture(html`
|
|
1018
|
+
<form @submit=${submitSpy}>
|
|
1019
|
+
<lion-combobox name="foo">
|
|
1020
|
+
<lion-option .choiceValue="${'Artichoke'}">Artichoke</lion-option>
|
|
1021
|
+
<lion-option .choiceValue="${'Chard'}">Chard</lion-option>
|
|
1022
|
+
<lion-option .choiceValue="${'Chicory'}">Chicory</lion-option>
|
|
1023
|
+
<lion-option .choiceValue="${'Victoria Plum'}">Victoria Plum</lion-option>
|
|
1024
|
+
</lion-combobox>
|
|
1025
|
+
<button type="submit">submit</button>
|
|
1026
|
+
</form>
|
|
1027
|
+
`)
|
|
1028
|
+
);
|
|
1029
|
+
const combobox = /** @type {LionCombobox} */ (el.querySelector('[name="foo"]'));
|
|
1030
|
+
const { _inputNode } = getComboboxMembers(combobox);
|
|
1031
|
+
combobox.opened = true;
|
|
1032
|
+
await combobox.updateComplete;
|
|
1033
|
+
_inputNode.focus();
|
|
1034
|
+
await sendKeys({
|
|
1035
|
+
press: 'Enter',
|
|
1036
|
+
});
|
|
1037
|
+
expect(submitSpy.callCount).to.equal(0);
|
|
1038
|
+
});
|
|
914
1039
|
});
|
|
915
1040
|
|
|
916
1041
|
describe('Overlay visibility', () => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getDateFormatBasedOnLocale } from './getDateFormatBasedOnLocale.js';
|
|
2
2
|
import { getLocalizeManager } from '../getLocalizeManager.js';
|
|
3
3
|
import { addLeadingZero } from './utils/addLeadingZero.js';
|
|
4
|
+
import { isCorrectYearFormat } from './utils/checkYearFormat.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {import('../../types/LocalizeMixinTypes.js').FormatDateOptions} FormatDateOptions
|
|
@@ -63,12 +64,16 @@ export function parseDate(dateString, options) {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
const [year, month, day] = parsedString.split('/').map(Number);
|
|
67
|
+
const [yearString] = parsedString.split('/');
|
|
68
|
+
if (!isCorrectYearFormat(yearString)) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
66
71
|
let correctedYear = year;
|
|
67
72
|
if (year < 50) {
|
|
68
73
|
correctedYear = 2000 + year;
|
|
69
74
|
}
|
|
70
75
|
|
|
71
|
-
const parsedDate = new Date(
|
|
76
|
+
const parsedDate = new Date(correctedYear, month - 1, day);
|
|
72
77
|
// Check if parsedDate is not `Invalid Date` or that the date has changed (e.g. the not existing 31.02.2020)
|
|
73
78
|
if (
|
|
74
79
|
year > 0 &&
|
|
@@ -91,4 +91,10 @@ describe('parseDate()', () => {
|
|
|
91
91
|
expect(parseDate('02.31.2020')).to.equal(undefined); // non existing date
|
|
92
92
|
expect(parseDate('31.12.2020')).to.equal(undefined); // day & month switched places
|
|
93
93
|
});
|
|
94
|
+
|
|
95
|
+
it('returns undefined for incorrect year format', () => {
|
|
96
|
+
// TODO: we need a `> 0` check for day and month, but maybe consider `>= 0` for year?
|
|
97
|
+
expect(parseDate('12-12-0000')).to.equal(undefined);
|
|
98
|
+
expect(parseDate('12-12-999')).to.equal(undefined);
|
|
99
|
+
});
|
|
94
100
|
});
|
package/custom-elements.json
CHANGED
|
@@ -145835,6 +145835,39 @@
|
|
|
145835
145835
|
}
|
|
145836
145836
|
]
|
|
145837
145837
|
},
|
|
145838
|
+
{
|
|
145839
|
+
"kind": "javascript-module",
|
|
145840
|
+
"path": "components/localize/src/date/utils/checkYearFormat.js",
|
|
145841
|
+
"declarations": [
|
|
145842
|
+
{
|
|
145843
|
+
"kind": "function",
|
|
145844
|
+
"name": "isCorrectYearFormat",
|
|
145845
|
+
"parameters": [
|
|
145846
|
+
{
|
|
145847
|
+
"name": "year",
|
|
145848
|
+
"type": {
|
|
145849
|
+
"text": "string"
|
|
145850
|
+
}
|
|
145851
|
+
}
|
|
145852
|
+
],
|
|
145853
|
+
"return": {
|
|
145854
|
+
"type": {
|
|
145855
|
+
"text": "boolean"
|
|
145856
|
+
}
|
|
145857
|
+
}
|
|
145858
|
+
}
|
|
145859
|
+
],
|
|
145860
|
+
"exports": [
|
|
145861
|
+
{
|
|
145862
|
+
"kind": "js",
|
|
145863
|
+
"name": "isCorrectYearFormat",
|
|
145864
|
+
"declaration": {
|
|
145865
|
+
"name": "isCorrectYearFormat",
|
|
145866
|
+
"module": "components/localize/src/date/utils/checkYearFormat.js"
|
|
145867
|
+
}
|
|
145868
|
+
}
|
|
145869
|
+
]
|
|
145870
|
+
},
|
|
145838
145871
|
{
|
|
145839
145872
|
"kind": "javascript-module",
|
|
145840
145873
|
"path": "../../node_modules/lit/directives/until.js",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LionCombobox.d.ts","sourceRoot":"","sources":["../../../../components/combobox/src/LionCombobox.js"],"names":[],"mappings":";AAgBA;;;;;;;;;GASG;AAEH;;;GAGG;AACH;IACE,kBAAkB;IAClB,6BAoBC;IAED,wFAgCC;IAuGD,4BAA4B;IAC5B,uBASC;IAtBD;;;;;;;OAOG;IACH,oBAEC;IAOG,iCAAiC;IACjC,SADW,MAAM,GAAG,SAAS,CACL;IAe5B;;OAEG;IACH,uCAcC;IAED;;;OAGG;IAEH,2EAOC;IAED;;OAEG;IAEH,0EAWC;IAED;;;OAGG;IACH,oEAEC;IAsDD;;;;OAIG;IACH,2CAEC;IAED;;;OAGG;IACH,sGAEC;IAED;;;;;OAKG;IACH,6CAOC;IAED;;;OAGG;IACH,4FAEC;IAED;;;OAGG;IACH,sDAEC;IAED;;;OAGG;IACH,sDAEC;IAaD;;;OAGG;IACH,6DAEC;IASD;;OAEG;IACH,qCAEC;IAZD;;OAEG;IACH,kCAEC;IAWC;;;;OAIG;IACH,cAFU,MAAM,GAAC,MAAM,GAAC,QAAQ,GAAC,MAAM,CAEb;IAC1B;;;;;;;OAOG;IACH,WAFU,OAAO,GAAC,KAAK,CAED;IACtB;;;OAGG;IACH,wBAA2B;IAM3B;;OAEG;IACH,kCAAoC;IACpC;;OAEG;IACH,+BAAiC;IAEjC;;;;OAIG;IACH,wBAHU,KAAK,GAAC,KAAK,CAG0C;IAW/D;;OAEG;IACH,mCAAoC;IACpC;;OAEG;IACH,wBAAyB;IACzB;;;OAGG;IACH,uCAA2C;IAC3C;;;OAGG;IACH,gCAAoC;
|
|
1
|
+
{"version":3,"file":"LionCombobox.d.ts","sourceRoot":"","sources":["../../../../components/combobox/src/LionCombobox.js"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseDate.d.ts","sourceRoot":"","sources":["../../../../../components/localize/src/date/parseDate.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parseDate.d.ts","sourceRoot":"","sources":["../../../../../components/localize/src/date/parseDate.js"],"names":[],"mappings":"AA6BA;;;;;;GAMG;AACH,sCAJW,MAAM,wFAEJ,IAAI,GAAG,SAAS,CAqD5B;gCAjFY,OAAO,mCAAmC,EAAE,iBAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkYearFormat.d.ts","sourceRoot":"","sources":["../../../../../../components/localize/src/date/utils/checkYearFormat.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,0CAHW,MAAM,GACJ,OAAO,CAInB"}
|