@dile/ui 3.4.5 → 3.5.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/accordion/accordion-item.js +3 -1
- package/components/accordion/accordion.js +3 -1
- package/components/app-drawer/app-drawer.js +3 -1
- package/components/avatar/avatar.js +3 -1
- package/components/avatar/avatar.spec.js +25 -0
- package/components/box-selector/box-selector-item.js +3 -1
- package/components/box-selector/box-selector-item.spec.js +27 -0
- package/components/box-selector/box-selector.js +3 -1
- package/components/box-selector/box-selector.spec.js +27 -0
- package/components/breadcrumbs/breadcrumbs-item.js +3 -1
- package/components/breadcrumbs/breadcrumbs-item.spec.js +28 -0
- package/components/breadcrumbs/breadcrumbs.js +3 -1
- package/components/breadcrumbs/breadcrumbs.spec.js +33 -0
- package/components/button/button-icon.js +3 -1
- package/components/button/button.js +3 -1
- package/components/card/card-slide.js +3 -1
- package/components/card/card-slide.spec.js +30 -0
- package/components/card/card.js +3 -1
- package/components/card/card.spec.js +26 -0
- package/components/checkbox/checkbox.js +3 -1
- package/components/chip/chip.js +3 -1
- package/components/chip/chip.spec.js +31 -0
- package/components/color-picker/color-picker.js +3 -1
- package/components/confirm/confirm.js +3 -1
- package/components/confirm/confirm.spec.js +32 -0
- package/components/confirm-text/confirm-text.js +3 -1
- package/components/confirm-text/confirm-text.spec.js +29 -0
- package/components/copy-markdown-url/copy-markdown-url.spec.js +27 -0
- package/components/copy-markdown-url/index.js +3 -1
- package/components/copy-text/__screenshots__/copy-text.spec.js/dile-copy-text-dispatches-dile-text-copied-with-the-content-on-copy---1.png +0 -0
- package/components/copy-text/copy-text.spec.js +38 -0
- package/components/copy-text/index.js +3 -1
- package/components/drop-file/drop-file.js +3 -1
- package/components/drop-file/drop-file.spec.js +33 -0
- package/components/drop-file/file-preview.js +3 -1
- package/components/drop-file/file-preview.spec.js +35 -0
- package/components/floating-feedback/floating-feedback.spec.js +30 -0
- package/components/floating-feedback/index.js +3 -1
- package/components/floating-menu/floating-menu-item.js +3 -1
- package/components/floating-menu/floating-menu-item.spec.js +27 -0
- package/components/floating-menu/floating-menu.js +3 -1
- package/components/floating-menu/floating-menu.spec.js +31 -0
- package/components/form-separator/form-separator.js +3 -1
- package/components/form-separator/form-separator.spec.js +28 -0
- package/components/hamburger/hamburger.js +3 -1
- package/components/hamburger/hamburger.spec.js +28 -0
- package/components/icon/icon.js +3 -1
- package/components/icon/icon.spec.js +31 -0
- package/components/icon-switch/icon-switch-group.js +3 -1
- package/components/icon-switch/icon-switch-group.spec.js +46 -0
- package/components/icon-switch/icon-switch.js +3 -1
- package/components/icon-switch/icon-switch.spec.js +35 -0
- package/components/info-box/info-box.js +3 -1
- package/components/info-box/info-box.spec.js +38 -0
- package/components/inline-feedback/inline-feedback.js +3 -1
- package/components/inline-feedback/inline-feedback.spec.js +46 -0
- package/components/input/__screenshots__/input-number-mask.spec.js/dile-input-number-mask-masks-digit-keydowns-following-the-given-pattern-1.png +0 -0
- package/components/input/input-contact.js +3 -1
- package/components/input/input-contact.spec.js +32 -0
- package/components/input/input-integer.js +3 -1
- package/components/input/input-integer.spec.js +31 -0
- package/components/input/input-message.js +3 -1
- package/components/input/input-message.spec.js +27 -0
- package/components/input/input-money.js +3 -1
- package/components/input/input-money.spec.js +30 -0
- package/components/input/input-number-mask.js +3 -1
- package/components/input/input-number-mask.spec.js +32 -0
- package/components/input/input-percentage.js +3 -1
- package/components/input/input-percentage.spec.js +31 -0
- package/components/input/input-search.js +3 -1
- package/components/input/input-search.spec.js +39 -0
- package/components/input/input.js +3 -1
- package/components/input/input.spec.js +47 -0
- package/components/light-mode-switch/light-mode-switch.js +3 -1
- package/components/light-mode-switch/light-mode-switch.spec.js +34 -0
- package/components/menu-hamburger/menu-hamburger.js +3 -1
- package/components/menu-hamburger/menu-hamburger.spec.js +34 -0
- package/components/menu-overlay/menu-overlay.js +3 -1
- package/components/menu-overlay/menu-overlay.spec.js +44 -0
- package/components/message/message.js +3 -1
- package/components/message/message.spec.js +42 -0
- package/components/modal/__screenshots__/modal-help.spec.js/dile-modal-help-opens-the-inner-modal-on-open---1.png +0 -0
- package/components/modal/modal-help.js +3 -1
- package/components/modal/modal-help.spec.js +32 -0
- package/components/modal/modal.js +3 -1
- package/components/modal/modal.spec.js +46 -0
- package/components/nav/nav.js +3 -1
- package/components/nav/nav.spec.js +33 -0
- package/components/number-picker/number-picker-element.js +3 -1
- package/components/number-picker/number-picker-element.spec.js +30 -0
- package/components/number-picker/number-picker.js +3 -1
- package/components/number-picker/number-picker.spec.js +30 -0
- package/components/order-switch/order-switch.js +3 -1
- package/components/order-switch/order-switch.spec.js +31 -0
- package/components/otp-input/otp-input.js +3 -1
- package/components/otp-input/otp-input.spec.js +41 -0
- package/components/pages/pages.js +3 -1
- package/components/pages/pages.spec.js +44 -0
- package/components/password/password.js +3 -1
- package/components/password/password.spec.js +35 -0
- package/components/progress-bar/progress-bar.js +3 -1
- package/components/progress-bar/progress-bar.spec.js +28 -0
- package/components/radio-group/radio-group.js +3 -1
- package/components/radio-group/radio-group.spec.js +44 -0
- package/components/radio-group/radio.js +3 -1
- package/components/radio-group/radio.spec.js +32 -0
- package/components/range/range.js +3 -1
- package/components/range/range.spec.js +36 -0
- package/components/rating/rating.js +3 -1
- package/components/rating/rating.spec.js +34 -0
- package/components/rating/star.js +3 -1
- package/components/rating/star.spec.js +30 -0
- package/components/rating-scale-question/rating-scale-option.js +3 -1
- package/components/rating-scale-question/rating-scale-option.spec.js +32 -0
- package/components/rating-scale-question/rating-scale-question.js +3 -1
- package/components/rating-scale-question/rating-scale-question.spec.js +35 -0
- package/components/select/__screenshots__/select-ajax-overlay.spec.js/dile-select-ajax-overlay-Selecting-a-result-clearing-the-selection-returns-to-the-search-field-1.png +0 -0
- package/components/select/__screenshots__/select-ajax-overlay.spec.js/dile-select-ajax-overlay-Selecting-a-result-selecting-an-option-sets-value-selectedText--closes-the-popup-and-fires-events-1.png +0 -0
- package/components/select/__screenshots__/select-ajax-overlay.spec.js/dile-select-ajax-overlay-Selecting-a-result-shows-the-read-only-field-with-the-clear-icon-after-selecting-1.png +0 -0
- package/components/select/__screenshots__/select-ajax-overlay.spec.js/dile-select-ajax-overlay-static-mode-loads-all-data-on-init-and-renders-it-inline-without-requiring-a-search-1.png +0 -0
- package/components/select/__screenshots__/select-ajax-overlay.spec.js/dile-select-ajax-overlay-static-mode-shows-a-visible--clickable-trigger-instead-of-hiding-it--there-is-no-separate-search-field-to-compose-under--1.png +0 -0
- package/components/select/__screenshots__/select-overlay.spec.js/dile-select-overlay-Positioning-keeps-the-same-moveTop-tightened-gap-when-flipping-above-the-trigger-as-when-sitting-below-it-1.png +0 -0
- package/components/select/__screenshots__/select-overlay.spec.js/dile-select-overlay-Rendering-throws-when-no-select-element-is-slotted-1.png +0 -0
- package/components/select/__screenshots__/select-overlay.spec.js/dile-select-overlay-hideTrigger-handleExternalKeydown---drives-navigation-without-a-visible-trigger-1.png +0 -0
- package/components/select/__screenshots__/zzdebug2.spec.js/debug-static-debug-1.png +0 -0
- package/components/select/__screenshots__/zzdebug3.spec.js/debug-rapid-close-reopen-reproduces-blur-then-quick-refocus-1.png +0 -0
- package/components/select/index.js +3 -1
- package/components/select/select-ajax-overlay.js +6 -0
- package/components/select/select-ajax-overlay.spec.js +389 -0
- package/components/select/select-ajax.js +3 -1
- package/components/select/select-boolean.js +3 -1
- package/components/select/select-overlay.js +5 -0
- package/components/select/select-overlay.spec.js +507 -0
- package/components/select/select.js +3 -1
- package/components/select/src/DileSelectAjaxOverlay.js +521 -0
- package/components/select/src/DileSelectOverlay.js +511 -0
- package/components/selector/selector-item.js +3 -1
- package/components/selector/selector-item.spec.js +40 -0
- package/components/selector/selector-overlay.js +3 -1
- package/components/selector/selector.js +3 -1
- package/components/selector/selector.spec.js +45 -0
- package/components/slide-menu/slide-menu.js +3 -1
- package/components/slide-menu/slide-menu.spec.js +38 -0
- package/components/slide-show/slide-show.js +3 -1
- package/components/slide-show/slide-show.spec.js +34 -0
- package/components/social-icon/social-icon.js +3 -1
- package/components/social-icon/social-icon.spec.js +26 -0
- package/components/spinner/spinner-bar.js +3 -1
- package/components/spinner/spinner-bar.spec.js +26 -0
- package/components/spinner/spinner-block.js +3 -1
- package/components/spinner/spinner-block.spec.js +21 -0
- package/components/spinner/spinner-horizontal.js +3 -1
- package/components/spinner/spinner-horizontal.spec.js +25 -0
- package/components/spinner/spinner-icon.js +3 -1
- package/components/spinner/spinner-icon.spec.js +25 -0
- package/components/spinner/spinner-modal.js +3 -1
- package/components/spinner/spinner-modal.spec.js +26 -0
- package/components/spinner/spinner.js +3 -1
- package/components/spinner/spinner.spec.js +26 -0
- package/components/switch/switch.js +3 -1
- package/components/switch/switch.spec.js +33 -0
- package/components/tabs/tab.js +3 -1
- package/components/tabs/tabs.js +3 -1
- package/components/tabs/tabs.spec.js +45 -0
- package/components/textarea/textarea.js +3 -1
- package/components/textarea/textarea.spec.js +39 -0
- package/components/time-picker/time-picker.js +3 -1
- package/components/time-picker/time-picker.spec.js +26 -0
- package/components/timer/timer.js +3 -1
- package/components/timer/timer.spec.js +31 -0
- package/components/toast/toast-item.js +3 -1
- package/components/toast/toast-persistent.js +3 -1
- package/components/toast/toast.js +3 -1
- package/components/tooltip/chip-tooltip.js +3 -1
- package/components/tooltip/chip-tooltip.spec.js +29 -0
- package/components/tooltip/tooltip.js +3 -1
- package/components/tooltip/tooltip.spec.js +32 -0
- package/components/web-visor/web-visor.js +3 -1
- package/components/web-visor/web-visor.spec.js +32 -0
- package/mixins/overlay/src/DileOverlay.js +9 -6
- package/package.json +3 -3
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
import { LitElement, html, css } from "lit";
|
|
2
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
+
import { DileEmmitChange } from '../../../mixins/form/index.js';
|
|
4
|
+
import { DileOverlay } from '../../../mixins/overlay/index.js';
|
|
5
|
+
import { DileCloseDocumentClick } from '../../../mixins/close-document-click/index.js';
|
|
6
|
+
import { labelStyles, messageStyles } from '../../input/index.js';
|
|
7
|
+
|
|
8
|
+
const TYPEAHEAD_RESET_DELAY = 500;
|
|
9
|
+
|
|
10
|
+
export class DileSelectOverlay extends DileOverlay(DileCloseDocumentClick(DileEmmitChange(LitElement))) {
|
|
11
|
+
static get styles() {
|
|
12
|
+
return [
|
|
13
|
+
labelStyles,
|
|
14
|
+
messageStyles,
|
|
15
|
+
css`
|
|
16
|
+
* {
|
|
17
|
+
box-sizing: border-box;
|
|
18
|
+
}
|
|
19
|
+
:host {
|
|
20
|
+
display: block;
|
|
21
|
+
margin-bottom: 10px;
|
|
22
|
+
}
|
|
23
|
+
.select-wrapper {
|
|
24
|
+
position: relative;
|
|
25
|
+
display: block;
|
|
26
|
+
width: 100%;
|
|
27
|
+
}
|
|
28
|
+
#trigger {
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
justify-content: space-between;
|
|
32
|
+
gap: 0.5rem;
|
|
33
|
+
width: var(--dile-input-width, 100%);
|
|
34
|
+
padding: var(--dile-input-padding, 7px 5px);
|
|
35
|
+
line-height: var(--dile-input-line-height, 1.5em);
|
|
36
|
+
font-size: var(--dile-select-font-size, 0.875em);
|
|
37
|
+
font-family: inherit;
|
|
38
|
+
border-radius: var(--dile-input-border-radius, 5px);
|
|
39
|
+
border: var(--dile-input-border-width, 1px) solid var(--dile-input-border-color, #888);
|
|
40
|
+
background-color: var(--dile-input-background-color, #fff);
|
|
41
|
+
color: var(--dile-input-color, #303030);
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
text-align: left;
|
|
44
|
+
}
|
|
45
|
+
#trigger:disabled {
|
|
46
|
+
background-color: #f5f5f5;
|
|
47
|
+
border-color: var(--dile-input-disabled-border-color, #eee);
|
|
48
|
+
cursor: not-allowed;
|
|
49
|
+
}
|
|
50
|
+
#trigger:focus-visible {
|
|
51
|
+
outline: var(--dile-input-focus-ring-width, 3px) solid var(--dile-input-focus-ring-color, rgba(102, 170, 255, 0.5));
|
|
52
|
+
outline-offset: calc(-1 * var(--dile-input-focus-ring-width, 3px));
|
|
53
|
+
border-color: var(--dile-input-focus-border-color, var(--dile-link-color, #6af));
|
|
54
|
+
}
|
|
55
|
+
#trigger.errored {
|
|
56
|
+
border-color: var(--dile-input-error-border-color, #c00);
|
|
57
|
+
}
|
|
58
|
+
:host([hideTrigger]) #trigger {
|
|
59
|
+
/* Keep the full width (used to size/position the popup) but collapse
|
|
60
|
+
vertically and hide visually, since a parent composer supplies its
|
|
61
|
+
own visible control and drives open()/close() directly. */
|
|
62
|
+
height: 0;
|
|
63
|
+
padding-top: 0;
|
|
64
|
+
padding-bottom: 0;
|
|
65
|
+
border-top: 0;
|
|
66
|
+
border-bottom: 0;
|
|
67
|
+
overflow: hidden;
|
|
68
|
+
opacity: 0;
|
|
69
|
+
pointer-events: none;
|
|
70
|
+
}
|
|
71
|
+
.trigger-text {
|
|
72
|
+
overflow: hidden;
|
|
73
|
+
text-overflow: ellipsis;
|
|
74
|
+
white-space: nowrap;
|
|
75
|
+
}
|
|
76
|
+
.trigger-text.placeholder {
|
|
77
|
+
color: var(--dile-input-placeholder-color, #ccc);
|
|
78
|
+
}
|
|
79
|
+
.arrow-icon {
|
|
80
|
+
width: 18px;
|
|
81
|
+
height: 18px;
|
|
82
|
+
flex: none;
|
|
83
|
+
display: flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
justify-content: center;
|
|
86
|
+
}
|
|
87
|
+
.arrow-icon svg {
|
|
88
|
+
width: 100%;
|
|
89
|
+
height: 100%;
|
|
90
|
+
}
|
|
91
|
+
.arrow-icon path {
|
|
92
|
+
fill: var(--dile-select-arrow-color, #303030);
|
|
93
|
+
}
|
|
94
|
+
#overlay {
|
|
95
|
+
margin: 0;
|
|
96
|
+
list-style: none;
|
|
97
|
+
display: none;
|
|
98
|
+
position: absolute;
|
|
99
|
+
opacity: 0;
|
|
100
|
+
box-sizing: border-box;
|
|
101
|
+
z-index: var(--dile-select-overlay-z-index, 999);
|
|
102
|
+
color: var(--dile-select-overlay-color, #303030);
|
|
103
|
+
background-color: var(--dile-select-overlay-background-color, #fff);
|
|
104
|
+
border-radius: var(--dile-select-overlay-border-radius, 5px);
|
|
105
|
+
max-height: var(--dile-select-overlay-max-height, 260px);
|
|
106
|
+
overflow-y: auto;
|
|
107
|
+
box-shadow: var(--dile-select-overlay-box-shadow, 0 4px 10px rgba(0, 0, 0, 0.15));
|
|
108
|
+
padding: var(--dile-select-overlay-padding, 4px 0);
|
|
109
|
+
transition: var(--dile-select-overlay-transition, ease 0.2s);
|
|
110
|
+
transition-property: transform, opacity;
|
|
111
|
+
transform: translateY(-6px);
|
|
112
|
+
}
|
|
113
|
+
#overlay.opened {
|
|
114
|
+
opacity: 1;
|
|
115
|
+
transform: translateY(0);
|
|
116
|
+
}
|
|
117
|
+
.option {
|
|
118
|
+
padding: var(--dile-select-overlay-option-padding, 7px 10px);
|
|
119
|
+
cursor: pointer;
|
|
120
|
+
color: var(--dile-select-overlay-color, #303030);
|
|
121
|
+
}
|
|
122
|
+
.option.highlighted {
|
|
123
|
+
background-color: var(--dile-select-overlay-highlighted-background-color, #eef6ff);
|
|
124
|
+
}
|
|
125
|
+
.option[aria-selected="true"] {
|
|
126
|
+
font-weight: var(--dile-select-overlay-selected-font-weight, 600);
|
|
127
|
+
}
|
|
128
|
+
@media (forced-colors: active) {
|
|
129
|
+
#trigger {
|
|
130
|
+
border-width: var(--dile-input-border-width, 1px);
|
|
131
|
+
}
|
|
132
|
+
#trigger:focus-visible {
|
|
133
|
+
outline: 3px solid;
|
|
134
|
+
}
|
|
135
|
+
.arrow-icon {
|
|
136
|
+
forced-color-adjust: none;
|
|
137
|
+
color: CanvasText;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
`];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static get formAssociated() {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static get properties() {
|
|
148
|
+
return {
|
|
149
|
+
label: { type: String },
|
|
150
|
+
value: { type: String },
|
|
151
|
+
name: { type: String, reflect: true },
|
|
152
|
+
disabled: { type: Boolean },
|
|
153
|
+
errored: { type: Boolean },
|
|
154
|
+
message: { type: String },
|
|
155
|
+
hideErrorOnInput: { type: Boolean },
|
|
156
|
+
quietOnStart: { type: Boolean },
|
|
157
|
+
/** Text shown on the trigger when no option is selected. Empty by default, matching
|
|
158
|
+
* dile-select's native <select> (which shows whichever option ends up selected). */
|
|
159
|
+
placeholder: { type: String },
|
|
160
|
+
/** Suppresses the visible trigger box, letting a parent component drive open()/close()
|
|
161
|
+
* and forward keyboard events via handleExternalKeydown() while supplying its own visible control. */
|
|
162
|
+
hideTrigger: { type: Boolean, reflect: true },
|
|
163
|
+
_activeIndex: { state: true },
|
|
164
|
+
/** Display text of the currently highlighted option, readable by an external composer. */
|
|
165
|
+
highlightedText: { state: true },
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
constructor() {
|
|
170
|
+
super();
|
|
171
|
+
this.errored = false;
|
|
172
|
+
this.hideErrorOnInput = false;
|
|
173
|
+
this.hideTrigger = false;
|
|
174
|
+
this.placeholder = '';
|
|
175
|
+
// Sit closer to the trigger than DileOverlay's 10px default gap.
|
|
176
|
+
this.moveTop = -8;
|
|
177
|
+
this.quiet = false;
|
|
178
|
+
this._activeIndex = -1;
|
|
179
|
+
this.highlightedText = '';
|
|
180
|
+
this._typeaheadQuery = '';
|
|
181
|
+
this._typeaheadTimeout = null;
|
|
182
|
+
this.internals = this.attachInternals();
|
|
183
|
+
this.selectId = `dile-select-overlay-${Math.random().toString(36).substr(2, 9)}`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
get elselect() {
|
|
187
|
+
return this.querySelector("select");
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
get opened() {
|
|
191
|
+
return this._overlayClass === 'opened' || this._opening;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
get options() {
|
|
195
|
+
return this.elselect
|
|
196
|
+
? Array.from(this.elselect.options).map(o => ({ value: o.value, text: o.textContent }))
|
|
197
|
+
: [];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
get selectedOption() {
|
|
201
|
+
return this.options.find(o => o.value === (this.value ?? ''));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
connectedCallback() {
|
|
205
|
+
super.connectedCallback();
|
|
206
|
+
if (!this.elselect) {
|
|
207
|
+
throw new Error('Use dile-select-overlay with a select element in the slot "select"');
|
|
208
|
+
}
|
|
209
|
+
if (!this.elselect.id) {
|
|
210
|
+
this.elselect.id = this.selectId;
|
|
211
|
+
}
|
|
212
|
+
// Unlike dile-select, the native <select> is never slotted for display (it's only
|
|
213
|
+
// read as the data source), so browser-native slot projection can't keep the popup
|
|
214
|
+
// in sync when a consumer regenerates its <option> children (e.g. dile-select-ajax-overlay
|
|
215
|
+
// re-rendering options after each search). Watch it directly instead.
|
|
216
|
+
this._optionsObserver = new MutationObserver(() => {
|
|
217
|
+
this.requestUpdate();
|
|
218
|
+
// The option count/height can change (e.g. a search narrowing from many results down
|
|
219
|
+
// to one), but DileOverlay only repositions on open/scroll/resize — without this, a
|
|
220
|
+
// popup that flipped above the trigger for a tall list stays anchored at that old top
|
|
221
|
+
// position once it shrinks, leaving it floating detached from the trigger.
|
|
222
|
+
this.updateComplete.then(() => {
|
|
223
|
+
if (this.opened) {
|
|
224
|
+
this.updatePosition();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
this._optionsObserver.observe(this.elselect, { childList: true, subtree: true, characterData: true });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
disconnectedCallback() {
|
|
232
|
+
super.disconnectedCallback();
|
|
233
|
+
if (this._optionsObserver) {
|
|
234
|
+
this._optionsObserver.disconnect();
|
|
235
|
+
}
|
|
236
|
+
if (this._typeaheadTimeout) {
|
|
237
|
+
clearTimeout(this._typeaheadTimeout);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
firstUpdated() {
|
|
242
|
+
super.firstUpdated();
|
|
243
|
+
this.quiet = this.quietOnStart;
|
|
244
|
+
if (this.value) {
|
|
245
|
+
this.elselect.value = this.value;
|
|
246
|
+
} else {
|
|
247
|
+
this.value = this.elselect.value;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Points positioning (open()/updatePosition()'s flip-to-top-or-bottom math) at an external
|
|
253
|
+
* element instead of this component's own trigger. Meant for hideTrigger compositions where
|
|
254
|
+
* a parent's own visible control (e.g. a search field) is the thing the popup should actually
|
|
255
|
+
* avoid covering — the internal trigger is a zero-height point, so flipping "above" it doesn't
|
|
256
|
+
* know to leave room for the parent's real, taller control sitting right before it.
|
|
257
|
+
* Pass no argument (or a falsy value) to revert to this component's own trigger.
|
|
258
|
+
*/
|
|
259
|
+
setTriggerElement(el) {
|
|
260
|
+
this.trigger = el || this.shadowRoot.getElementById('trigger');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
updatePosition() {
|
|
264
|
+
// DileOverlay switches #overlay to position:fixed, so a CSS percentage width
|
|
265
|
+
// would resolve against the viewport instead of the trigger. Match it in JS instead.
|
|
266
|
+
if (this.trigger) {
|
|
267
|
+
this.overlay.style.width = `${this.trigger.getBoundingClientRect().width}px`;
|
|
268
|
+
}
|
|
269
|
+
super.updatePosition();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
updated(changedProperties) {
|
|
273
|
+
if (changedProperties.has("value")) {
|
|
274
|
+
if (this.elselect) {
|
|
275
|
+
this.elselect.value = this.value ?? '';
|
|
276
|
+
}
|
|
277
|
+
if (this.quiet) {
|
|
278
|
+
this.quiet = false;
|
|
279
|
+
} else {
|
|
280
|
+
this.emmitChange();
|
|
281
|
+
}
|
|
282
|
+
this.internals.setFormValue(this.value);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
render() {
|
|
287
|
+
const messageId = this.message ? `${this.selectId}-message` : null;
|
|
288
|
+
return html`
|
|
289
|
+
<div>${this.label
|
|
290
|
+
? html`<label for="trigger">${this.label}</label>`
|
|
291
|
+
: ""
|
|
292
|
+
}<div class="select-wrapper">
|
|
293
|
+
${this.triggerTemplate}
|
|
294
|
+
${this.overlayTemplate}
|
|
295
|
+
</div></div>
|
|
296
|
+
${this.message
|
|
297
|
+
? html`<div class="message ${this.errored ? 'errored-msg' : ''}" id="${messageId}" role="status" aria-live="polite"><span>${this.message}</span></div>`
|
|
298
|
+
: ''
|
|
299
|
+
}
|
|
300
|
+
`;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
get triggerTemplate() {
|
|
304
|
+
const selected = this.selectedOption;
|
|
305
|
+
return html`
|
|
306
|
+
<button
|
|
307
|
+
type="button"
|
|
308
|
+
id="trigger"
|
|
309
|
+
role="combobox"
|
|
310
|
+
aria-haspopup="listbox"
|
|
311
|
+
aria-expanded="${this.opened}"
|
|
312
|
+
aria-controls="overlay"
|
|
313
|
+
aria-activedescendant="${ifDefined(this._activeIndex >= 0 ? this._optionId(this._activeIndex) : undefined)}"
|
|
314
|
+
aria-invalid="${this.errored}"
|
|
315
|
+
aria-describedby="${ifDefined(this.message ? `${this.selectId}-message` : undefined)}"
|
|
316
|
+
?disabled="${this.disabled}"
|
|
317
|
+
tabindex="${this.hideTrigger ? '-1' : '0'}"
|
|
318
|
+
class="${this.errored ? 'errored' : ''}"
|
|
319
|
+
@click="${this._onTriggerClick}"
|
|
320
|
+
@keydown="${this.handleExternalKeydown}"
|
|
321
|
+
>
|
|
322
|
+
<span class="trigger-text ${selected ? '' : 'placeholder'}">${selected ? selected.text : this.placeholder}</span>
|
|
323
|
+
<span class="arrow-icon" aria-hidden="true">
|
|
324
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 448" enable-background="new 0 0 256 448">
|
|
325
|
+
<path d="M255.9 168c0-4.2-1.6-7.9-4.8-11.2-3.2-3.2-6.9-4.8-11.2-4.8H16c-4.2 0-7.9 1.6-11.2 4.8S0 163.8 0 168c0 4.4 1.6 8.2 4.8 11.4l112 112c3.1 3.1 6.8 4.6 11.2 4.6 4.4 0 8.2-1.5 11.4-4.6l112-112c3-3.2 4.5-7 4.5-11.4z"></path>
|
|
326
|
+
</svg>
|
|
327
|
+
</span>
|
|
328
|
+
</button>
|
|
329
|
+
`;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
get overlayTemplate() {
|
|
333
|
+
const options = this.options;
|
|
334
|
+
return html`
|
|
335
|
+
<ul id="overlay" class="${this._overlayClass}" role="listbox">
|
|
336
|
+
${options.map((opt, index) => html`
|
|
337
|
+
<li
|
|
338
|
+
id="${this._optionId(index)}"
|
|
339
|
+
role="option"
|
|
340
|
+
class="option ${index === this._activeIndex ? 'highlighted' : ''}"
|
|
341
|
+
aria-selected="${opt.value === (this.value ?? '')}"
|
|
342
|
+
@click="${() => this.selectOption(index)}"
|
|
343
|
+
@mousemove="${() => this._setActiveIndex(index, false)}"
|
|
344
|
+
>${opt.text}</li>
|
|
345
|
+
`)}
|
|
346
|
+
</ul>
|
|
347
|
+
`;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
_optionId(index) {
|
|
351
|
+
return `${this.selectId}-option-${index}`;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
_indexForValue(value) {
|
|
355
|
+
return this.options.findIndex(o => o.value === (value ?? ''));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
_setActiveIndex(index, scroll = true) {
|
|
359
|
+
this._activeIndex = index;
|
|
360
|
+
const opt = this.options[index];
|
|
361
|
+
this.highlightedText = opt ? opt.text : '';
|
|
362
|
+
if (scroll) {
|
|
363
|
+
this.updateComplete.then(() => {
|
|
364
|
+
const el = this.shadowRoot.getElementById(this._optionId(index));
|
|
365
|
+
if (el) {
|
|
366
|
+
el.scrollIntoView({ block: 'nearest' });
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
_moveActiveIndex(delta, options = this.options) {
|
|
373
|
+
if (!options.length) return;
|
|
374
|
+
let next = this._activeIndex;
|
|
375
|
+
if (next < 0) {
|
|
376
|
+
next = delta > 0 ? 0 : options.length - 1;
|
|
377
|
+
} else {
|
|
378
|
+
next = Math.min(Math.max(next + delta, 0), options.length - 1);
|
|
379
|
+
}
|
|
380
|
+
this._setActiveIndex(next);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
_onTriggerClick() {
|
|
384
|
+
if (this.disabled) return;
|
|
385
|
+
const wasOpen = this.opened;
|
|
386
|
+
this.toggle();
|
|
387
|
+
if (!wasOpen) {
|
|
388
|
+
this._setActiveIndex(this._indexForValue(this.value), false);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
handleExternalKeydown(e) {
|
|
393
|
+
if (this.disabled) return;
|
|
394
|
+
const options = this.options;
|
|
395
|
+
|
|
396
|
+
switch (e.key) {
|
|
397
|
+
case 'ArrowDown':
|
|
398
|
+
case 'ArrowUp': {
|
|
399
|
+
e.preventDefault();
|
|
400
|
+
const wasOpen = this.opened;
|
|
401
|
+
if (!wasOpen) {
|
|
402
|
+
this.open();
|
|
403
|
+
this._setActiveIndex(this._indexForValue(this.value), false);
|
|
404
|
+
}
|
|
405
|
+
this._moveActiveIndex(e.key === 'ArrowDown' ? 1 : -1, options);
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
case 'Home':
|
|
409
|
+
e.preventDefault();
|
|
410
|
+
if (!this.opened) this.open();
|
|
411
|
+
this._setActiveIndex(0);
|
|
412
|
+
break;
|
|
413
|
+
case 'End':
|
|
414
|
+
e.preventDefault();
|
|
415
|
+
if (!this.opened) this.open();
|
|
416
|
+
this._setActiveIndex(options.length - 1);
|
|
417
|
+
break;
|
|
418
|
+
case 'Enter':
|
|
419
|
+
case ' ':
|
|
420
|
+
e.preventDefault();
|
|
421
|
+
if (this.opened) {
|
|
422
|
+
if (this._activeIndex >= 0) {
|
|
423
|
+
this.selectOption(this._activeIndex);
|
|
424
|
+
} else {
|
|
425
|
+
this.close();
|
|
426
|
+
}
|
|
427
|
+
} else {
|
|
428
|
+
this._onTriggerClick();
|
|
429
|
+
}
|
|
430
|
+
break;
|
|
431
|
+
case 'Escape':
|
|
432
|
+
if (this.opened) {
|
|
433
|
+
e.preventDefault();
|
|
434
|
+
this.close();
|
|
435
|
+
}
|
|
436
|
+
break;
|
|
437
|
+
case 'Tab':
|
|
438
|
+
this.close();
|
|
439
|
+
break;
|
|
440
|
+
default:
|
|
441
|
+
if (e.key && e.key.length === 1 && /\S/.test(e.key)) {
|
|
442
|
+
this._handleTypeahead(e.key, options);
|
|
443
|
+
}
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
_handleTypeahead(char, options = this.options) {
|
|
449
|
+
if (!options.length) return;
|
|
450
|
+
if (this._typeaheadTimeout) {
|
|
451
|
+
clearTimeout(this._typeaheadTimeout);
|
|
452
|
+
}
|
|
453
|
+
this._typeaheadQuery += char.toLowerCase();
|
|
454
|
+
this._typeaheadTimeout = setTimeout(() => {
|
|
455
|
+
this._typeaheadQuery = '';
|
|
456
|
+
}, TYPEAHEAD_RESET_DELAY);
|
|
457
|
+
|
|
458
|
+
const currentIndex = this.opened ? this._activeIndex : this._indexForValue(this.value);
|
|
459
|
+
const startFrom = currentIndex >= 0 ? currentIndex + 1 : 0;
|
|
460
|
+
const ordered = [...options.slice(startFrom), ...options.slice(0, startFrom)];
|
|
461
|
+
const relativeMatch = ordered.findIndex(o => o.text.toLowerCase().startsWith(this._typeaheadQuery));
|
|
462
|
+
if (relativeMatch < 0) return;
|
|
463
|
+
|
|
464
|
+
const matchIndex = (startFrom + relativeMatch) % options.length;
|
|
465
|
+
if (this.opened) {
|
|
466
|
+
this._setActiveIndex(matchIndex);
|
|
467
|
+
} else {
|
|
468
|
+
this.selectOption(matchIndex);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
selectOption(index) {
|
|
473
|
+
const opt = this.options[index];
|
|
474
|
+
if (!opt) return;
|
|
475
|
+
this.value = opt.value;
|
|
476
|
+
this.close();
|
|
477
|
+
this.hideErrorOnInteraction();
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
hideErrorOnInteraction() {
|
|
481
|
+
if (this.hideErrorOnInput && this.errored) {
|
|
482
|
+
this.errored = false;
|
|
483
|
+
this.message = '';
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
close() {
|
|
488
|
+
super.close();
|
|
489
|
+
this._activeIndex = -1;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
clear() {
|
|
493
|
+
this.value = undefined;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
getOptionByValue(id) {
|
|
497
|
+
let options = this.elselect.options;
|
|
498
|
+
for (let i = 0; i < options.length; i++) {
|
|
499
|
+
if (options[i].value === id) {
|
|
500
|
+
return options[i];
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
quietChange(value) {
|
|
506
|
+
if (value != this.value) {
|
|
507
|
+
this.quiet = true;
|
|
508
|
+
this.value = value;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './selector-item.js';
|
|
3
|
+
|
|
4
|
+
describe('dile-selector-item', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
document.body.innerHTML = '';
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function renderSelectorItem(html) {
|
|
10
|
+
document.body.innerHTML = html;
|
|
11
|
+
const el = document.body.querySelector('dile-selector-item');
|
|
12
|
+
await el.updateComplete;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('renders the slotted content and starts unselected', async () => {
|
|
17
|
+
const el = await renderSelectorItem('<dile-selector-item>Option A</dile-selector-item>');
|
|
18
|
+
|
|
19
|
+
expect(el.selected).toBe(false);
|
|
20
|
+
expect(el.textContent.trim()).toBe('Option A');
|
|
21
|
+
expect(el.shadowRoot.querySelector('article')).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('dispatches dile-item-selected with itself when clicked', async () => {
|
|
25
|
+
const el = await renderSelectorItem('<dile-selector-item>Option A</dile-selector-item>');
|
|
26
|
+
let detail = null;
|
|
27
|
+
el.addEventListener('dile-item-selected', (e) => { detail = e.detail; });
|
|
28
|
+
|
|
29
|
+
el.shadowRoot.querySelector('article').click();
|
|
30
|
+
|
|
31
|
+
expect(detail).toBe(el);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('wraps content in a link when href is set', async () => {
|
|
35
|
+
const el = await renderSelectorItem('<dile-selector-item href="/foo">Go</dile-selector-item>');
|
|
36
|
+
const link = el.shadowRoot.querySelector('a');
|
|
37
|
+
expect(link).toBeTruthy();
|
|
38
|
+
expect(link.getAttribute('href')).toBe('/foo');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { DileSelectorOverlay } from "./src/DileSelectorOverlay.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
if (!customElements.get("dile-selector-overlay")) {
|
|
4
|
+
window.customElements.define("dile-selector-overlay", DileSelectorOverlay);
|
|
5
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './selector.js';
|
|
3
|
+
import './selector-item.js';
|
|
4
|
+
|
|
5
|
+
describe('dile-selector', () => {
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
document.body.innerHTML = '';
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
async function renderSelector(html) {
|
|
11
|
+
document.body.innerHTML = html;
|
|
12
|
+
const el = document.body.querySelector('dile-selector');
|
|
13
|
+
await el.updateComplete;
|
|
14
|
+
return el;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
it('renders a slot with the selector items', async () => {
|
|
18
|
+
const el = await renderSelector(`
|
|
19
|
+
<dile-selector>
|
|
20
|
+
<dile-selector-item>One</dile-selector-item>
|
|
21
|
+
<dile-selector-item>Two</dile-selector-item>
|
|
22
|
+
</dile-selector>
|
|
23
|
+
`);
|
|
24
|
+
|
|
25
|
+
expect(el.shadowRoot.querySelector('slot')).toBeTruthy();
|
|
26
|
+
expect(el.querySelectorAll('dile-selector-item').length).toBe(2);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('selects an item by index when clicked, marking it selected', async () => {
|
|
30
|
+
const el = await renderSelector(`
|
|
31
|
+
<dile-selector>
|
|
32
|
+
<dile-selector-item>One</dile-selector-item>
|
|
33
|
+
<dile-selector-item>Two</dile-selector-item>
|
|
34
|
+
</dile-selector>
|
|
35
|
+
`);
|
|
36
|
+
|
|
37
|
+
const items = el.querySelectorAll('dile-selector-item');
|
|
38
|
+
items[1].shadowRoot.querySelector('article').click();
|
|
39
|
+
await el.updateComplete;
|
|
40
|
+
|
|
41
|
+
expect(el.selected).toBe(1);
|
|
42
|
+
expect(items[1].selected).toBe(true);
|
|
43
|
+
expect(items[0].selected).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './slide-menu.js';
|
|
3
|
+
|
|
4
|
+
describe('dile-slide-menu', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
document.body.innerHTML = '';
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function renderSlideMenu(html) {
|
|
10
|
+
document.body.innerHTML = html;
|
|
11
|
+
const el = document.body.querySelector('dile-slide-menu');
|
|
12
|
+
await el.updateComplete;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('renders closed by default with a nav control', async () => {
|
|
17
|
+
const el = await renderSlideMenu('<dile-slide-menu>Content</dile-slide-menu>');
|
|
18
|
+
expect(el.opened).toBe(false);
|
|
19
|
+
|
|
20
|
+
const nav = el.shadowRoot.querySelector('nav');
|
|
21
|
+
expect(nav).toBeTruthy();
|
|
22
|
+
expect(nav.getAttribute('aria-expanded')).toBe('false');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('opens when toggled', async () => {
|
|
26
|
+
const el = await renderSlideMenu('<dile-slide-menu>Content</dile-slide-menu>');
|
|
27
|
+
el.toggle();
|
|
28
|
+
await el.updateComplete;
|
|
29
|
+
|
|
30
|
+
expect(el.opened).toBe(true);
|
|
31
|
+
expect(el.shadowRoot.querySelector('nav').getAttribute('aria-expanded')).toBe('true');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('uses the label property in the nav control', async () => {
|
|
35
|
+
const el = await renderSlideMenu('<dile-slide-menu label="Options">Content</dile-slide-menu>');
|
|
36
|
+
expect(el.shadowRoot.querySelector('nav').getAttribute('aria-label')).toBe('Options');
|
|
37
|
+
});
|
|
38
|
+
});
|