@ucalgary-design-system/dropdown 1.0.3 → 1.0.4

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/index.js +121 -465
  3. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @ucalgary-design-system/dropdown
2
2
 
3
+ ## 1.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - fe87dab: Updated externalized dependencies
8
+ - Updated dependencies [fe87dab]
9
+ - @ucalgary-design-system/icon@1.0.4
10
+ - @ucalgary-design-system/core@1.0.4
11
+ - @ucalgary-design-system/tokens@1.0.4
12
+
3
13
  ## 1.0.3
4
14
 
5
15
  ### Patch Changes
package/index.js CHANGED
@@ -1,360 +1,16 @@
1
- import { unsafeCSS as A, nothing as v, html as y } from "lit";
2
- import { classMap as M } from "lit/directives/class-map.js";
3
- import { BaseElement as _ } from "@ucalgary-design-system/core";
1
+ import { unsafeCSS as v, nothing as u, html as p } from "lit";
2
+ import { property as a, state as b, queryAssignedElements as x, customElement as w } from "lit/decorators.js";
3
+ import { classMap as y } from "lit/directives/class-map.js";
4
+ import { BaseElement as m } from "@ucalgary-design-system/core";
4
5
  import "@ucalgary-design-system/helper-components";
5
6
  import "@ucalgary-design-system/icon";
6
- /**
7
- * @license
8
- * Copyright 2017 Google LLC
9
- * SPDX-License-Identifier: BSD-3-Clause
10
- */
11
- const I = (s) => (e, t) => {
12
- t !== void 0 ? t.addInitializer(() => {
13
- customElements.define(s, e);
14
- }) : customElements.define(s, e);
7
+ const _ = ':host{position:relative;display:block}.dropdown-wrapper{display:flex;flex-direction:column;gap:8px;align-items:start}.dropdown,.menu,.toggle,.dropdown-wrapper{min-width:115px;max-width:var(--ucds-form-element-maxwidth);width:var(--ucds-form-element-width)}.dropdown{position:relative}.toggle{display:flex;align-items:center;justify-content:space-between;gap:16px;height:48px;padding:0 var(--ucds-form-element-horizontal-padding);font-family:var(--ucds-font-family-sans-serif);font-size:var(--ucds-font-base-size);border:var(--ucds-color-forms-input-border-rest) solid var(--ucds-form-element-border-width);border-radius:var(--ucds-form-element-border-radius);background-color:var(--ucds-color-forms-input-background-rest)}.toggle:focus{outline:var(--ucds-color-action-focus) 2px solid;outline-offset:2px}.toggle .selected-label-wrapper{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.toggle ucds-icon{color:var(--ucds-color-action-rest);transition:transform .5s ease}.toggle.error{background-color:var(--ucds-color-feedback-error-background-light);border-color:var(--ucds-color-feedback-error-light)}.toggle:hover{border-color:var(--ucds-color-forms-input-border-hover);cursor:pointer}.toggle.disabled{border-color:var(--ucds-color-forms-input-border-disabled);color:var(--ucds-color-text-disabled);cursor:not-allowed;pointer-events:none}.toggle.disabled ucds-icon{color:var(--ucds-color-forms-input-element-disabled)}.menu{position:absolute;background:var(--ucds-color-forms-input-background-rest);border:var(--ucds-color-forms-input-border-rest) solid var(--ucds-form-element-border-width);border-radius:var(--ucds-form-element-border-radius);display:none;cursor:pointer;list-style:none;margin:0;padding:12px;flex-direction:column;gap:8px;overflow-y:auto;z-index:100;-webkit-overflow-scrolling:touch;scroll-behavior:smooth}:host([open]) .menu{display:flex}:host([open]) ucds-icon{transform:rotateX(180deg)}:host([data-open-direction="up"]) .menu{bottom:calc(100% + 8px)}:host([data-open-direction="down"]) .menu{top:calc(100% + 8px)}';
8
+ var k = Object.defineProperty, I = Object.getOwnPropertyDescriptor, d = (e, t, i, o) => {
9
+ for (var s = o > 1 ? void 0 : o ? I(t, i) : t, r = e.length - 1, n; r >= 0; r--)
10
+ (n = e[r]) && (s = (o ? n(t, i, s) : n(s)) || s);
11
+ return o && s && k(t, i, s), s;
15
12
  };
16
- /**
17
- * @license
18
- * Copyright 2019 Google LLC
19
- * SPDX-License-Identifier: BSD-3-Clause
20
- */
21
- const w = globalThis, x = w.ShadowRoot && (w.ShadyCSS === void 0 || w.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, L = Symbol(), C = /* @__PURE__ */ new WeakMap();
22
- let D = class {
23
- constructor(e, t, i) {
24
- if (this._$cssResult$ = !0, i !== L) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
25
- this.cssText = e, this.t = t;
26
- }
27
- get styleSheet() {
28
- let e = this.o;
29
- const t = this.t;
30
- if (x && e === void 0) {
31
- const i = t !== void 0 && t.length === 1;
32
- i && (e = C.get(t)), e === void 0 && ((this.o = e = new CSSStyleSheet()).replaceSync(this.cssText), i && C.set(t, e));
33
- }
34
- return e;
35
- }
36
- toString() {
37
- return this.cssText;
38
- }
39
- };
40
- const R = (s) => new D(typeof s == "string" ? s : s + "", void 0, L), z = (s, e) => {
41
- if (x) s.adoptedStyleSheets = e.map((t) => t instanceof CSSStyleSheet ? t : t.styleSheet);
42
- else for (const t of e) {
43
- const i = document.createElement("style"), o = w.litNonce;
44
- o !== void 0 && i.setAttribute("nonce", o), i.textContent = t.cssText, s.appendChild(i);
45
- }
46
- }, O = x ? (s) => s : (s) => s instanceof CSSStyleSheet ? ((e) => {
47
- let t = "";
48
- for (const i of e.cssRules) t += i.cssText;
49
- return R(t);
50
- })(s) : s;
51
- /**
52
- * @license
53
- * Copyright 2017 Google LLC
54
- * SPDX-License-Identifier: BSD-3-Clause
55
- */
56
- const { is: j, defineProperty: q, getOwnPropertyDescriptor: T, getOwnPropertyNames: B, getOwnPropertySymbols: H, getPrototypeOf: V } = Object, u = globalThis, k = u.trustedTypes, K = k ? k.emptyScript : "", $ = u.reactiveElementPolyfillSupport, f = (s, e) => s, g = { toAttribute(s, e) {
57
- switch (e) {
58
- case Boolean:
59
- s = s ? K : null;
60
- break;
61
- case Object:
62
- case Array:
63
- s = s == null ? s : JSON.stringify(s);
64
- }
65
- return s;
66
- }, fromAttribute(s, e) {
67
- let t = s;
68
- switch (e) {
69
- case Boolean:
70
- t = s !== null;
71
- break;
72
- case Number:
73
- t = s === null ? null : Number(s);
74
- break;
75
- case Object:
76
- case Array:
77
- try {
78
- t = JSON.parse(s);
79
- } catch {
80
- t = null;
81
- }
82
- }
83
- return t;
84
- } }, E = (s, e) => !j(s, e), P = { attribute: !0, type: String, converter: g, reflect: !1, useDefault: !1, hasChanged: E };
85
- Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), u.litPropertyMetadata ?? (u.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
86
- class p extends HTMLElement {
87
- static addInitializer(e) {
88
- this._$Ei(), (this.l ?? (this.l = [])).push(e);
89
- }
90
- static get observedAttributes() {
91
- return this.finalize(), this._$Eh && [...this._$Eh.keys()];
92
- }
93
- static createProperty(e, t = P) {
94
- if (t.state && (t.attribute = !1), this._$Ei(), this.prototype.hasOwnProperty(e) && ((t = Object.create(t)).wrapped = !0), this.elementProperties.set(e, t), !t.noAccessor) {
95
- const i = Symbol(), o = this.getPropertyDescriptor(e, i, t);
96
- o !== void 0 && q(this.prototype, e, o);
97
- }
98
- }
99
- static getPropertyDescriptor(e, t, i) {
100
- const { get: o, set: r } = T(this.prototype, e) ?? { get() {
101
- return this[t];
102
- }, set(n) {
103
- this[t] = n;
104
- } };
105
- return { get: o, set(n) {
106
- const a = o == null ? void 0 : o.call(this);
107
- r == null || r.call(this, n), this.requestUpdate(e, a, i);
108
- }, configurable: !0, enumerable: !0 };
109
- }
110
- static getPropertyOptions(e) {
111
- return this.elementProperties.get(e) ?? P;
112
- }
113
- static _$Ei() {
114
- if (this.hasOwnProperty(f("elementProperties"))) return;
115
- const e = V(this);
116
- e.finalize(), e.l !== void 0 && (this.l = [...e.l]), this.elementProperties = new Map(e.elementProperties);
117
- }
118
- static finalize() {
119
- if (this.hasOwnProperty(f("finalized"))) return;
120
- if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(f("properties"))) {
121
- const t = this.properties, i = [...B(t), ...H(t)];
122
- for (const o of i) this.createProperty(o, t[o]);
123
- }
124
- const e = this[Symbol.metadata];
125
- if (e !== null) {
126
- const t = litPropertyMetadata.get(e);
127
- if (t !== void 0) for (const [i, o] of t) this.elementProperties.set(i, o);
128
- }
129
- this._$Eh = /* @__PURE__ */ new Map();
130
- for (const [t, i] of this.elementProperties) {
131
- const o = this._$Eu(t, i);
132
- o !== void 0 && this._$Eh.set(o, t);
133
- }
134
- this.elementStyles = this.finalizeStyles(this.styles);
135
- }
136
- static finalizeStyles(e) {
137
- const t = [];
138
- if (Array.isArray(e)) {
139
- const i = new Set(e.flat(1 / 0).reverse());
140
- for (const o of i) t.unshift(O(o));
141
- } else e !== void 0 && t.push(O(e));
142
- return t;
143
- }
144
- static _$Eu(e, t) {
145
- const i = t.attribute;
146
- return i === !1 ? void 0 : typeof i == "string" ? i : typeof e == "string" ? e.toLowerCase() : void 0;
147
- }
148
- constructor() {
149
- super(), this._$Ep = void 0, this.isUpdatePending = !1, this.hasUpdated = !1, this._$Em = null, this._$Ev();
150
- }
151
- _$Ev() {
152
- var e;
153
- this._$ES = new Promise((t) => this.enableUpdating = t), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), (e = this.constructor.l) == null || e.forEach((t) => t(this));
154
- }
155
- addController(e) {
156
- var t;
157
- (this._$EO ?? (this._$EO = /* @__PURE__ */ new Set())).add(e), this.renderRoot !== void 0 && this.isConnected && ((t = e.hostConnected) == null || t.call(e));
158
- }
159
- removeController(e) {
160
- var t;
161
- (t = this._$EO) == null || t.delete(e);
162
- }
163
- _$E_() {
164
- const e = /* @__PURE__ */ new Map(), t = this.constructor.elementProperties;
165
- for (const i of t.keys()) this.hasOwnProperty(i) && (e.set(i, this[i]), delete this[i]);
166
- e.size > 0 && (this._$Ep = e);
167
- }
168
- createRenderRoot() {
169
- const e = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
170
- return z(e, this.constructor.elementStyles), e;
171
- }
172
- connectedCallback() {
173
- var e;
174
- this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this.enableUpdating(!0), (e = this._$EO) == null || e.forEach((t) => {
175
- var i;
176
- return (i = t.hostConnected) == null ? void 0 : i.call(t);
177
- });
178
- }
179
- enableUpdating(e) {
180
- }
181
- disconnectedCallback() {
182
- var e;
183
- (e = this._$EO) == null || e.forEach((t) => {
184
- var i;
185
- return (i = t.hostDisconnected) == null ? void 0 : i.call(t);
186
- });
187
- }
188
- attributeChangedCallback(e, t, i) {
189
- this._$AK(e, i);
190
- }
191
- _$ET(e, t) {
192
- var r;
193
- const i = this.constructor.elementProperties.get(e), o = this.constructor._$Eu(e, i);
194
- if (o !== void 0 && i.reflect === !0) {
195
- const n = (((r = i.converter) == null ? void 0 : r.toAttribute) !== void 0 ? i.converter : g).toAttribute(t, i.type);
196
- this._$Em = e, n == null ? this.removeAttribute(o) : this.setAttribute(o, n), this._$Em = null;
197
- }
198
- }
199
- _$AK(e, t) {
200
- var r, n;
201
- const i = this.constructor, o = i._$Eh.get(e);
202
- if (o !== void 0 && this._$Em !== o) {
203
- const a = i.getPropertyOptions(o), d = typeof a.converter == "function" ? { fromAttribute: a.converter } : ((r = a.converter) == null ? void 0 : r.fromAttribute) !== void 0 ? a.converter : g;
204
- this._$Em = o;
205
- const b = d.fromAttribute(t, a.type);
206
- this[o] = b ?? ((n = this._$Ej) == null ? void 0 : n.get(o)) ?? b, this._$Em = null;
207
- }
208
- }
209
- requestUpdate(e, t, i) {
210
- var o;
211
- if (e !== void 0) {
212
- const r = this.constructor, n = this[e];
213
- if (i ?? (i = r.getPropertyOptions(e)), !((i.hasChanged ?? E)(n, t) || i.useDefault && i.reflect && n === ((o = this._$Ej) == null ? void 0 : o.get(e)) && !this.hasAttribute(r._$Eu(e, i)))) return;
214
- this.C(e, t, i);
215
- }
216
- this.isUpdatePending === !1 && (this._$ES = this._$EP());
217
- }
218
- C(e, t, { useDefault: i, reflect: o, wrapped: r }, n) {
219
- i && !(this._$Ej ?? (this._$Ej = /* @__PURE__ */ new Map())).has(e) && (this._$Ej.set(e, n ?? t ?? this[e]), r !== !0 || n !== void 0) || (this._$AL.has(e) || (this.hasUpdated || i || (t = void 0), this._$AL.set(e, t)), o === !0 && this._$Em !== e && (this._$Eq ?? (this._$Eq = /* @__PURE__ */ new Set())).add(e));
220
- }
221
- async _$EP() {
222
- this.isUpdatePending = !0;
223
- try {
224
- await this._$ES;
225
- } catch (t) {
226
- Promise.reject(t);
227
- }
228
- const e = this.scheduleUpdate();
229
- return e != null && await e, !this.isUpdatePending;
230
- }
231
- scheduleUpdate() {
232
- return this.performUpdate();
233
- }
234
- performUpdate() {
235
- var i;
236
- if (!this.isUpdatePending) return;
237
- if (!this.hasUpdated) {
238
- if (this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this._$Ep) {
239
- for (const [r, n] of this._$Ep) this[r] = n;
240
- this._$Ep = void 0;
241
- }
242
- const o = this.constructor.elementProperties;
243
- if (o.size > 0) for (const [r, n] of o) {
244
- const { wrapped: a } = n, d = this[r];
245
- a !== !0 || this._$AL.has(r) || d === void 0 || this.C(r, void 0, n, d);
246
- }
247
- }
248
- let e = !1;
249
- const t = this._$AL;
250
- try {
251
- e = this.shouldUpdate(t), e ? (this.willUpdate(t), (i = this._$EO) == null || i.forEach((o) => {
252
- var r;
253
- return (r = o.hostUpdate) == null ? void 0 : r.call(o);
254
- }), this.update(t)) : this._$EM();
255
- } catch (o) {
256
- throw e = !1, this._$EM(), o;
257
- }
258
- e && this._$AE(t);
259
- }
260
- willUpdate(e) {
261
- }
262
- _$AE(e) {
263
- var t;
264
- (t = this._$EO) == null || t.forEach((i) => {
265
- var o;
266
- return (o = i.hostUpdated) == null ? void 0 : o.call(i);
267
- }), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(e)), this.updated(e);
268
- }
269
- _$EM() {
270
- this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1;
271
- }
272
- get updateComplete() {
273
- return this.getUpdateComplete();
274
- }
275
- getUpdateComplete() {
276
- return this._$ES;
277
- }
278
- shouldUpdate(e) {
279
- return !0;
280
- }
281
- update(e) {
282
- this._$Eq && (this._$Eq = this._$Eq.forEach((t) => this._$ET(t, this[t]))), this._$EM();
283
- }
284
- updated(e) {
285
- }
286
- firstUpdated(e) {
287
- }
288
- }
289
- p.elementStyles = [], p.shadowRootOptions = { mode: "open" }, p[f("elementProperties")] = /* @__PURE__ */ new Map(), p[f("finalized")] = /* @__PURE__ */ new Map(), $ == null || $({ ReactiveElement: p }), (u.reactiveElementVersions ?? (u.reactiveElementVersions = [])).push("2.1.1");
290
- /**
291
- * @license
292
- * Copyright 2017 Google LLC
293
- * SPDX-License-Identifier: BSD-3-Clause
294
- */
295
- const N = { attribute: !0, type: String, converter: g, reflect: !1, hasChanged: E }, J = (s = N, e, t) => {
296
- const { kind: i, metadata: o } = t;
297
- let r = globalThis.litPropertyMetadata.get(o);
298
- if (r === void 0 && globalThis.litPropertyMetadata.set(o, r = /* @__PURE__ */ new Map()), i === "setter" && ((s = Object.create(s)).wrapped = !0), r.set(t.name, s), i === "accessor") {
299
- const { name: n } = t;
300
- return { set(a) {
301
- const d = e.get.call(this);
302
- e.set.call(this, a), this.requestUpdate(n, d, s);
303
- }, init(a) {
304
- return a !== void 0 && this.C(n, void 0, s, a), a;
305
- } };
306
- }
307
- if (i === "setter") {
308
- const { name: n } = t;
309
- return function(a) {
310
- const d = this[n];
311
- e.call(this, a), this.requestUpdate(n, d, s);
312
- };
313
- }
314
- throw Error("Unsupported decorator location: " + i);
315
- };
316
- function h(s) {
317
- return (e, t) => typeof t == "object" ? J(s, e, t) : ((i, o, r) => {
318
- const n = o.hasOwnProperty(r);
319
- return o.constructor.createProperty(r, i), n ? Object.getOwnPropertyDescriptor(o, r) : void 0;
320
- })(s, e, t);
321
- }
322
- /**
323
- * @license
324
- * Copyright 2017 Google LLC
325
- * SPDX-License-Identifier: BSD-3-Clause
326
- */
327
- function U(s) {
328
- return h({ ...s, state: !0, attribute: !1 });
329
- }
330
- /**
331
- * @license
332
- * Copyright 2017 Google LLC
333
- * SPDX-License-Identifier: BSD-3-Clause
334
- */
335
- const W = (s, e, t) => (t.configurable = !0, t.enumerable = !0, Reflect.decorate && typeof e != "object" && Object.defineProperty(s, e, t), t);
336
- /**
337
- * @license
338
- * Copyright 2021 Google LLC
339
- * SPDX-License-Identifier: BSD-3-Clause
340
- */
341
- function X(s) {
342
- return (e, t) => {
343
- const { slot: i, selector: o } = s ?? {}, r = "slot" + (i ? `[name=${i}]` : ":not([name])");
344
- return W(e, t, { get() {
345
- var d;
346
- const n = (d = this.renderRoot) == null ? void 0 : d.querySelector(r), a = (n == null ? void 0 : n.assignedElements(s)) ?? [];
347
- return o === void 0 ? a : a.filter((b) => b.matches(o));
348
- } });
349
- };
350
- }
351
- const F = ':host{position:relative;display:block}.dropdown-wrapper{display:flex;flex-direction:column;gap:8px;align-items:start}.dropdown,.menu,.toggle,.dropdown-wrapper{min-width:115px;max-width:var(--ucds-form-element-maxwidth);width:var(--ucds-form-element-width)}.dropdown{position:relative}.toggle{display:flex;align-items:center;justify-content:space-between;gap:16px;height:48px;padding:0 var(--ucds-form-element-horizontal-padding);font-family:var(--ucds-font-family-sans-serif);font-size:var(--ucds-font-base-size);border:var(--ucds-color-forms-input-border-rest) solid var(--ucds-form-element-border-width);border-radius:var(--ucds-form-element-border-radius);background-color:var(--ucds-color-forms-input-background-rest)}.toggle:focus{outline:var(--ucds-color-action-focus) 2px solid;outline-offset:2px}.toggle .selected-label-wrapper{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.toggle ucds-icon{color:var(--ucds-color-action-rest);transition:transform .5s ease}.toggle.error{background-color:var(--ucds-color-feedback-error-background-light);border-color:var(--ucds-color-feedback-error-light)}.toggle:hover{border-color:var(--ucds-color-forms-input-border-hover);cursor:pointer}.toggle.disabled{border-color:var(--ucds-color-forms-input-border-disabled);color:var(--ucds-color-text-disabled);cursor:not-allowed;pointer-events:none}.toggle.disabled ucds-icon{color:var(--ucds-color-forms-input-element-disabled)}.menu{position:absolute;background:var(--ucds-color-forms-input-background-rest);border:var(--ucds-color-forms-input-border-rest) solid var(--ucds-form-element-border-width);border-radius:var(--ucds-form-element-border-radius);display:none;cursor:pointer;list-style:none;margin:0;padding:12px;flex-direction:column;gap:8px;overflow-y:auto;z-index:100;-webkit-overflow-scrolling:touch;scroll-behavior:smooth}:host([open]) .menu{display:flex}:host([open]) ucds-icon{transform:rotateX(180deg)}:host([data-open-direction="up"]) .menu{bottom:calc(100% + 8px)}:host([data-open-direction="down"]) .menu{top:calc(100% + 8px)}';
352
- var G = Object.defineProperty, Q = Object.getOwnPropertyDescriptor, c = (s, e, t, i) => {
353
- for (var o = i > 1 ? void 0 : i ? Q(e, t) : e, r = s.length - 1, n; r >= 0; r--)
354
- (n = s[r]) && (o = (i ? n(e, t, o) : n(o)) || o);
355
- return i && o && G(e, t, o), o;
356
- };
357
- let l = class extends _ {
13
+ let l = class extends m {
358
14
  // == Constructor ==
359
15
  constructor() {
360
16
  super(), this.initialValue = "", this.initialLabel = "", this._isOutsideClickListenerAttached = !1, this.scrollHandler = () => this._adjustDropdownDirection(), this.resizeObserver = new ResizeObserver(() => this._adjustDropdownDirection()), this.errorText = "", this.inputId = "", this.label = "", this.name = "", this.selectedLabel = "- Select -", this.disabled = !1, this.error = !1, this.open = !1, this.required = !1, this.activeIndex = -1, this._value = "", this.internals = this.attachInternals();
@@ -365,9 +21,9 @@ let l = class extends _ {
365
21
  return this._value;
366
22
  }
367
23
  /** Updates the value, triggers reactivity and form value update. */
368
- set value(s) {
369
- const e = this._value;
370
- this._value = s, this.internals.setFormValue(this._value), this.requestUpdate("value", e);
24
+ set value(e) {
25
+ const t = this._value;
26
+ this._value = e, this.internals.setFormValue(this._value), this.requestUpdate("value", t);
371
27
  }
372
28
  // == Lifecycle methods ==
373
29
  connectedCallback() {
@@ -377,27 +33,27 @@ let l = class extends _ {
377
33
  super.disconnectedCallback && super.disconnectedCallback(), this.removeEventListener("keydown", this._handleKeydown), this._removeOutsideClickListener();
378
34
  }
379
35
  firstUpdated() {
380
- const s = this.items.find((e) => e.hasAttribute("selected"));
36
+ const e = this.items.find((t) => t.hasAttribute("selected"));
381
37
  queueMicrotask(() => {
382
- var e;
383
- !this.value && s ? (this.initialValue = s.value, this.initialLabel = (e = s.textContent) == null ? void 0 : e.trim(), this.value = this.initialValue, this.selectedLabel = this.initialLabel, this.activeIndex = this.items.indexOf(s)) : (this.initialValue = "", this.initialLabel = this.selectedLabel), this._syncSelectedItem();
38
+ var t;
39
+ !this.value && e ? (this.initialValue = e.value, this.initialLabel = (t = e.textContent) == null ? void 0 : t.trim(), this.value = this.initialValue, this.selectedLabel = this.initialLabel, this.activeIndex = this.items.indexOf(e)) : (this.initialValue = "", this.initialLabel = this.selectedLabel), this._syncSelectedItem();
384
40
  });
385
41
  }
386
42
  // == Event handlers ==
387
43
  /** Handles keyboard navigation and interaction. */
388
- _handleKeydown(s) {
389
- var t, i;
390
- const e = (t = this.shadowRoot) == null ? void 0 : t.querySelector(".toggle");
44
+ _handleKeydown(e) {
45
+ var i, o;
46
+ const t = (i = this.shadowRoot) == null ? void 0 : i.querySelector(".toggle");
391
47
  if (!this.open) {
392
- if (["ArrowDown", "ArrowUp", " "].includes(s.key)) {
48
+ if (["ArrowDown", "ArrowUp", " "].includes(e.key)) {
393
49
  this._toggleMenu();
394
- const o = this.items.findIndex((r) => r.hasAttribute("selected"));
395
- this.activeIndex = o >= 0 ? o : 0, this.updateComplete.then(() => this._focusActiveItem()), s.preventDefault(), s.stopImmediatePropagation();
396
- } else if (["ArrowLeft", "ArrowRight"].includes(s.key)) {
397
- s.preventDefault(), s.stopImmediatePropagation();
398
- const o = this.items.find((a) => a.hasAttribute("selected")), r = o ? this.items.indexOf(o) : -1;
50
+ const s = this.items.findIndex((r) => r.hasAttribute("selected"));
51
+ this.activeIndex = s >= 0 ? s : 0, this.updateComplete.then(() => this._focusActiveItem()), e.preventDefault(), e.stopImmediatePropagation();
52
+ } else if (["ArrowLeft", "ArrowRight"].includes(e.key)) {
53
+ e.preventDefault(), e.stopImmediatePropagation();
54
+ const s = this.items.find((h) => h.hasAttribute("selected")), r = s ? this.items.indexOf(s) : -1;
399
55
  let n = r;
400
- s.key === "ArrowLeft" ? n = Math.max(r - 1, 0) : s.key === "ArrowRight" && (n = Math.min(r + 1, this.items.length - 1)), n !== this.activeIndex && (this.activeIndex = n, this.value = this.items[this.activeIndex].value, this.selectedLabel = (i = this.items[this.activeIndex].textContent) == null ? void 0 : i.trim(), this._syncSelectedItem(), this.dispatchEvent(new CustomEvent("change", {
56
+ e.key === "ArrowLeft" ? n = Math.max(r - 1, 0) : e.key === "ArrowRight" && (n = Math.min(r + 1, this.items.length - 1)), n !== this.activeIndex && (this.activeIndex = n, this.value = this.items[this.activeIndex].value, this.selectedLabel = (o = this.items[this.activeIndex].textContent) == null ? void 0 : o.trim(), this._syncSelectedItem(), this.dispatchEvent(new CustomEvent("change", {
401
57
  detail: { value: this.value, selectedLabel: this.selectedLabel },
402
58
  bubbles: !0,
403
59
  composed: !0
@@ -405,49 +61,49 @@ let l = class extends _ {
405
61
  }
406
62
  return;
407
63
  }
408
- switch (s.key) {
64
+ switch (e.key) {
409
65
  case "ArrowDown":
410
- s.preventDefault(), this.activeIndex = Math.min(this.activeIndex + 1, this.items.length - 1), this._focusActiveItem();
66
+ e.preventDefault(), this.activeIndex = Math.min(this.activeIndex + 1, this.items.length - 1), this._focusActiveItem();
411
67
  break;
412
68
  case "ArrowUp":
413
- s.preventDefault(), this.activeIndex = Math.max(this.activeIndex - 1, 0), this._focusActiveItem();
69
+ e.preventDefault(), this.activeIndex = Math.max(this.activeIndex - 1, 0), this._focusActiveItem();
414
70
  break;
415
71
  case "Escape":
416
- this._toggleMenu(), e == null || e.focus();
72
+ this._toggleMenu(), t == null || t.focus();
417
73
  break;
418
74
  }
419
75
  }
420
76
  /** Handles selection of an item via custom `dropdown-select` event. */
421
- _handleSelection(s) {
422
- this.value = s.detail.value, this.selectedLabel = s.detail.selectedLabel, this._syncSelectedItem(), queueMicrotask(() => {
423
- var i;
424
- const e = this.items.find((o) => o.hasAttribute("selected"));
425
- this.activeIndex = this.items.indexOf(e), this._toggleMenu();
426
- const t = (i = this.shadowRoot) == null ? void 0 : i.querySelector(".toggle");
427
- t == null || t.focus();
77
+ _handleSelection(e) {
78
+ this.value = e.detail.value, this.selectedLabel = e.detail.selectedLabel, this._syncSelectedItem(), queueMicrotask(() => {
79
+ var o;
80
+ const t = this.items.find((s) => s.hasAttribute("selected"));
81
+ this.activeIndex = this.items.indexOf(t), this._toggleMenu();
82
+ const i = (o = this.shadowRoot) == null ? void 0 : o.querySelector(".toggle");
83
+ i == null || i.focus();
428
84
  });
429
85
  }
430
86
  /** Closes the dropdown when clicking outside. */
431
- _handleOutsideClick(s) {
432
- var e;
87
+ _handleOutsideClick(e) {
88
+ var t;
433
89
  if (this.open) {
434
- const t = s.composedPath(), i = (e = this.shadowRoot) == null ? void 0 : e.querySelector(".menu");
435
- (!i || !t.includes(i)) && (this.open = !1, this._removeOutsideClickListener());
90
+ const i = e.composedPath(), o = (t = this.shadowRoot) == null ? void 0 : t.querySelector(".menu");
91
+ (!o || !i.includes(o)) && (this.open = !1, this._removeOutsideClickListener());
436
92
  }
437
93
  }
438
94
  // == Form-associated methods ==
439
95
  /** Called when parent form is reset. */
440
96
  formResetCallback() {
441
- var e;
97
+ var t;
442
98
  this.value = this.initialValue;
443
- const s = this.items.find((t) => t.value === this.initialValue);
444
- s ? (this.selectedLabel = (e = s.textContent) == null ? void 0 : e.trim(), this.activeIndex = this.items.indexOf(s)) : (this.selectedLabel = this.initialLabel, this.activeIndex = -1), this._syncSelectedItem();
99
+ const e = this.items.find((i) => i.value === this.initialValue);
100
+ e ? (this.selectedLabel = (t = e.textContent) == null ? void 0 : t.trim(), this.activeIndex = this.items.indexOf(e)) : (this.selectedLabel = this.initialLabel, this.activeIndex = -1), this._syncSelectedItem();
445
101
  }
446
102
  /** Called when form state is restored. */
447
- formStateRestoreCallback(s) {
448
- var t;
449
- const e = this.items.find((i) => i.value === s);
450
- e ? (this.selectedLabel = (t = e.textContent) == null ? void 0 : t.trim(), this.activeIndex = this.items.indexOf(e), this._syncSelectedItem(), this.value = s) : console.warn("No matching item found during restore");
103
+ formStateRestoreCallback(e) {
104
+ var i;
105
+ const t = this.items.find((o) => o.value === e);
106
+ t ? (this.selectedLabel = (i = t.textContent) == null ? void 0 : i.trim(), this.activeIndex = this.items.indexOf(t), this._syncSelectedItem(), this.value = e) : console.warn("No matching item found during restore");
451
107
  }
452
108
  // == Private methods ==
453
109
  /** Opens or closes the dropdown. */
@@ -458,28 +114,28 @@ let l = class extends _ {
458
114
  }
459
115
  /** Marks selected item visually based on value. */
460
116
  _syncSelectedItem() {
461
- this.items.forEach((s) => {
462
- const e = s;
463
- e.selected = e.value === this.value;
117
+ this.items.forEach((e) => {
118
+ const t = e;
119
+ t.selected = t.value === this.value;
464
120
  });
465
121
  }
466
122
  /** Determines if dropdown should open upward or downward based on viewport space. */
467
123
  _adjustDropdownDirection() {
468
- var n, a;
469
- const e = ((n = this.shadowRoot) == null ? void 0 : n.querySelector(".dropdown")).getBoundingClientRect(), t = e.top, i = window.innerHeight - e.bottom, o = i >= t ? "down" : "up";
470
- this.setAttribute("data-open-direction", o);
471
- const r = (a = this.shadowRoot) == null ? void 0 : a.querySelector(".menu");
124
+ var n, h;
125
+ const t = ((n = this.shadowRoot) == null ? void 0 : n.querySelector(".dropdown")).getBoundingClientRect(), i = t.top, o = window.innerHeight - t.bottom, s = o >= i ? "down" : "up";
126
+ this.setAttribute("data-open-direction", s);
127
+ const r = (h = this.shadowRoot) == null ? void 0 : h.querySelector(".menu");
472
128
  if (r) {
473
- const d = o === "down" ? i - 16 : t - 16;
474
- r.style.maxHeight = `${d}px`;
129
+ const g = s === "down" ? o - 16 : i - 16;
130
+ r.style.maxHeight = `${g}px`;
475
131
  }
476
132
  }
477
133
  /** Focuses the currently active item (for keyboard nav). */
478
134
  _focusActiveItem() {
479
- var s, e;
135
+ var e, t;
480
136
  if (this.items.length > 0 && this.activeIndex > -1) {
481
- const t = (e = (s = this.items[this.activeIndex]) == null ? void 0 : s.shadowRoot) == null ? void 0 : e.querySelector(".dropdown-item");
482
- t == null || t.focus();
137
+ const i = (t = (e = this.items[this.activeIndex]) == null ? void 0 : e.shadowRoot) == null ? void 0 : t.querySelector(".dropdown-item");
138
+ i == null || i.focus();
483
139
  }
484
140
  }
485
141
  /** Helper to remove the outside click handler and update _isOutsideClickListenerAttached at the same time. */
@@ -488,17 +144,17 @@ let l = class extends _ {
488
144
  }
489
145
  // == Render ==
490
146
  render() {
491
- const s = {
147
+ const e = {
492
148
  disabled: this.disabled,
493
149
  error: this.error
494
150
  };
495
- return y`
151
+ return p`
496
152
  <div class="dropdown-wrapper">
497
- ${this.label ? y`
498
- <form-label id="${this.inputId}-label" for="${this.inputId}" text="${this.label}" ?required="${this.required}" ?disabled="${this.disabled}"></form-label>` : v}
153
+ ${this.label ? p`
154
+ <form-label id="${this.inputId}-label" for="${this.inputId}" text="${this.label}" ?required="${this.required}" ?disabled="${this.disabled}"></form-label>` : u}
499
155
  <div class="dropdown">
500
- <div class="toggle ${M(s)}"
501
- aria-disabled="${this.disabled ? !0 : v}"
156
+ <div class="toggle ${y(e)}"
157
+ aria-disabled="${this.disabled ? !0 : u}"
502
158
  role="button"
503
159
  tabindex="${this.disabled ? "-1" : "0"}"
504
160
  @click="${this._toggleMenu}"
@@ -513,85 +169,85 @@ let l = class extends _ {
513
169
  <slot></slot>
514
170
  </div>
515
171
  </div>
516
- ${this.error ? y`<form-error-message text="${this.errorText}"></form-error-message>` : v}
172
+ ${this.error ? p`<form-error-message text="${this.errorText}"></form-error-message>` : u}
517
173
  </div>
518
174
  `;
519
175
  }
520
176
  };
521
177
  l.styles = [
522
- _.styles,
523
- A(F)
178
+ m.styles,
179
+ v(_)
524
180
  ];
525
181
  l.formAssociated = !0;
526
- c([
527
- h({ type: String, attribute: "error-text" })
182
+ d([
183
+ a({ type: String, attribute: "error-text" })
528
184
  ], l.prototype, "errorText", 2);
529
- c([
530
- h({ type: String, attribute: "input-id" })
185
+ d([
186
+ a({ type: String, attribute: "input-id" })
531
187
  ], l.prototype, "inputId", 2);
532
- c([
533
- h({ type: String })
188
+ d([
189
+ a({ type: String })
534
190
  ], l.prototype, "label", 2);
535
- c([
536
- h({ type: String, reflect: !0 })
191
+ d([
192
+ a({ type: String, reflect: !0 })
537
193
  ], l.prototype, "name", 2);
538
- c([
539
- h({ type: String, attribute: "selected-label" })
194
+ d([
195
+ a({ type: String, attribute: "selected-label" })
540
196
  ], l.prototype, "selectedLabel", 2);
541
- c([
542
- h({ type: Boolean, reflect: !0 })
197
+ d([
198
+ a({ type: Boolean, reflect: !0 })
543
199
  ], l.prototype, "disabled", 2);
544
- c([
545
- h({ type: Boolean, reflect: !0 })
200
+ d([
201
+ a({ type: Boolean, reflect: !0 })
546
202
  ], l.prototype, "error", 2);
547
- c([
548
- h({ type: Boolean, reflect: !0 })
203
+ d([
204
+ a({ type: Boolean, reflect: !0 })
549
205
  ], l.prototype, "open", 2);
550
- c([
551
- h({ type: Boolean, reflect: !0 })
206
+ d([
207
+ a({ type: Boolean, reflect: !0 })
552
208
  ], l.prototype, "required", 2);
553
- c([
554
- U()
209
+ d([
210
+ b()
555
211
  ], l.prototype, "activeIndex", 2);
556
- c([
557
- U()
212
+ d([
213
+ b()
558
214
  ], l.prototype, "_value", 2);
559
- c([
560
- X({ selector: "ucds-dropdown-item" })
215
+ d([
216
+ x({ selector: "ucds-dropdown-item" })
561
217
  ], l.prototype, "items", 2);
562
- l = c([
563
- I("ucds-dropdown")
218
+ l = d([
219
+ w("ucds-dropdown")
564
220
  ], l);
565
- const Y = ".dropdown-item{display:flex;gap:4px;align-items:center;padding:10px 6px 10px 26px;border-radius:8px}.dropdown-item ucds-icon{display:none}.dropdown-item .dropdown-item-text{display:inline-block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dropdown-item:hover,.dropdown-item:active,.dropdown-item:focus{background-color:var(--ucds-color-palette-berry-900);outline:none}.dropdown-item.selected{padding-left:6px}.dropdown-item.selected ucds-icon{display:inline-flex}";
566
- var Z = Object.defineProperty, ee = Object.getOwnPropertyDescriptor, S = (s, e, t, i) => {
567
- for (var o = i > 1 ? void 0 : i ? ee(e, t) : e, r = s.length - 1, n; r >= 0; r--)
568
- (n = s[r]) && (o = (i ? n(e, t, o) : n(o)) || o);
569
- return i && o && Z(e, t, o), o;
221
+ const L = ".dropdown-item{display:flex;gap:4px;align-items:center;padding:10px 6px 10px 26px;border-radius:8px}.dropdown-item ucds-icon{display:none}.dropdown-item .dropdown-item-text{display:inline-block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.dropdown-item:hover,.dropdown-item:active,.dropdown-item:focus{background-color:var(--ucds-color-palette-berry-900);outline:none}.dropdown-item.selected{padding-left:6px}.dropdown-item.selected ucds-icon{display:inline-flex}";
222
+ var C = Object.defineProperty, O = Object.getOwnPropertyDescriptor, f = (e, t, i, o) => {
223
+ for (var s = o > 1 ? void 0 : o ? O(t, i) : t, r = e.length - 1, n; r >= 0; r--)
224
+ (n = e[r]) && (s = (o ? n(t, i, s) : n(s)) || s);
225
+ return o && s && C(t, i, s), s;
570
226
  };
571
- let m = class extends _ {
227
+ let c = class extends m {
572
228
  constructor() {
573
229
  super(...arguments), this.value = "", this.selected = !1;
574
230
  }
575
231
  // == Private methods ==
576
232
  /** Called when the item is clicked or activated via keyboard. */
577
233
  _select() {
578
- var e;
579
- const s = (e = this.textContent) == null ? void 0 : e.trim();
234
+ var t;
235
+ const e = (t = this.textContent) == null ? void 0 : t.trim();
580
236
  this.selected = !0, this.dispatchEvent(new CustomEvent("dropdown-select", {
581
- detail: { value: this.value, selectedLabel: s },
237
+ detail: { value: this.value, selectedLabel: e },
582
238
  bubbles: !0,
583
239
  composed: !0
584
240
  }));
585
241
  }
586
242
  /** Handle Enter, Tab, or Esc key to activate the item. */
587
- _handleKeydown(s) {
588
- (s.key === "Enter" || s.key === "Tab" || s.key === "Esc") && (s.preventDefault(), this._select());
243
+ _handleKeydown(e) {
244
+ (e.key === "Enter" || e.key === "Tab" || e.key === "Esc") && (e.preventDefault(), this._select());
589
245
  }
590
246
  // == Render ==
591
247
  render() {
592
- return y`
248
+ return p`
593
249
  <div class="dropdown-item ${this.selected ? "selected" : ""}"
594
- aria-selected="${this.selected ? !0 : v}"
250
+ aria-selected="${this.selected ? !0 : u}"
595
251
  role="option"
596
252
  tabindex="-1"
597
253
  @click=${this._select}
@@ -603,20 +259,20 @@ let m = class extends _ {
603
259
  `;
604
260
  }
605
261
  };
606
- m.styles = [
607
- _.styles,
608
- A(Y)
262
+ c.styles = [
263
+ m.styles,
264
+ v(L)
609
265
  ];
610
- S([
611
- h({ type: String })
612
- ], m.prototype, "value", 2);
613
- S([
614
- h({ type: Boolean, reflect: !0 })
615
- ], m.prototype, "selected", 2);
616
- m = S([
617
- I("ucds-dropdown-item")
618
- ], m);
266
+ f([
267
+ a({ type: String })
268
+ ], c.prototype, "value", 2);
269
+ f([
270
+ a({ type: Boolean, reflect: !0 })
271
+ ], c.prototype, "selected", 2);
272
+ c = f([
273
+ w("ucds-dropdown-item")
274
+ ], c);
619
275
  export {
620
276
  l as Dropdown,
621
- m as DropdownItem
277
+ c as DropdownItem
622
278
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucalgary-design-system/dropdown",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -11,10 +11,10 @@
11
11
  }
12
12
  },
13
13
  "peerDependencies": {
14
- "@ucalgary-design-system/core": "^1.0.3",
14
+ "@ucalgary-design-system/core": "^1.0.4",
15
15
  "@ucalgary-design-system/helper-components": "^1.0.2",
16
- "@ucalgary-design-system/icon": "^1.0.3",
17
- "@ucalgary-design-system/tokens": "^1.0.3",
16
+ "@ucalgary-design-system/icon": "^1.0.4",
17
+ "@ucalgary-design-system/tokens": "^1.0.4",
18
18
  "lit": "^3.2.1"
19
19
  },
20
20
  "description": "A web component for Dropdown",