@dile/ui 3.22.1 → 3.24.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.
- package/components/button/src/DileButton.js +3 -0
- package/components/checkbox/src/DileCheckbox.js +14 -5
- package/components/color-picker/src/DileColorPicker.js +6 -2
- package/components/drop-file/src/DileDropFile.js +7 -5
- package/components/form-group/form-group.js +5 -0
- package/components/form-group/index.js +1 -0
- package/components/form-group/src/DileFormGroup.js +188 -0
- package/components/input/index.js +1 -1
- package/components/input/src/DileInput.js +128 -31
- package/components/input/src/DileInputContact.js +38 -40
- package/components/input/src/DileInputIcon.js +7 -43
- package/components/input/src/DileInputInteger.js +8 -22
- package/components/input/src/DileInputMask.js +25 -15
- package/components/input/src/DileInputMoney.js +6 -23
- package/components/input/src/DileInputNumber.js +6 -12
- package/components/input/src/DileInputNumberMask.js +5 -12
- package/components/input/src/DileInputPercentage.js +8 -20
- package/components/input/src/DileInputSearch.js +7 -1
- package/components/input/src/label-styles.js +15 -0
- package/components/input-suggestions/src/DileInputSuggestionsBase.js +6 -3
- package/components/number-picker/src/DileNumberPicker.js +8 -4
- package/components/number-picker/src/DileNumberPickerElement.js +7 -0
- package/components/order-switch/src/DileOrderSwitch.js +18 -2
- package/components/otp-input/src/DileOtpInput.js +10 -4
- package/components/password/src/DilePassword.js +19 -42
- package/components/radio-group/src/DileRadioGroup.js +6 -3
- package/components/rating-scale-question/src/DileRatingScaleQuestion.js +35 -3
- package/components/select/src/DileSelect.js +12 -4
- package/components/select/src/DileSelectAjax.js +12 -5
- package/components/select/src/DileSelectBoolean.js +9 -2
- package/components/select/src/DileSelectOverlay.js +6 -3
- package/components/select/src/DileSelectSearchableBase.js +8 -3
- package/components/switch/src/DileSwitch.js +3 -1
- package/components/textarea/src/DileTextarea.js +7 -3
- package/components/time-picker/src/DileTimePicker.js +680 -123
- package/components/wheel-picker/src/DileWheelPicker.js +17 -2
- package/lib/time/time.js +171 -0
- package/lib/time/time.test.js +63 -0
- package/mixins/form/index.js +3 -2
- package/mixins/form/src/DileFieldMessage.js +4 -1
- package/mixins/form/src/DileForm.js +240 -1
- package/mixins/form/src/DileNativeValidity.js +195 -0
- package/mixins/overlay/src/DileOverlay.js +16 -0
- package/package.json +2 -2
|
@@ -27,6 +27,8 @@ export class DileButton extends LitElement {
|
|
|
27
27
|
noWrap: { type: Boolean, reflect: true, attribute: 'no-wrap' },
|
|
28
28
|
/** Accessible name for the button. Required when the button only shows an icon. */
|
|
29
29
|
label: { type: String },
|
|
30
|
+
/** Accessible description of the button, applied as aria-description (e.g. a related validation message). */
|
|
31
|
+
accessibleDescription: { type: String },
|
|
30
32
|
_hasText: { type: Boolean, state: true },
|
|
31
33
|
};
|
|
32
34
|
}
|
|
@@ -175,6 +177,7 @@ export class DileButton extends LitElement {
|
|
|
175
177
|
type=${this.type || "button"}
|
|
176
178
|
aria-label=${ifDefined(this._computedAriaLabel)}
|
|
177
179
|
aria-busy=${ifDefined(this.loading ? 'true' : undefined)}
|
|
180
|
+
aria-description=${ifDefined(this.accessibleDescription || undefined)}
|
|
178
181
|
>
|
|
179
182
|
${showIcon && this.iconPosition !== 'right' ? this.iconTemplate : ''}
|
|
180
183
|
<slot @slotchange=${this._onSlotChange}></slot>
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { html, css, LitElement } from "lit";
|
|
2
2
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
-
import {
|
|
3
|
+
import { requiredIndicatorStyles } from '../../input/src/label-styles.js';
|
|
4
|
+
import { DileNativeValidity, DileEmmitChange } from '../../../mixins/form/index.js';
|
|
4
5
|
import { checkboxBlankIcon, checkboxCheckedIcon } from '@dile/icons';
|
|
5
6
|
import '../../icon/icon.js';
|
|
6
7
|
import '../../input/input-message.js';
|
|
7
8
|
|
|
8
|
-
export class DileCheckbox extends DileEmmitChange(LitElement) {
|
|
9
|
+
export class DileCheckbox extends DileNativeValidity(DileEmmitChange(LitElement)) {
|
|
9
10
|
static get properties() {
|
|
10
11
|
return {
|
|
11
12
|
checked: { type: Boolean, reflect: true, },
|
|
12
13
|
disabled: { type: Boolean, reflect: true, },
|
|
14
|
+
/** Marks the field as required: shows the required indicator in the label and sets aria-required */
|
|
15
|
+
required: { type: Boolean, reflect: true },
|
|
13
16
|
_hasInner: { type: Boolean },
|
|
14
17
|
name: { type: String, reflect: true, },
|
|
15
18
|
message: { type: String },
|
|
@@ -33,7 +36,7 @@ export class DileCheckbox extends DileEmmitChange(LitElement) {
|
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
static get styles() {
|
|
36
|
-
return css`
|
|
39
|
+
return [requiredIndicatorStyles, css`
|
|
37
40
|
:host {
|
|
38
41
|
display: inline-block;
|
|
39
42
|
--dile-icon-size: var(--dile-checkbox-size, 20px);
|
|
@@ -68,7 +71,7 @@ export class DileCheckbox extends DileEmmitChange(LitElement) {
|
|
|
68
71
|
.disabled .label {
|
|
69
72
|
color: var(--dile-checkbox-label-disabled-color, #777);
|
|
70
73
|
}
|
|
71
|
-
|
|
74
|
+
`];
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
firstUpdated() {
|
|
@@ -83,6 +86,11 @@ export class DileCheckbox extends DileEmmitChange(LitElement) {
|
|
|
83
86
|
this.checked = value;
|
|
84
87
|
}
|
|
85
88
|
|
|
89
|
+
/** Used by the required check of DileForm: as in HTML, a required checkbox must be checked */
|
|
90
|
+
isEmpty() {
|
|
91
|
+
return !this.checked;
|
|
92
|
+
}
|
|
93
|
+
|
|
86
94
|
updated(changedProperties) {
|
|
87
95
|
if (changedProperties.has('checked')) {
|
|
88
96
|
this.emmitChange();
|
|
@@ -97,6 +105,7 @@ export class DileCheckbox extends DileEmmitChange(LitElement) {
|
|
|
97
105
|
role="checkbox"
|
|
98
106
|
aria-checked="${this.checked}"
|
|
99
107
|
aria-disabled="${this.disabled ? "true" : "false"}"
|
|
108
|
+
aria-required="${ifDefined(this.required ? "true" : undefined)}"
|
|
100
109
|
aria-labelledby="${ifDefined(this._hasInner ? `${this._id}-label` : undefined)}"
|
|
101
110
|
aria-describedby="${ifDefined(this.message ? `${this._id}-message` : undefined)}"
|
|
102
111
|
tabindex="${this.disabled ? "-1" : "0"}"
|
|
@@ -117,7 +126,7 @@ export class DileCheckbox extends DileEmmitChange(LitElement) {
|
|
|
117
126
|
get innerTemplate() {
|
|
118
127
|
return html`
|
|
119
128
|
${this._hasInner
|
|
120
|
-
? html` <label id="${this._id}-label" class="label">
|
|
129
|
+
? html` <label id="${this._id}-label" class="label field-label">
|
|
121
130
|
<slot></slot>
|
|
122
131
|
</label>`
|
|
123
132
|
: ""
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LitElement, html, css } from 'lit';
|
|
2
|
-
import {
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { DileEmmitChange, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
|
|
3
4
|
import { DileOverlay } from '../../../mixins/overlay/index.js';
|
|
4
5
|
import { DileCloseDocumentClick } from '../../../mixins/close-document-click/index.js';
|
|
5
6
|
import { DileCloseOnEscPressed } from '../../../mixins/close-on-esc-pressed/index.js';
|
|
@@ -308,6 +309,7 @@ export class DileColorPicker extends DileOverlay(
|
|
|
308
309
|
aria-haspopup="dialog"
|
|
309
310
|
aria-expanded="${this.opened}"
|
|
310
311
|
aria-label="${this.label || 'Color picker'}"
|
|
312
|
+
aria-describedby="${ifDefined(this.message ? FIELD_MESSAGE_ID : undefined)}"
|
|
311
313
|
@click="${this.toggle}"
|
|
312
314
|
></button>
|
|
313
315
|
</div>
|
|
@@ -361,6 +363,8 @@ export class DileColorPicker extends DileOverlay(
|
|
|
361
363
|
type="text"
|
|
362
364
|
class="hex-input ${this.errored ? 'errored' : ''}"
|
|
363
365
|
aria-label="Hex color"
|
|
366
|
+
aria-invalid="${ifDefined(this.errored ? 'true' : undefined)}"
|
|
367
|
+
aria-describedby="${ifDefined(this.message ? FIELD_MESSAGE_ID : undefined)}"
|
|
364
368
|
maxlength="7"
|
|
365
369
|
spellcheck="false"
|
|
366
370
|
autocomplete="off"
|
|
@@ -379,7 +383,7 @@ export class DileColorPicker extends DileOverlay(
|
|
|
379
383
|
get messageTemplate() {
|
|
380
384
|
return html`
|
|
381
385
|
${this.message
|
|
382
|
-
? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
|
|
386
|
+
? html`<div id="${FIELD_MESSAGE_ID}" class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
|
|
383
387
|
: ''
|
|
384
388
|
}
|
|
385
389
|
`;
|
|
@@ -4,9 +4,9 @@ import '../file-preview.js';
|
|
|
4
4
|
import '../../button/button.js';
|
|
5
5
|
import { labelStyles } from '../../input/src/label-styles.js';
|
|
6
6
|
import { messageStyles } from '../../input/src/message-styles.js';
|
|
7
|
-
import { DileEmmitChange } from '../../../mixins/form/index.js';
|
|
7
|
+
import { DileNativeValidity, DileEmmitChange, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
|
|
8
8
|
|
|
9
|
-
export class DileDropFile extends DileEmmitChange(LitElement) {
|
|
9
|
+
export class DileDropFile extends DileNativeValidity(DileEmmitChange(LitElement)) {
|
|
10
10
|
static styles = [
|
|
11
11
|
labelStyles,
|
|
12
12
|
messageStyles,
|
|
@@ -53,6 +53,8 @@ export class DileDropFile extends DileEmmitChange(LitElement) {
|
|
|
53
53
|
static get properties() {
|
|
54
54
|
return {
|
|
55
55
|
label: { type: String },
|
|
56
|
+
/** Marks the field as required: shows the required indicator in the label and sets aria-required */
|
|
57
|
+
required: { type: Boolean, reflect: true },
|
|
56
58
|
message: { type: String },
|
|
57
59
|
errored: { type: Boolean },
|
|
58
60
|
dropLabel: { type: String },
|
|
@@ -98,7 +100,7 @@ export class DileDropFile extends DileEmmitChange(LitElement) {
|
|
|
98
100
|
return html`
|
|
99
101
|
<main>
|
|
100
102
|
${this.label
|
|
101
|
-
? html`<label for="fileInput">${this.label}</label>`
|
|
103
|
+
? html`<label for="fileInput" class="field-label">${this.label}</label>`
|
|
102
104
|
: ""
|
|
103
105
|
}
|
|
104
106
|
</main>
|
|
@@ -136,7 +138,7 @@ export class DileDropFile extends DileEmmitChange(LitElement) {
|
|
|
136
138
|
get messageTemplate() {
|
|
137
139
|
return html`
|
|
138
140
|
${this.message
|
|
139
|
-
? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
|
|
141
|
+
? html`<div id="${FIELD_MESSAGE_ID}" class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
|
|
140
142
|
: ''
|
|
141
143
|
}
|
|
142
144
|
`
|
|
@@ -145,7 +147,7 @@ export class DileDropFile extends DileEmmitChange(LitElement) {
|
|
|
145
147
|
get dropLabelTemplate() {
|
|
146
148
|
return html`
|
|
147
149
|
<p>${this.dropLabel}</p>
|
|
148
|
-
<p><dile-button>${this.buttonLabel}</dile-button></p>
|
|
150
|
+
<p><dile-button .accessibleDescription=${this.message || undefined}>${this.buttonLabel}</dile-button></p>
|
|
149
151
|
`
|
|
150
152
|
}
|
|
151
153
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DileFormGroup } from './src/DileFormGroup.js';
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
2
|
+
|
|
3
|
+
export class DileFormGroup extends LitElement {
|
|
4
|
+
static styles = [
|
|
5
|
+
css`
|
|
6
|
+
* {
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
}
|
|
9
|
+
:host {
|
|
10
|
+
display: block;
|
|
11
|
+
margin: var(--dile-form-group-margin, 0 0 1.5rem);
|
|
12
|
+
}
|
|
13
|
+
:host([hidden]) {
|
|
14
|
+
display: none;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.group {
|
|
18
|
+
padding: var(--dile-form-group-padding, 1rem 0 0);
|
|
19
|
+
border-top: var(--dile-form-group-border-top, 1px solid var(--dile-form-group-line-color, var(--dile-secondary-dark-color, #888)));
|
|
20
|
+
}
|
|
21
|
+
:host([variant="box"]) .group {
|
|
22
|
+
padding: var(--dile-form-group-padding, 1rem);
|
|
23
|
+
border: var(--dile-form-group-border, 1px solid var(--dile-form-group-line-color, #ccc));
|
|
24
|
+
border-radius: var(--dile-form-group-border-radius, 0.5rem);
|
|
25
|
+
background-color: var(--dile-form-group-background-color, transparent);
|
|
26
|
+
}
|
|
27
|
+
:host([variant="plain"]) .group {
|
|
28
|
+
padding: var(--dile-form-group-padding, 0);
|
|
29
|
+
border: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
header {
|
|
33
|
+
margin-bottom: var(--dile-form-group-header-margin-bottom, 0.75rem);
|
|
34
|
+
}
|
|
35
|
+
.label {
|
|
36
|
+
margin: 0;
|
|
37
|
+
color: var(--dile-form-group-label-color, var(--dile-secondary-dark-color, #888));
|
|
38
|
+
font-size: var(--dile-form-group-label-font-size, 1.1rem);
|
|
39
|
+
font-weight: var(--dile-form-group-label-font-weight, 300);
|
|
40
|
+
}
|
|
41
|
+
.description {
|
|
42
|
+
margin: 0.25rem 0 0;
|
|
43
|
+
color: var(--dile-form-group-description-color, var(--dile-on-background-color, #303030));
|
|
44
|
+
font-size: var(--dile-form-group-description-font-size, 0.875rem);
|
|
45
|
+
opacity: 0.8;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.grid {
|
|
49
|
+
display: grid;
|
|
50
|
+
grid-template-columns: minmax(0, 1fr);
|
|
51
|
+
gap: var(--dile-form-group-gap, 0 1rem);
|
|
52
|
+
align-items: start;
|
|
53
|
+
}
|
|
54
|
+
:host([columns="2"]) .grid {
|
|
55
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
56
|
+
}
|
|
57
|
+
:host([columns="3"]) .grid {
|
|
58
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
59
|
+
}
|
|
60
|
+
.grid ::slotted([data-span="2"]) {
|
|
61
|
+
grid-column: span 2;
|
|
62
|
+
}
|
|
63
|
+
.grid ::slotted([data-span="full"]) {
|
|
64
|
+
grid-column: 1 / -1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.split {
|
|
68
|
+
display: grid;
|
|
69
|
+
grid-template-columns: var(--dile-form-group-split-columns, 1fr 1fr);
|
|
70
|
+
gap: var(--dile-form-group-gap, 0 1rem);
|
|
71
|
+
align-items: start;
|
|
72
|
+
}
|
|
73
|
+
.split-column {
|
|
74
|
+
display: flex;
|
|
75
|
+
flex-direction: column;
|
|
76
|
+
min-width: 0;
|
|
77
|
+
}
|
|
78
|
+
.split:not(.has-content) {
|
|
79
|
+
display: none;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
:host([collapsed]) .grid,
|
|
83
|
+
:host([collapsed]) .split {
|
|
84
|
+
grid-template-columns: minmax(0, 1fr);
|
|
85
|
+
}
|
|
86
|
+
:host([collapsed]) .grid ::slotted([data-span]) {
|
|
87
|
+
grid-column: auto;
|
|
88
|
+
}
|
|
89
|
+
`
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
static get properties() {
|
|
93
|
+
return {
|
|
94
|
+
label: { type: String },
|
|
95
|
+
description: { type: String },
|
|
96
|
+
labelLevel: { type: Number, attribute: 'label-level' },
|
|
97
|
+
columns: { type: Number, reflect: true },
|
|
98
|
+
breakpoint: { type: Number },
|
|
99
|
+
variant: { type: String, reflect: true },
|
|
100
|
+
collapsed: { type: Boolean, reflect: true },
|
|
101
|
+
_hasSplitContent: { state: true },
|
|
102
|
+
_hasLabelSlot: { state: true },
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
constructor() {
|
|
107
|
+
super();
|
|
108
|
+
this.columns = 1;
|
|
109
|
+
this.breakpoint = 600;
|
|
110
|
+
this.variant = 'line';
|
|
111
|
+
this.collapsed = false;
|
|
112
|
+
this._hasSplitContent = false;
|
|
113
|
+
this._hasLabelSlot = false;
|
|
114
|
+
this._width = null;
|
|
115
|
+
this._resizeObserver = new ResizeObserver((entries) => {
|
|
116
|
+
this._width = entries[0].contentRect.width;
|
|
117
|
+
this._updateCollapsed();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
connectedCallback() {
|
|
122
|
+
super.connectedCallback();
|
|
123
|
+
this._resizeObserver.observe(this);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
disconnectedCallback() {
|
|
127
|
+
super.disconnectedCallback();
|
|
128
|
+
this._resizeObserver.disconnect();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
updated(changedProperties) {
|
|
132
|
+
if (changedProperties.has('breakpoint')) {
|
|
133
|
+
this._updateCollapsed();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
_updateCollapsed() {
|
|
138
|
+
if (this._width === null) return;
|
|
139
|
+
this.collapsed = this.breakpoint > 0 && this._width < this.breakpoint;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
render() {
|
|
143
|
+
const hasHeader = this.label || this.description || this._hasLabelSlot;
|
|
144
|
+
return html`
|
|
145
|
+
<div
|
|
146
|
+
class="group"
|
|
147
|
+
role="group"
|
|
148
|
+
aria-labelledby=${this.label || this._hasLabelSlot ? 'label' : nothing}
|
|
149
|
+
aria-describedby=${this.description ? 'description' : nothing}
|
|
150
|
+
>
|
|
151
|
+
<header ?hidden=${!hasHeader}>
|
|
152
|
+
${this.labelTemplate}
|
|
153
|
+
${this.description ? html`<p id="description" class="description">${this.description}</p>` : ''}
|
|
154
|
+
</header>
|
|
155
|
+
<div class="split ${this._hasSplitContent ? 'has-content' : ''}">
|
|
156
|
+
<div class="split-column"><slot name="left" @slotchange=${this._onSplitSlotChange}></slot></div>
|
|
157
|
+
<div class="split-column"><slot name="right" @slotchange=${this._onSplitSlotChange}></slot></div>
|
|
158
|
+
</div>
|
|
159
|
+
<div class="grid">
|
|
160
|
+
<slot></slot>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
get labelTemplate() {
|
|
167
|
+
const useHeadingRole = this.labelLevel && !this._hasLabelSlot;
|
|
168
|
+
return html`
|
|
169
|
+
<div
|
|
170
|
+
id="label"
|
|
171
|
+
class="label"
|
|
172
|
+
role=${useHeadingRole ? 'heading' : nothing}
|
|
173
|
+
aria-level=${useHeadingRole ? this.labelLevel : nothing}
|
|
174
|
+
>
|
|
175
|
+
<slot name="label" @slotchange=${this._onLabelSlotChange}>${this.label}</slot>
|
|
176
|
+
</div>
|
|
177
|
+
`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
_onSplitSlotChange() {
|
|
181
|
+
const slots = this.shadowRoot.querySelectorAll('slot[name="left"], slot[name="right"]');
|
|
182
|
+
this._hasSplitContent = [...slots].some((slot) => slot.assignedNodes().length > 0);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
_onLabelSlotChange(e) {
|
|
186
|
+
this._hasLabelSlot = e.target.assignedNodes().length > 0;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -8,7 +8,7 @@ export { DileInputNumber } from './src/DileInputNumber.js';
|
|
|
8
8
|
export { DileInputNumberMask } from './src/DileInputNumberMask.js';
|
|
9
9
|
export { DileInputPercentage } from './src/DileInputPercentage.js';
|
|
10
10
|
export { DileInputSearch } from './src/DileInputSearch.js';
|
|
11
|
-
export { labelStyles } from './src/label-styles.js';
|
|
11
|
+
export { labelStyles, requiredIndicatorStyles } from './src/label-styles.js';
|
|
12
12
|
export { messageStyles } from './src/message-styles.js';
|
|
13
13
|
export { Mask } from './src/Mask.js';
|
|
14
14
|
export { MaskPattern } from './src/MaskPattern.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { LitElement, html, css } from 'lit';
|
|
2
2
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
-
import { DileEmmitChange, DileFieldMessage } from '../../../mixins/form/index.js';
|
|
3
|
+
import { DileNativeValidity, DileEmmitChange, DileFieldMessage, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
|
|
4
4
|
import { labelStyles } from './label-styles.js';
|
|
5
5
|
import { messageStyles } from './message-styles.js';
|
|
6
6
|
|
|
7
|
-
export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
|
|
7
|
+
export class DileInput extends DileFieldMessage(DileNativeValidity(DileEmmitChange(LitElement))) {
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Fired when user press enter key.
|
|
@@ -35,6 +35,9 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
|
|
|
35
35
|
/** Disable the input field */
|
|
36
36
|
disabled: { type: Boolean },
|
|
37
37
|
|
|
38
|
+
/** Marks the field as required: shows the required indicator in the label and sets aria-required */
|
|
39
|
+
required: { type: Boolean, reflect: true },
|
|
40
|
+
|
|
38
41
|
/** Set initial value to the input. This property syncs to the input field value property */
|
|
39
42
|
value: { type: String },
|
|
40
43
|
|
|
@@ -44,6 +47,9 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
|
|
|
44
47
|
/** Disable the autocomplete of the input field */
|
|
45
48
|
disableAutocomplete: { type: Boolean },
|
|
46
49
|
|
|
50
|
+
/** Value of the autocomplete attribute of the input field (e.g. "email", "new-password"). Defaults to "on". Ignored when disableAutocomplete is set */
|
|
51
|
+
autocomplete: { type: String },
|
|
52
|
+
|
|
47
53
|
/** ReadOnly attribute */
|
|
48
54
|
readonly: { type: Boolean },
|
|
49
55
|
|
|
@@ -58,6 +64,9 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
|
|
|
58
64
|
|
|
59
65
|
/** Set the application focus to this the input component after the initialization */
|
|
60
66
|
focusOnStart: { type: Boolean },
|
|
67
|
+
|
|
68
|
+
/** Disabled state inherited from an ancestor fieldset or form */
|
|
69
|
+
_formDisabled: { state: true },
|
|
61
70
|
};
|
|
62
71
|
}
|
|
63
72
|
|
|
@@ -72,13 +81,27 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
|
|
|
72
81
|
this.labelRight = '';
|
|
73
82
|
this.value = '';
|
|
74
83
|
this.disabled = false;
|
|
84
|
+
this.required = false;
|
|
75
85
|
this.disableAutocomplete = false;
|
|
76
86
|
this.name = '';
|
|
77
87
|
this.type = 'text';
|
|
78
88
|
this.types = ['text', 'password', 'email', 'number', 'tel', 'url', 'search', 'date', 'time', 'datetime', 'datetime-local', 'month', 'week'];
|
|
89
|
+
this._formDisabled = false;
|
|
79
90
|
this.internals = this.attachInternals();
|
|
80
91
|
}
|
|
81
92
|
|
|
93
|
+
/** Called by the browser when the owner form is reset: restores the value of the value attribute */
|
|
94
|
+
formResetCallback() {
|
|
95
|
+
super.formResetCallback?.();
|
|
96
|
+
this.value = this.getAttribute('value') ?? '';
|
|
97
|
+
this.clearError();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Called by the browser when an ancestor fieldset or form is disabled or enabled */
|
|
101
|
+
formDisabledCallback(disabled) {
|
|
102
|
+
this._formDisabled = disabled;
|
|
103
|
+
}
|
|
104
|
+
|
|
82
105
|
firstUpdated() {
|
|
83
106
|
if(this.focusOnStart) {
|
|
84
107
|
this.focus();
|
|
@@ -88,7 +111,7 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
|
|
|
88
111
|
updated(changedProperties) {
|
|
89
112
|
if(changedProperties.has('value')) {
|
|
90
113
|
this.emmitChange();
|
|
91
|
-
this.internals.setFormValue(this.value);
|
|
114
|
+
this.internals.setFormValue(this.value ?? '');
|
|
92
115
|
}
|
|
93
116
|
}
|
|
94
117
|
|
|
@@ -156,36 +179,100 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
|
|
|
156
179
|
render() {
|
|
157
180
|
return html`
|
|
158
181
|
<main>
|
|
159
|
-
${this.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
id="textField"
|
|
166
|
-
name="${this.name}"
|
|
167
|
-
aria-label="${ifDefined(this.inputAriaLabel)}"
|
|
168
|
-
placeholder="${this.placeholder}"
|
|
169
|
-
?disabled="${this.disabled}"
|
|
170
|
-
?readonly="${this.readonly}"
|
|
171
|
-
autocomplete="${this.disableAutocomplete ? "off" : "on"}"
|
|
172
|
-
.value="${this.computeValue(this.value)}"
|
|
173
|
-
class="${this.errored ? 'errored' : ''}"
|
|
174
|
-
@keypress="${this._lookForEnter}"
|
|
175
|
-
@input="${this._input}"
|
|
176
|
-
@blur="${this.doBlur}"
|
|
177
|
-
@focus="${this.doFocus}"
|
|
178
|
-
/>
|
|
179
|
-
${this.labelRight
|
|
180
|
-
? html`<span class="labelright">${this.labelRight}</span>`
|
|
181
|
-
: ''
|
|
182
|
-
}
|
|
182
|
+
${this.labelTemplate}
|
|
183
|
+
<section class="for-input">
|
|
184
|
+
${this.fieldStartTemplate}
|
|
185
|
+
${this.inputTemplate}
|
|
186
|
+
${this.fieldEndTemplate}
|
|
187
|
+
${this.labelRightTemplate}
|
|
183
188
|
</section>
|
|
184
189
|
${this.messageTemplate}
|
|
185
190
|
</main>
|
|
186
191
|
`;
|
|
187
192
|
}
|
|
188
193
|
|
|
194
|
+
/** Template of the visible label. Override to customize it. */
|
|
195
|
+
get labelTemplate() {
|
|
196
|
+
return this.label
|
|
197
|
+
? html`<label for="textField" class="field-label">${this.label}</label>`
|
|
198
|
+
: '';
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Template of the native input. Subclasses should reuse it instead of copying it,
|
|
203
|
+
* customizing it through `inputType`, `computeValue()`, `computeAutocomplete()`,
|
|
204
|
+
* `inputModeValue` and the event handlers (`_input`, `doKeydown`, `doBlur`, `doFocus`).
|
|
205
|
+
*/
|
|
206
|
+
get inputTemplate() {
|
|
207
|
+
return html`
|
|
208
|
+
<input
|
|
209
|
+
type="${this.inputType}"
|
|
210
|
+
id="textField"
|
|
211
|
+
name="${this.name}"
|
|
212
|
+
inputmode="${ifDefined(this.inputModeValue)}"
|
|
213
|
+
aria-label="${ifDefined(this.inputAriaLabel)}"
|
|
214
|
+
aria-invalid="${ifDefined(this.errored ? 'true' : undefined)}"
|
|
215
|
+
aria-required="${ifDefined(this.required ? 'true' : undefined)}"
|
|
216
|
+
aria-describedby="${ifDefined(this.messageDescribedBy)}"
|
|
217
|
+
placeholder="${this.placeholder}"
|
|
218
|
+
?disabled="${this.isDisabled}"
|
|
219
|
+
?readonly="${this.readonly}"
|
|
220
|
+
autocomplete="${this.computeAutocomplete()}"
|
|
221
|
+
.value="${this.computeValue(this.value)}"
|
|
222
|
+
class="${this.errored ? 'errored' : ''}"
|
|
223
|
+
@keypress="${this._lookForEnter}"
|
|
224
|
+
@keydown="${this.doKeydown}"
|
|
225
|
+
@input="${this._input}"
|
|
226
|
+
@blur="${this.doBlur}"
|
|
227
|
+
@focus="${this.doFocus}"
|
|
228
|
+
/>
|
|
229
|
+
`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Content placed inside the field row, before the input (e.g. a prefix selector) */
|
|
233
|
+
get fieldStartTemplate() {
|
|
234
|
+
return '';
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Content placed inside the field row, after the input (e.g. an action button) */
|
|
238
|
+
get fieldEndTemplate() {
|
|
239
|
+
return '';
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
get labelRightTemplate() {
|
|
243
|
+
return this.labelRight
|
|
244
|
+
? html`<span class="labelright">${this.labelRight}</span>`
|
|
245
|
+
: '';
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Type applied to the native input */
|
|
249
|
+
get inputType() {
|
|
250
|
+
return this.availableType(this.type);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** inputmode applied to the native input. Undefined means no attribute. */
|
|
254
|
+
get inputModeValue() {
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Value of the autocomplete attribute of the native input */
|
|
259
|
+
computeAutocomplete() {
|
|
260
|
+
if (this.disableAutocomplete) {
|
|
261
|
+
return 'off';
|
|
262
|
+
}
|
|
263
|
+
return this.autocomplete || 'on';
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** True when the field is disabled by its own property or by a disabled ancestor fieldset/form */
|
|
267
|
+
get isDisabled() {
|
|
268
|
+
return this.disabled || this._formDisabled;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Id of the element describing the input (the message), if any */
|
|
272
|
+
get messageDescribedBy() {
|
|
273
|
+
return this.message ? FIELD_MESSAGE_ID : undefined;
|
|
274
|
+
}
|
|
275
|
+
|
|
189
276
|
/** aria-label for the inner input: accessibleLabel, only when there is no visible label */
|
|
190
277
|
get inputAriaLabel() {
|
|
191
278
|
return !this.label && this.accessibleLabel ? this.accessibleLabel : undefined;
|
|
@@ -215,7 +302,12 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
|
|
|
215
302
|
}
|
|
216
303
|
|
|
217
304
|
get el() {
|
|
218
|
-
return this.shadowRoot
|
|
305
|
+
return this.shadowRoot?.querySelector('input') ?? null;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** Hook for the keydown event of the native input */
|
|
309
|
+
doKeydown() {
|
|
310
|
+
//
|
|
219
311
|
}
|
|
220
312
|
|
|
221
313
|
doBlur() {
|
|
@@ -229,10 +321,15 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
|
|
|
229
321
|
}
|
|
230
322
|
|
|
231
323
|
computeValue(value) {
|
|
232
|
-
return value;
|
|
324
|
+
return value ?? '';
|
|
233
325
|
}
|
|
234
326
|
|
|
235
|
-
focus
|
|
236
|
-
|
|
327
|
+
/** Moves the focus to the native input. Waits for the first render if needed. */
|
|
328
|
+
focus(options) {
|
|
329
|
+
if (this.el) {
|
|
330
|
+
this.el.focus(options);
|
|
331
|
+
} else {
|
|
332
|
+
this.updateComplete.then(() => this.el?.focus(options));
|
|
333
|
+
}
|
|
237
334
|
}
|
|
238
335
|
}
|